Class: Webring::Generators::CustomWidgetControllerGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Webring::Generators::CustomWidgetControllerGenerator
- Includes:
- Shared::RouteInjector
- Defined in:
- lib/generators/webring/custom_widget_controller/custom_widget_controller_generator.rb
Overview
Note:
This generator should be run after installing the Webring engine
This generator creates both the controller file and adds the required routes
Instance Method Summary collapse
-
#create_controller_file ⇒ Object
Creates the CustomWidgetController file based on the template.
-
#create_custom_widget_routes ⇒ Object
Adds custom widget routes to the application’s routes.rb file These routes are used to create new custom widgets.
Instance Method Details
#create_controller_file ⇒ Object
Creates the CustomWidgetController file based on the template
22 23 24 |
# File 'lib/generators/webring/custom_widget_controller/custom_widget_controller_generator.rb', line 22 def create_controller_file template 'custom_widget_controller.rb', 'app/controllers/webring/custom_widget_controller.rb' end |
#create_custom_widget_routes ⇒ Object
Adds custom widget routes to the application’s routes.rb file These routes are used to create new custom widgets
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/webring/custom_widget_controller/custom_widget_controller_generator.rb', line 28 def routes_file = 'config/routes.rb' = "get 'widget.js', to: 'widget#show', format: 'js', as: :widget" = "get 'widget.js', to: 'custom_widget#show', format: 'js', as: :widget" if File.read(routes_file).include?() gsub_file routes_file, , else route_content = <<~ROUTE scope module: 'webring' do get 'widget.js', to: 'custom_widget#show', format: 'js', as: :widget end ROUTE inject_webring_routes(route_content) end end |