diff --git a/VERSION b/VERSION index 81340c7..bbdeab6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.4 +0.0.5 diff --git a/draft_generators.gemspec b/draft_generators.gemspec index 5517801..c3b4274 100644 --- a/draft_generators.gemspec +++ b/draft_generators.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |s| s.name = "draft_generators".freeze - s.version = "0.0.4" + s.version = "0.0.5" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index c5e3366..522a65f 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -32,13 +32,13 @@ def generate_model end def create_root_folder - empty_directory File.join("app/views", "#{plural_table_name}") + empty_directory File.join("app/views", "#{singular_table_name}_templates") end def generate_view_files available_views.each do |view| filename = view_filename_with_extensions(view) - template filename, File.join("app/views", "#{plural_table_name}", File.basename(options[:new_form_name].presence || filename)) + template filename, File.join("app/views", "#{singular_table_name}_templates", File.basename(options[:new_form_name].presence || filename)) end end @@ -72,16 +72,16 @@ def golden_five_routes # CREATE post("/insert_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create" }) - + # READ get("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index" }) - + get("/#{plural_table_name}/:path_id", { :controller => "#{plural_table_name}", :action => "show" }) - + # UPDATE - + post("/modify_#{singular_table_name}/:path_id", { :controller => "#{plural_table_name}", :action => "update" }) - + # DELETE get("/delete_#{singular_table_name}/:path_id", { :controller => "#{plural_table_name}", :action => "destroy" }) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index c838941..635073b 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -4,7 +4,7 @@ def index @list_of_<%= plural_table_name.underscore %> = matching_<%= plural_table_name.underscore %>.order({ :created_at => :desc }) - render({ :template => "<%= plural_table_name.underscore %>/index" }) + render({ :template => "<%= singular_table_name.underscore %>_templates/index" }) end def show @@ -14,7 +14,7 @@ def show @the_<%= singular_table_name.underscore %> = matching_<%= plural_table_name.underscore.downcase %>.at(0) - render({ :template => "<%= plural_table_name.underscore %>/show" }) + render({ :template => "<%= singular_table_name.underscore %>_templates/show" }) end def create @@ -62,7 +62,7 @@ def update <% unless skip_validation_alerts? -%> if the_<%= singular_table_name.underscore %>.valid? the_<%= singular_table_name.underscore %>.save - redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}", { :notice => "<%= singular_table_name.humanize %> updated successfully."} ) + redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}", { :notice => "<%= singular_table_name.humanize %> updated successfully." } ) else redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}", { :alert => the_<%= singular_table_name.underscore %>.errors.full_messages.to_sentence }) end @@ -72,7 +72,7 @@ def update <% unless skip_redirect? -%> redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}") <% else -%> - render({ :template => "<%= plural_table_name.underscore %>/show" }) + render({ :template => "<%= singular_table_name.underscore %>_templates/show" }) <% end -%> <% end -%> end @@ -84,7 +84,7 @@ def destroy the_<%= singular_table_name.underscore %>.destroy <% unless skip_validation_alerts? -%> - redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> deleted successfully."} ) + redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> deleted successfully." } ) <% else -%> <% unless skip_redirect? -%> redirect_to("/<%= plural_table_name.underscore %>") diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 58e33f6..330abcf 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -1,148 +1,66 @@ -
| - ID - | - -<% attributes.each do |attribute| -%> -- <%= attribute.human_name %> - | - -<% end -%> -- Created at - | - -- Updated at - | - -- | -
|---|---|---|---|---|
| - <%%= <%= singular_table_name.indefinitize.gsub(" ", "_") %>.id %> - | -<% if with_sentinels? -%> - -<% end -%> - -<% attributes.each do |attribute| -%> -<% if with_sentinels? -%> - -<% end -%> -- <%%= <%= singular_table_name.indefinitize.gsub(" ", "_") %>.<%= attribute.column_name %> %> - | -<% if with_sentinels? -%> - -<% end -%> - -<% end -%> -<% if with_sentinels? -%> - -<% end -%> -- <%%= time_ago_in_words(<%= singular_table_name.indefinitize.gsub(" ", "_") %>.created_at) %> ago - | -<% if with_sentinels? -%> - - - -<% end -%> -- <%%= time_ago_in_words(<%= singular_table_name.indefinitize.gsub(" ", "_") %>.updated_at) %> ago - | -<% if with_sentinels? -%> - -<% end -%> - -- .id %>"> - Show details - - | -