Class: TurboCable::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/turbo_cable/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_controller_to_layoutObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/turbo_cable/install/install_generator.rb', line 11

def add_controller_to_layout
  layout_file = "app/views/layouts/application.html.erb"

  if File.exist?(layout_file)
    # Check if already added
    content = File.read(layout_file)
    unless content.include?('data-controller="turbo-streams"')
      inject_into_file layout_file,
        ' data-controller="turbo-streams"',
        after: "<body"
    end
  else
    say "WARNING: Could not find #{layout_file}", :yellow
    say "Please add data-controller=\"turbo-streams\" to your <body> tag manually", :yellow
  end
end

#copy_javascript_controllerObject



6
7
8
9
# File 'lib/generators/turbo_cable/install/install_generator.rb', line 6

def copy_javascript_controller
  copy_file "turbo_streams_controller.js",
    "app/javascript/controllers/turbo_streams_controller.js"
end

#show_readmeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/turbo_cable/install/install_generator.rb', line 28

def show_readme
  say "\n" + "=" * 70
  say "TurboCable Installation Complete!", :green
  say "=" * 70
  say "\nNext steps:"
  say "  1. Restart your Rails server"
  say "  2. Use turbo_stream_from in your views"
  say "  3. Use broadcast_* methods in your models"
  say "\nExample usage:"
  say "  # In your view"
  say '  <%= turbo_stream_from "counter_updates" %>'
  say "\n  # In your model"
  say '  broadcast_replace_later_to "counter_updates", target: "counter"'
  say "\nFor more information, see the README at:"
  say "  https://github.com/rubys/turbo_cable"
  say "\n" + "=" * 70 + "\n"
end