Class: WiserChat::Generators::InstallGenerator

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

Overview

Install generator that creates migration file from template

Instance Method Summary collapse

Instance Method Details

#create_events_initializer_fileObject


11
12
13
14
15
16
17
18
19
# File 'lib/generators/wiser_chat/install/install_generator.rb', line 11

def create_events_initializer_file
  timestamp = Time.now.strftime("%Y%m%d%H%M%S")
  template 'events.rb', File.join('config', 'events.rb')
  template 'websocket.rb', File.join('config', 'initializers', 'websocket_rails.rb')
  template 'stylesheet.css', File.join('app', 'assets', 'stylesheets', 'wiser_chat.css')
  template 'javascript.js', File.join('app', 'assets', 'javascripts', 'wiser_chat.js')
  template 'partial.html.haml', File.join('app', 'views', 'layouts', '_wiser_chat.html.haml')
  template 'migration.rb', File.join('db', 'migrate', "#{timestamp}_create_wiser_chat_messages.rb")
end

#inject_websocket_rails_clientObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/wiser_chat/install/install_generator.rb', line 21

def inject_websocket_rails_client
  js_manifest = options[:js_manifest]
  js_path  = "app/assets/javascripts"
  create_file("#{js_path}/#{js_manifest}") unless File.exists?("#{js_path}/#{js_manifest}")
  append_to_file "#{js_path}/#{js_manifest}" do
    out = ""
    out << "\n"
    out << "//= require jquery.moment"
    out << "\n"
    out << "//= require websocket_rails/main"
    out << "\n"
    out << "//= require wiser_chat"
  end
end