Skip to content
Open
12 changes: 6 additions & 6 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"
Copy link
Copy Markdown

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"
Copy link
Copy Markdown

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))
Copy link
Copy Markdown

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"
Copy link
Copy Markdown

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 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 new_form new_form_with_errors edit_form show)
end
end

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

render("<%= plural_table_name.underscore %>_templates/index.html.erb")
render("<%= singular_table_name %>_templates/index.html.erb", :locals => {
:list_of_<%= plural_table_name %> => all_<%= plural_table_name %>
})
end

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

render("<%= plural_table_name.underscore %>_templates/show.html.erb")
render("<%= singular_table_name %>_templates/show.html.erb", :locals => {
:the_<%= singular_table_name %> => <%= singular_table_name %>_to_show
})
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 %>_to_add = <%= class_name.singularize %>.new

<% attributes.each do |attribute| -%>
@<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>]
<%= singular_table_name %>_to_add.<%= attribute.column_name %> = params["<%= attribute.column_name %>_from_form"]
<% end -%>

<% unless skip_validation_alerts? -%>
save_status = @<%= singular_table_name.underscore %>.save
save_status = <%= singular_table_name %>_to_add.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", :locals => {
:<%= singular_table_name %>_with_errors => <%= singular_table_name %>_to_add
})
end
<% else -%>
@<%= singular_table_name.underscore %>.save
<%= singular_table_name %>_to_add.save

<% unless skip_redirect? -%>
redirect_to("/<%= @plural_table_name.underscore %>")
redirect_to("/<%= plural_table_name %>")
<% else -%>
@current_count = <%= class_name.singularize %>.count

render("<%= plural_table_name.underscore %>_templates/create_row.html.erb")
render("<%= singular_table_name %>_templates/create_row.html.erb", :locals => {
:current_count => <%= class_name.singularize %>.count
})
<% end -%>
<% end -%>
end

def edit_form
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:prefill_with_id])
existing_<%= singular_table_name %> = <%= class_name.singularize %>.find(params["prefill_with_id"])
Copy link
Copy Markdown

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/edit_form.html.erb")
render("<%= singular_table_name %>_templates/edit_form.html.erb", :locals => {
:<%= singular_table_name %>_to_prefill => existing_<%= singular_table_name %>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tOP_ASGN
unexpected token tIDENTIFIER

})
end

def update_row
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_modify])
<%= singular_table_name %>_to_change = <%= class_name.singularize %>.find(params["id_to_modify"])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tIDENTIFIER


<% attributes.each do |attribute| -%>
@<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>]
<%= singular_table_name %>_to_change.<%= attribute.column_name %> = params["<%= attribute.column_name %>_from_form"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tIDENTIFIER
unexpected token tOP_ASGN

<% 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.")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tLT
unexpected token tRPAREN

else
render("<%= plural_table_name.underscore %>_templates/edit_form.html.erb")
render("<%= singular_table_name %>_templates/edit_form.html.erb", :locals => {
:<%= singular_table_name %>_to_prefill => <%= singular_table_name %>_to_change
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tOP_ASGN

})
end
<% else -%>
@<%= singular_table_name.underscore %>.save
<%= singular_table_name %>_to_change.save
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tIDENTIFIER


<% 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}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tLT

<% else -%>
render("<%= plural_table_name.underscore %>_templates/update_row.html.erb")
render("<%= singular_table_name %>_templates/update_row.html.erb", :locals => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tIDENTIFIER
unexpected token tLCURLY

:<%= singular_table_name %>_to_prefill => <%= singular_table_name %>_to_change
})
<% end -%>
<% end -%>
end

def destroy_row
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_remove])
<%= singular_table_name %>_to_delete = <%= class_name.singularize %>.find(params["id_to_remove"])
Copy link
Copy Markdown

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.underscore %>.destroy
<%= singular_table_name %>_to_delete.destroy
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tLT


<% 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.")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tIDENTIFIER
unexpected token tRPAREN

<% else -%>
<% unless skip_redirect? -%>
redirect_to("/<%= @plural_table_name.underscore %>")
redirect_to("/<%= plural_table_name %>")
<% else -%>
@remaining_count = <%= class_name.singularize %>.count

render("<%= plural_table_name.underscore %>_templates/destroy_row.html.erb")
render("<%= singular_table_name %>_templates/destroy_row.html.erb", :locals => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unexpected token tIDENTIFIER
unterminated string meets end of file

:remaining_count => <%= class_name.singularize %>.count
})
<% end -%>
<% end -%>
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
class <%= plural_table_name.camelize %>Controller < ApplicationController
def index
@<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all
all_<%= plural_table_name %> = <%= class_name.singularize %>.all.order(:created_at => :desc)

render("<%= plural_table_name %>_templates/index.html.erb", :locals => {
:list_of_<%= plural_table_name %> => all_<%= plural_table_name %>
})
end

def show
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id])
<%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(params[:id_to_display])
Copy link
Copy Markdown

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 %>_templates/show.html.erb", :locals => {
:the_<%= singular_table_name %> => <%= singular_table_name %>_to_show
})
end
end
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_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_count %> <%= plural_table_name.humanize.downcase %>.
</p>

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

Expand Down
14 changes: 7 additions & 7 deletions lib/generators/draft/resource/templates/views/edit_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% unless skip_validation_alerts? -%>
<!-- Validation failure messages -->
<%% if @<%= singular_table_name %>.errors.any? %>
<%% @<%= singular_table_name %>.errors.full_messages.each do |message| %>
<%% if <%= singular_table_name %>_to_prefill.errors.any? %>
<%% <%= singular_table_name %>_to_prefill.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>

Expand All @@ -12,18 +12,18 @@

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

<hr>

<form action="/update_<%= singular_table_name %>/<%%= @<%= singular_table_name %>.id %>"<% unless skip_post? -%> method="post"<% end -%>>
<form action="/update_<%= singular_table_name %>/<%%= <%= singular_table_name %>_to_prefill.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 %>" 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 %>_to_prefill.<%= attribute.column_name %> %>>
<%= attribute.column_name.humanize %>
</label>
</div>
Expand All @@ -34,9 +34,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 %>_to_prefill.<%= 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 %>_to_prefill.<%= attribute.column_name %> %>">
<% end -%>
</div>
<% end -%>
Expand Down
12 changes: 6 additions & 6 deletions lib/generators/draft/resource/templates/views/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,28 @@
</th>
</tr>

<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<%% list_of_<%= plural_table_name %>.each do |the_current_<%= singular_table_name %>| %>
<tr>
<td>
<%%= <%= singular_table_name %>.id %>
<%%= the_current_<%= singular_table_name %>.id %>
</td>

<% attributes.each do |attribute| -%>
<td>
<%%= <%= singular_table_name %>.<%= attribute.column_name %> %>
<%%= the_current_<%= singular_table_name %>.<%= attribute.column_name %> %>
</td>

<% end -%>
<td>
<%%= time_ago_in_words(<%= singular_table_name %>.created_at) %> ago
<%%= time_ago_in_words(the_current_<%= singular_table_name %>.created_at) %> ago
</td>

<td>
<%%= time_ago_in_words(<%= singular_table_name %>.updated_at) %> ago
<%%= time_ago_in_words(the_current_<%= singular_table_name %>.updated_at) %> ago
</td>

<td>
<a href="/<%= plural_table_name %>/<%%= <%= singular_table_name %>.id %>">
<a href="/<%= plural_table_name %>/<%%= the_current_<%= singular_table_name %>.id %>">
Show details
</a>
</td>
Expand Down
19 changes: 3 additions & 16 deletions lib/generators/draft/resource/templates/views/new_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>
Add a new <%= singular_table_name.humanize.downcase %>
</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 %>" <% unless skip_validation_alerts? -%><%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%>>
<input type="checkbox" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>_from_form">
<%= 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"><% unless skip_validation_alerts? -%><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%></textarea>
<textarea id="<%= attribute.column_name %>" name="<%= attribute.column_name %>_from_form" class="form-control" rows="3"></textarea>
<% else -%>
<input type="text" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" class="form-control"<% unless skip_validation_alerts? -%> value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>>
<input type="text" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>_from_form" class="form-control">
<% end -%>
</div>
<% end -%>
Expand Down
Loading