Class: Chats::Generators::ViewsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/chats/views_generator.rb

Overview

‘rails generate chats: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 e.g. ‘app/views/chats/messages/_message.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 `directory` copies the exact templates the engine renders.

Instance Method Summary collapse

Instance Method Details

#copy_viewsObject



30
31
32
33
34
# File 'lib/generators/chats/views_generator.rb', line 30

def copy_views
  directory "chats/conversations", "app/views/chats/conversations" if include?("conversations")
  directory "chats/messages", "app/views/chats/messages" if include?("messages")
  directory "chats/shared", "app/views/chats/shared" if include?("shared")
end

#show_styling_tipObject



36
37
38
39
40
# File 'lib/generators/chats/views_generator.rb', line 36

def show_styling_tip
  say "\n🎨 Views copied. They render with the gem's bundled chats.css by default;"
  say "   restyle freely — if your app uses Tailwind, classes you add here are"
  say "   picked up by your build automatically (the files now live in app/views)."
end