Class: Podium::PodletGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Podium::PodletGenerator
- Defined in:
- lib/generators/podium/podlet_generator.rb
Constant Summary collapse
- APP_CONTROLLER_PATH =
"app/controllers/application_controller.rb"
- PREVIEW_CONTROLLER_PATH =
"app/controllers/podlet_preview_controller.rb"
- LAYOUT_PATH =
"app/views/layouts/application.html.erb"
Instance Method Summary collapse
- #create_controller ⇒ Object
- #create_views ⇒ Object
- #prepare_assets ⇒ Object
- #setup_preview ⇒ Object
- #setup_routes ⇒ Object
Instance Method Details
#create_controller ⇒ Object
13 14 15 |
# File 'lib/generators/podium/podlet_generator.rb', line 13 def create_controller template "podlet_controller.rb", "app/controllers/#{controller_file_name}" end |
#create_views ⇒ Object
17 18 19 |
# File 'lib/generators/podium/podlet_generator.rb', line 17 def create_views template "content.html.erb", "app/views/#{folder_name}/content.html.erb" end |
#prepare_assets ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/generators/podium/podlet_generator.rb', line 21 def prepare_assets create_file "app/assets/javascripts/#{folder_name}/podlet.js" create_file "app/assets/stylesheets/#{folder_name}/podlet.css" return if contents("app/assets/config/manifest.js").include?(folder_name) append_to_file "app/assets/config/manifest.js", "//= link_directory ../javascripts/#{folder_name} .js\n" append_to_file "app/assets/config/manifest.js", "//= link_directory ../stylesheets/#{folder_name} .css\n" end |
#setup_preview ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/generators/podium/podlet_generator.rb', line 40 def setup_preview unless preview_exists? template "podlet_preview_controller.rb", PREVIEW_CONTROLLER_PATH end return if contents(PREVIEW_CONTROLLER_PATH).include?(podlet_name) podlet_action = <<-RUBY \ndef #{podlet_name} resource = podlet_resource(:#{podlet_name}) render html: resource.fetch({}).html_safe end RUBY inject_into_file PREVIEW_CONTROLLER_PATH, podlet_action, before: "\nend" end |
#setup_routes ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/podium/podlet_generator.rb', line 29 def setup_routes route = "podlet :#{podlet_name}" return if route_present?(route) if route_present?("podlet_preview") inject_into_file "config/routes.rb", "\n #{route}", before: "\n podlet_preview" else inject_into_file "config/routes.rb", "\n #{route}", before: "\nend" inject_into_file "config/routes.rb", "\n podlet_preview if Rails.env.development?", before: "\nend" end end |