Skip to content
Open
36 changes: 23 additions & 13 deletions lib/generators/draft/layout/templates/_flashes.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
<div class="row">
<div class="col-lg-12">
<%% if notice.present? %>
<div class="alert alert-dismissable alert-success">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<%%= notice %>
<%% if notice.present? %>
<div class="alert alert-dismissable alert-success">
<div class="container">
<div class="row">
<div class="col-lg-12">
<button class="close" data-dismiss="alert">&times;</button>

<%%= notice %>
</div>
</div>
<%% end %>
</div>
</div>
<%% end %>

<%% if alert.present? %>
<div class="alert alert-dismissable alert-success">
<div class="container">
<div class="row">
<div class="alert alert-dismissable alert-warning">
<button class="close" data-dismiss="alert">&times;</button>

<%% if alert.present? %>
<div class="alert alert-dismissable alert-warning">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<%%= alert %>
<%%= alert %>
</div>
</div>
<%% end %>
</div>
</div>
</div>
<%% end %>
2 changes: 1 addition & 1 deletion lib/generators/draft/layout/templates/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<%% else %>
<li>
<a href="/<%= devise_route[1].pluralize %>/edit">
Edit profile
Edit <%= devise_route[1].humanize %>
</a>
</li>

Expand Down
4 changes: 2 additions & 2 deletions lib/generators/draft/layout/templates/layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<body>
<%%= render "shared/navbar" %>

<div class="container">
<%%= render "shared/flashes" %>
<%%= render "shared/flashes" %>

<div class="container">
<%%= yield %>
</div>

Expand Down
14 changes: 7 additions & 7 deletions lib/generators/draft/resource/resource_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def generate_controller
return if skip_controller?

if read_only?
template "controllers/read_only_controller.rb", "app/controllers/#{plural_table_name.underscore}_controller.rb"
template "controllers/read_only_controller.rb", "app/controllers/#{plural_table_name}_controller.rb"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [108/80]

else
template "controllers/controller.rb", "app/controllers/#{plural_table_name.underscore}_controller.rb"
template "controllers/controller.rb", "app/controllers/#{plural_table_name}_controller.rb"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [98/80]

end
end

Expand All @@ -35,7 +35,7 @@ def generate_model
def generate_view_files
available_views.each do |view|
filename = view_filename_with_extensions(view)
template filename, File.join("app/views", "#{plural_table_name}_templates", File.basename(filename))
template filename, File.join("app/views", "#{singular_table_name}_templates", File.basename(filename))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [110/80]

end
end

Expand All @@ -52,8 +52,8 @@ def generate_routes
def generate_specs
return if read_only? || skip_controller? || skip_model?

template "specs/crud_spec.rb", "spec/features/crud_#{plural_table_name.underscore}_spec.rb"
template "specs/factories.rb", "spec/factories/#{plural_table_name.underscore}.rb"
template "specs/crud_spec.rb", "spec/features/crud_#{plural_table_name}_spec.rb"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [86/80]

template "specs/factories.rb", "spec/factories/#{plural_table_name}.rb"
end

private
Expand All @@ -74,7 +74,7 @@ def golden_seven_routes
get("/#{plural_table_name}/:id_to_display", { :controller => "#{plural_table_name}", :action => "show" })

# UPDATE
get("/#{plural_table_name}/:prefill_with_id/edit", { :controller => "#{plural_table_name}", :action => "edit_form" })
get("/#{plural_table_name}/:id_to_edit/edit", { :controller => "#{plural_table_name}", :action => "edit_form" })
#{skip_post? ? "get" : "post"}("/update_#{singular_table_name}/:id_to_modify", { :controller => "#{plural_table_name}", :action => "update_row" })

# DELETE
Expand Down Expand Up @@ -148,7 +148,7 @@ def available_views
elsif skip_redirect?
%w(index show new_form create_row edit_form update_row destroy_row)
else
%w(index new_form edit_form show)
%w(index show new_form new_form_with_errors edit_form edit_form_with_errors)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]

end
end

Expand Down
71 changes: 38 additions & 33 deletions lib/generators/draft/resource/templates/controllers/controller.rb
Original file line number Diff line number Diff line change
@@ -1,97 +1,102 @@
class <%= plural_table_name.camelize %>Controller < ApplicationController
def index
@<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all
@list_of_<%= plural_table_name %> = <%= class_name.singularize %>.all.order({ :created_at => :desc })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token tIDENTIFIER


render("<%= plural_table_name.underscore %>_templates/index.html.erb")
render("<%= singular_table_name %>_templates/index.html.erb")
end

def show
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_display])
id_of_<%= singular_table_name %>_to_show = params.fetch("id_to_display")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token tIDENTIFIER


render("<%= plural_table_name.underscore %>_templates/show.html.erb")
@<%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_show)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected @'

render("<%= singular_table_name %>_templates/show.html.erb")
end
def new_form
<% unless skip_validation_alerts? -%>
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new
<% end -%>
render("<%= plural_table_name.underscore %>_templates/new_form.html.erb")
render("<%= singular_table_name %>_templates/new_form.html.erb")
end
def create_row
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new
@<%= singular_table_name %> = <%= class_name.singularize %>.new
<% attributes.each do |attribute| -%>
@<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>]
@<%= singular_table_name %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_form")
<% end -%>
<% unless skip_validation_alerts? -%>
save_status = @<%= singular_table_name.underscore %>.save
save_status = @<%= singular_table_name %>.save
if save_status == true
redirect_to("/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> created successfully.")
redirect_to("/<%= plural_table_name %>", :notice => "<%= singular_table_name.humanize %> created successfully.")
else
render("<%= plural_table_name.underscore %>_templates/new_form.html.erb")
render("<%= singular_table_name %>_templates/new_form_with_errors.html.erb")
end
<% else -%>
@<%= singular_table_name.underscore %>.save
@<%= singular_table_name %>.save
<% unless skip_redirect? -%>
redirect_to("/<%= @plural_table_name.underscore %>")
redirect_to("/<%= plural_table_name %>")
<% else -%>
@current_count = <%= class_name.singularize %>.count
@current_<%= singular_table_name %>_count = <%= class_name.singularize %>.count
render("<%= plural_table_name.underscore %>_templates/create_row.html.erb")
render("<%= singular_table_name %>_templates/create_row.html.erb")
<% end -%>
<% end -%>
end
def edit_form
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:prefill_with_id])
id_of_<%= singular_table_name %>_to_prefill = params.fetch("id_to_edit")
render("<%= plural_table_name.underscore %>_templates/edit_form.html.erb")
@<%= singular_table_name %> = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_prefill)
render("<%= singular_table_name %>_templates/edit_form.html.erb")
end
def update_row
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_modify])
id_of_<%= singular_table_name %>_to_change = params.fetch("id_to_modify")
@<%= singular_table_name %>_to_change = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_change)
<% attributes.each do |attribute| -%>
@<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>]
@<%= singular_table_name %>_to_change.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_form")
<% end -%>
<% unless skip_validation_alerts? -%>
save_status = @<%= singular_table_name.underscore %>.save
save_status = @<%= singular_table_name %>_to_change.save
if save_status == true
redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.")
redirect_to("/<%= plural_table_name %>/#{@<%= singular_table_name %>_to_change.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.")
else
render("<%= plural_table_name.underscore %>_templates/edit_form.html.erb")
render("<%= singular_table_name %>_templates/edit_form_with_errors.html.erb")
end
<% else -%>
@<%= singular_table_name.underscore %>.save
@<%= singular_table_name %>_to_change.save

<% unless skip_redirect? -%>
redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}")
redirect_to("/<%= plural_table_name %>/#{@<%= singular_table_name %>_to_change.id}")
<% else -%>
render("<%= plural_table_name.underscore %>_templates/update_row.html.erb")
render("<%= singular_table_name %>_templates/update_row.html.erb")
<% end -%>
<% end -%>
end
def destroy_row
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_remove])
id_of_<%= singular_table_name %>_to_delete = params.fetch("id_to_remove")
@<%= singular_table_name %>_to_toast = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_delete)
@<%= singular_table_name.underscore %>.destroy
@<%= singular_table_name %>_to_toast.destroy
<% unless skip_validation_alerts? -%>
redirect_to("/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.")
redirect_to("/<%= plural_table_name %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.")
<% else -%>
<% unless skip_redirect? -%>
redirect_to("/<%= @plural_table_name.underscore %>")
redirect_to("/<%= plural_table_name %>")
<% else -%>
@remaining_count = <%= class_name.singularize %>.count
@remaining_<%= singular_table_name %>_count = <%= class_name.singularize %>.count
render("<%= plural_table_name.underscore %>_templates/destroy_row.html.erb")
render("<%= singular_table_name %>_templates/destroy_row.html.erb")
<% end -%>
<% end -%>
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
class <%= plural_table_name.camelize %>Controller < ApplicationController
def index
@<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all
@list_of_<%= plural_table_name %> = <%= class_name.singularize %>.all.order({ :created_at => :desc })

render("<%= singular_table_name %>_templates/index.html.erb")
end

def show
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id])
id_of_<%= singular_table_name %>_to_show = params.fetch("id_to_display")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token tIDENTIFIER


@<%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_show)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected @'

render("<%= singular_table_name %>_templates/show.html.erb")
end
end
2 changes: 1 addition & 1 deletion lib/generators/draft/resource/templates/specs/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require Rails.root.join("spec", "support", "increasing_random.rb")

FactoryGirl.define do
FactoryBot.define do
factory :<%= singular_table_name %> do
sequence(:id, IncreasingRandom.new) { |n| n.value }
<% attributes.each do |attribute| -%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<h1>You created <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>!</h1>
<h1>You created a <%= singular_table_name.humanize.downcase %>!</h1>

<p>
There are now <%%= @current_count %> <%= plural_table_name.humanize.downcase %>.
There are now <%%= @current_<%= singular_table_name %>_count %> <%= plural_table_name.humanize.downcase %>.
</p>

<p>
<a href="/<%= @plural_table_name.underscore %>">
<a href="/<%= plural_table_name %>">
Click here
</a>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<h1>You deleted <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>!</h1>
<h1>You deleted a <%= singular_table_name.humanize.downcase %>!</h1>

<p>
There are now <%%= @remaining_count %> <%= plural_table_name.humanize.downcase %>.
There are now <%%= @remaining_<%= singular_table_name %>_count %> <%= plural_table_name.humanize.downcase %>.
</p>

<p>
<a href="/<%= @plural_table_name.underscore %>">
<a href="/<%= plural_table_name %>">
Click here
</a>

Expand Down
19 changes: 3 additions & 16 deletions lib/generators/draft/resource/templates/views/edit_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
<% unless skip_validation_alerts? -%>
<!-- Validation failure messages -->
<%% if @<%= singular_table_name %>.errors.any? %>
<%% @<%= singular_table_name %>.errors.full_messages.each do |message| %>
<div class="alert alert-dismissable alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

<%%= message %>
</div>
<%% end %>
<%% end %>

<% end -%>
<h1>
Edit <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>
</h1>
Expand All @@ -23,7 +10,7 @@
<% if attribute.field_type == :check_box -%>
<div class="checkbox">
<label for="<%= attribute.column_name %>">
<input type="checkbox" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" value="1" <%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %>>
<input type="checkbox" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>_from_form" value="1" <%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %>>
<%= attribute.column_name.humanize %>
</label>
</div>
Expand All @@ -34,9 +21,9 @@
</label>

<% if attribute.field_type == :text_area -%>
<textarea id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" class="form-control" rows="3"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %></textarea>
<textarea id="<%= attribute.column_name %>" name="<%= attribute.column_name %>_from_form" class="form-control" rows="3"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %></textarea>
<% else -%>
<input type="text" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" class="form-control" value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>">
<input type="text" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>_from_form" class="form-control" value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>">
<% end -%>
</div>
<% end -%>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<% unless skip_validation_alerts? -%>
<!-- Validation failure messages -->
<%% if @<%= singular_table_name %>.errors.any? %>
<%% @<%= singular_table_name %>.errors.full_messages.each do |message| %>
<div class="alert alert-dismissable alert-danger">
<button class="close" data-dismiss="alert">&times;</button>

<%%= message %>
</div>
<%% end %>
<%% end %>

<% end -%>
<h1>
Edit <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>
</h1>

<hr>

<form action="/update_<%= singular_table_name %>/<%%= @<%= singular_table_name %>.id %>"<% unless skip_post? -%> method="post"<% end -%>>
<% attributes.each do |attribute| -%>
<!-- Label and input for <%= attribute.column_name %> -->
<% if attribute.field_type == :check_box -%>
<div class="checkbox">
<label for="<%= attribute.column_name %>">
<input type="checkbox" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>_from_form" value="1" <%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %>>
<%= attribute.column_name.humanize %>
</label>
</div>
<% else -%>
<div class="form-group">
<label for="<%= attribute.column_name %>" class="control-label">
<%= attribute.column_name.humanize %>
</label>

<% if attribute.field_type == :text_area -%>
<textarea id="<%= attribute.column_name %>" name="<%= attribute.column_name %>_from_form" class="form-control" rows="3"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %></textarea>
<% else -%>
<input type="text" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>_from_form" class="form-control" value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>">
<% end -%>
</div>
<% end -%>

<% end -%>
<button class="btn btn-default">
Update <%= singular_table_name.humanize.downcase %>
</button>
</form>

<hr>

<a href="/<%= plural_table_name %>">
Go back
</a>
Loading