Class: Cable::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/cable/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/generators/cable/install_generator.rb', line 63

def self.next_migration_number(dirname)
 if ActiveRecord::Base.timestamped_migrations
   Time.now.utc.strftime("%Y%m%d%H%M%S") + (rand(6) + rand(5)).to_s
 else
   "%.3d" % (current_migration_number(dirname) + 1)
 end
end

Instance Method Details

#copy_simple_navObject



34
35
36
37
38
39
# File 'lib/generators/cable/install_generator.rb', line 34

def copy_simple_nav
  if options.simple_nav?
    copy_file 'config/admin_navigation.rb', 'config/admin_navigation.rb'
    copy_file 'config/navigation.rb', 'config/navigation.rb'
  end
end

#create_blocksObject



25
26
27
28
29
30
31
32
# File 'lib/generators/cable/install_generator.rb', line 25

def create_blocks
  if options.blocks?
    migration_template 'lib/generators/templates/create_blocks.rb', 'db/migrate/create_blocks.rb'
    copy_file 'lib/generators/templates/block.rb', 'app/models/block.rb'
    copy_file 'lib/generators/templates/partials/_block.html.erb', 'app/views/admin/partials/_block.html.erb'
    copy_file 'lib/generators/templates/partials/_block_form.html.erb', 'app/views/admin/partials/_block_form.html.erb'
  end
end

#create_settingsObject



18
19
20
21
22
23
# File 'lib/generators/cable/install_generator.rb', line 18

def create_settings
  if options.settings?
   migration_template 'lib/generators/templates/create_cable_settings.rb', "db/migrate/create_cable_settings.rb"
   route( 'cable_to :cable_settings' ) if options.settings?
 end
end

#install_adminObject



45
46
47
# File 'lib/generators/cable/install_generator.rb', line 45

def install_admin
  copy_file "app/views/layouts/admin.html.erb", 'app/views/layouts/admin.html.erb'
end

#install_initializerObject



41
42
43
# File 'lib/generators/cable/install_generator.rb', line 41

def install_initializer
  copy_file "lib/generators/templates/initializer.rb", "config/initializers/cable.rb"
end

#install_routesObject



49
50
# File 'lib/generators/cable/install_generator.rb', line 49

def install_routes
end

hook_for :orm, :as => :migration



53
54
55
56
57
58
59
60
61
# File 'lib/generators/cable/install_generator.rb', line 53

def print_setup_instructions
  puts ""
  puts "Run rake db:migrate to complete setup."
  puts ""
  puts "To begin using Cable Menu and Pages use:"
  puts "rails generate cable:menu MENU_NAME"
  puts "rails generate cable:resource PAGE_NAME field:type field:type ..."
  puts ""
end