Class: AdminTheme::ResourceGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- AdminTheme::ResourceGenerator
- Defined in:
- lib/generators/admin_theme/resource/resource_generator.rb
Instance Method Summary collapse
- #generate_controller ⇒ Object
- #generate_views ⇒ Object
-
#initialize(args, *options) ⇒ ResourceGenerator
constructor
A new instance of ResourceGenerator.
Constructor Details
#initialize(args, *options) ⇒ ResourceGenerator
Returns a new instance of ResourceGenerator.
14 15 16 17 |
# File 'lib/generators/admin_theme/resource/resource_generator.rb', line 14 def initialize(args, *) super(args, *) initialize_views_variables end |
Instance Method Details
#generate_controller ⇒ Object
19 20 21 22 |
# File 'lib/generators/admin_theme/resource/resource_generator.rb', line 19 def generate_controller template "../controllers/admin_resource_controller.erb", "app/controllers/admin/#{plural_resource_name}_controller.rb" inject_into_file "config/routes.rb", " resources :#{plural_resource_name}\n", :after => "namespace :admin do\n" end |
#generate_views ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/generators/admin_theme/resource/resource_generator.rb', line 24 def generate_views template "#{.engine}/view_form.html.#{.engine}", "app/views/admin/#{plural_resource_name}/_form.html.#{.engine}" template "#{.engine}/view_edit.html.#{.engine}", "app/views/admin/#{plural_resource_name}/edit.html.#{.engine}" template "#{.engine}/view_index.html.#{.engine}", "app/views/admin/#{plural_resource_name}/index.html.#{.engine}" template "#{.engine}/view_new.html.#{.engine}", "app/views/admin/#{plural_resource_name}/new.html.#{.engine}" template "#{.engine}/view_show.html.#{.engine}", "app/views/admin/#{plural_resource_name}/show.html.#{.engine}" # Add link to resource in admin layout gsub_file("app/views/layouts/admin.html.erb", /\<div\s+id=\"main-navigation\">.*\<\/ul\>/mi) do |match| match.gsub!(/\<\/ul\>/, "") %|#{match} <li class="<%= controller_name == '#{plural_resource_name}' ? 'active' : '' %>"> <%= link_to "#{plural_model_name}", #{controller_routing_path}_path %> </li> </ul>| end end |