Class: BoGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- BoGenerator
- Defined in:
- lib/generators/bo/bo_generator.rb
Instance Method Summary collapse
Instance Method Details
#add_link_to_side_bar ⇒ Object
30 31 32 33 34 |
# File 'lib/generators/bo/bo_generator.rb', line 30 def inject_into_file "app/views/#{options[:namespace]}/layouts/_side_bar.html.erb", before: " <%= sidebar.with_current_user_card(user: current_#{options[:namespace].singularize}) %>\n" do " <%= sidebar.with_item(path: #{options[:namespace]}_#{plural_name}_path, icon: Icons::UsersComponent, label: I18n.t('bo.#{file_name}.others').capitalize) %>\n" end end |
#create_bo_file ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/generators/bo/bo_generator.rb', line 10 def create_bo_file check_model_existence # Template method # First argument is the name of the template # Second argument is where to create the resulting file. In this case, app/bo/my_bo.rb template 'new.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/new.html.erb") template 'item.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/_#{file_name.underscore}.html.erb") template '_form.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/_form.html.erb") template 'index.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/index.html.erb") template '_table.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/_table.html.erb") template '_search_bar.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/_search_bar.html.erb") template 'show.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/show.html.erb") template 'controller.rb', File.join("app/controllers/#{options[:namespace]}", "#{plural_name}_controller.rb") template 'policy.rb', File.join("app/policies/bo/#{options[:namespace]}", "#{file_name.underscore}_policy.rb") unless File.exist?("app/policies/bo/#{options[:namespace]}_policy.rb") template 'namespace_policy.rb', "app/policies/bo/#{options[:namespace]}_policy.rb" end create_translations end |
#create_routes ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/generators/bo/bo_generator.rb', line 36 def create_routes rails_routes = Rails.application.routes.named_routes.names.map(&:to_s) return if rails_routes.any?("#{options[:namespace]}_#{plural_name}") inject_into_file 'config/routes.rb', after: " namespace :#{options[:namespace]} do\n" do " resources :#{plural_name} do\n get 'export_csv', on: :collection\n end\n" end end |