Class: SuperuserGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- SuperuserGenerator
- Defined in:
- lib/generators/superuser/superuser_generator.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
- #generate_controller ⇒ Object
-
#generate_css_file ⇒ Object
NOTE: the order of the following methods is important!.
- #generate_js_file ⇒ Object
- #generate_layout ⇒ Object
- #generate_route_and_link ⇒ Object
- #generate_search_form ⇒ Object
- #generate_views ⇒ Object
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/generators/superuser/superuser_generator.rb', line 5 def attributes @attributes end |
Instance Method Details
#generate_controller ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generators/superuser/superuser_generator.rb', line 33 def generate_controller if !File.exist?("app/controllers/superuser/base_controller.rb") copy_file "base_controller.rb", "app/controllers/superuser/base_controller.rb" end if !File.exist?("app/controllers/superuser/dashboard_controller.rb") copy_file "dashboard_controller.rb", "app/controllers/superuser/dashboard_controller.rb" copy_file "views/dashboard_index.html.erb", "app/views/superuser/dashboard/index.html.erb" route "\tnamespace :superuser do\n\t\troot to: 'dashboard#index'\n\tend" add_layout_links 'app/views/layouts/superuser/application.html.erb', search = '<div class="sidebar_dashboard_link">', "<%= link_to 'dashboard', [:superuser, :root] %>" end template "controller_template.rb", "app/controllers/superuser/#{naming(:resources)}_controller.rb" end |
#generate_css_file ⇒ Object
NOTE: the order of the following methods is important!
9 10 11 12 13 14 15 |
# File 'lib/generators/superuser/superuser_generator.rb', line 9 def generate_css_file if !File.exist?("app/assets/stylesheets/superuser/application.scss") copy_file "superuser_base.scss", "app/assets/stylesheets/superuser/application.scss" end end |
#generate_js_file ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/generators/superuser/superuser_generator.rb', line 17 def generate_js_file if !File.exist?("app/assets/javascripts/superuser/application.js") copy_file "superuser_base.js", "app/assets/javascripts/superuser/application.js" end end |
#generate_layout ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/generators/superuser/superuser_generator.rb', line 25 def generate_layout if !File.exist?("app/views/layouts/superuser/application.html.erb") template "views/layouts/application.html.erb", "app/views/layouts/superuser/application.html.erb" end end |
#generate_route_and_link ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/generators/superuser/superuser_generator.rb', line 48 def generate_route_and_link # add resources to route if not exists route_replacement = "resources :#{resources}" r = add_resources_route 'config/routes.rb', search = 'namespace :superuser do', route_replacement # add link to resources in the layout if not exists link = "<%= link_to '#{resources}', [:superuser, :#{resources}] %>" add_layout_links 'app/views/layouts/superuser/application.html.erb', search = '<div class="sidebar_item">', link end |
#generate_search_form ⇒ Object
70 71 72 73 74 |
# File 'lib/generators/superuser/superuser_generator.rb', line 70 def generate_search_form template "views/_search.html.erb", "app/views/shared/_search.html.erb" end |
#generate_views ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/generators/superuser/superuser_generator.rb', line 60 def generate_views template "views/_form.html.erb", "app/views/superuser/#{naming(:resources)}/_form.html.erb" template "views/index.html.erb", "app/views/superuser/#{naming(:resources)}/index.html.erb" template "views/show.html.erb", "app/views/superuser/#{naming(:resources)}/show.html.erb" template "views/new.html.erb", "app/views/superuser/#{naming(:resources)}/new.html.erb" template "views/edit.html.erb", "app/views/superuser/#{naming(:resources)}/edit.html.erb" end |