Class: Moderate::Generators::ViewsGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Moderate::Generators::ViewsGenerator
- Defined in:
- lib/generators/moderate/views_generator.rb
Overview
‘rails generate moderate:views` — eject the engine’s overridable templates into the HOST app so they can be restyled. This is the Devise move (‘rails g devise:views`), and it works for the same boring Rails reason: the host app’s ‘app/views` sits AHEAD of any engine’s view paths in the lookup chain, so a file copied to ‘app/views/moderate/notices/new.html.erb` SHADOWS the gem’s bundled default automatically — no config, no registration. Delete your copy and the gem’s default comes back. Upgrade the gem and your ejected copies are untouched (re-run only if you WANT the new defaults).
‘source_root` points at the engine’s own ‘app/views`, so `copy_file` / `directory` read the exact templates the engine renders.
Instance Method Summary collapse
Instance Method Details
#copy_views ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/moderate/views_generator.rb', line 31 def copy_views # The whole notices directory (new/show + any partials that ship with it). directory "moderate/notices", "app/views/moderate/notices" if include?("notices") # Just the field partial, for the "I only want to restyle the fields" path. # Guarded by File.exist? so the generator doesn't fail if the partial isn't # part of the shipped set in a given version. if include?("form") && !include?("notices") partial = "moderate/notices/_form.html.erb" copy_file partial, "app/views/#{partial}" if engine_view_exists?(partial) end # The engine layout (only if one ships under layouts/moderate). if include?("layout") directory "layouts/moderate", "app/views/layouts/moderate" if engine_view_exists?("layouts/moderate") end end |