Class: Superuser::InitGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Superuser::InitGenerator
- Defined in:
- lib/generators/superuser/init_generator.rb
Instance Method Summary collapse
- #add_base_route ⇒ Object
-
#add_entry_to_webpack_native_config ⇒ Object
in case of user is using webpack_native gem then add an entry pointing to superuser “application” javascript file.
- #generate_base_controller ⇒ Object
- #generate_css_file ⇒ Object
- #generate_dashboard_controller ⇒ Object
- #generate_js_file ⇒ Object
- #generate_layout ⇒ Object
- #generate_search_form ⇒ Object
Instance Method Details
#add_base_route ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/generators/superuser/init_generator.rb', line 45 def add_base_route path = File.join(destination_root, 'config/routes.rb') file_content = File.read(path) # if namespace for :superuser don't exists then create it unless file_content.include? 'namespace :superuser do' route "\tnamespace :superuser do\n\t\troot to: 'dashboard#index'\n\tend\n" end end |
#add_entry_to_webpack_native_config ⇒ Object
in case of user is using webpack_native gem then add an entry pointing to superuser “application” javascript file
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/generators/superuser/init_generator.rb', line 59 def add_entry_to_webpack_native_config if for_webpack_native webpack_config_file = "#{Rails.root}/app/webpack_native/webpack.config.js" entry_line = "\n\t\t\tsuperuser: './src/javascripts/superuser/application.js'," path = File.join(destination_root, 'app/webpack_native/webpack.config.js') file_content = File.read(path) if file_content.include? 'entry: {' inject_into_file webpack_config_file, entry_line, :after => 'entry: {' puts separator_line note = "Restart rails server (in case it's running) for updates to take place in webpack.config.js" puts "\e[33m#{note}\e[0m" puts separator_line else puts separator_line puts "You need to add the following entry to your webpack.config.js, i.e:\n\n" entry = "entry: { \n superuser: './src/javascripts/superuser/application.js',\n // ...\n}" puts "\e[32m#{entry}\e[0m" note = "\nNote: do not forget to restart your server after that!" puts "\e[33m#{note}\e[0m" puts separator_line end end end |
#generate_base_controller ⇒ Object
27 28 29 30 31 32 |
# File 'lib/generators/superuser/init_generator.rb', line 27 def generate_base_controller superuser_base_controller = "app/controllers/superuser/base_controller.rb" if !File.exist?(superuser_base_controller) copy_file "base_controller.rb", superuser_base_controller end end |
#generate_css_file ⇒ Object
6 7 8 9 10 11 |
# File 'lib/generators/superuser/init_generator.rb', line 6 def generate_css_file superuser_css_file = "#{stylesheets_folder()}/superuser.scss" if !File.exist?(superuser_css_file) copy_file "superuser_base.scss", superuser_css_file end end |
#generate_dashboard_controller ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/superuser/init_generator.rb', line 34 def generate_dashboard_controller superuser_dashboard_controller = "app/controllers/superuser/dashboard_controller.rb" if !File.exist?(superuser_dashboard_controller) copy_file "dashboard_controller.rb", superuser_dashboard_controller copy_file "views/dashboard_index.html.erb", "app/views/superuser/dashboard/index.html.erb" add_layout_links 'app/views/layouts/superuser/application.html.erb', search = '<div class="sidebar_dashboard_link">', "<%= link_to 'dashboard', [:superuser, :root] %>" end end |
#generate_js_file ⇒ Object
13 14 15 16 17 18 |
# File 'lib/generators/superuser/init_generator.rb', line 13 def generate_js_file superuser_js_file = "#{javascripts_folder()}/superuser.js" if !File.exist?(superuser_js_file) copy_file "superuser_base.js", superuser_js_file end end |
#generate_layout ⇒ Object
20 21 22 23 24 25 |
# File 'lib/generators/superuser/init_generator.rb', line 20 def generate_layout superuser_layout_file = "app/views/layouts/superuser/application.html.erb" if !File.exist?(superuser_layout_file) template "views/layouts/application.html.erb", superuser_layout_file end end |
#generate_search_form ⇒ Object
54 55 56 |
# File 'lib/generators/superuser/init_generator.rb', line 54 def generate_search_form template "views/_search.html.erb", "app/views/shared/superuser/_search.html.erb" end |