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



88
89
90
91
92
93
94
# File 'lib/generators/cable/install_generator.rb', line 88

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



43
44
45
46
47
48
49
50
51
# File 'lib/generators/cable/install_generator.rb', line 43

def copy_simple_nav
  if options.simple_nav?
    if yes?("Would you like to install simple navigation?".color(:yellow) ) 
      generate("navigation_config")
      copy_file 'config/admin_navigation.rb', 'config/admin_navigation.rb'
        # copy_file 'config/navigation.rb', 'config/navigation.rb'
    end
  end
end

#create_blocksObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/cable/install_generator.rb', line 31

def create_blocks
  if options.blocks?
    begin
      migration_template 'lib/generators/templates/create_blocks.rb', 'db/migrate/create_blocks.rb'
    rescue
      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
end

#create_settingsObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/cable/install_generator.rb', line 20

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

    end
 end
end

#install_adminObject



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

def install_admin
  copy_file "app/views/layouts/admin.html.erb", 'app/views/layouts/admin.html.erb'
  directory 'app/views/layouts/admin', 'app/views/layouts/admin'
  directory "public/stylesheets/tinymce", "public/stylesheets/tinymce"
end

#install_cocoonObject



69
70
71
72
# File 'lib/generators/cable/install_generator.rb', line 69

def install_cocoon
    generate('cocoon:install')
    insert_into_file 'app/views/layouts/admin.html.erb', "<%= javascript_include_tag :cocoon %>\n", :before => '<%= yield :scripts %>'
end

#install_initializerObject



59
60
61
# File 'lib/generators/cable/install_generator.rb', line 59

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

#install_jqueryObject



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

def install_jquery
  if yes?("Dost thou require jquery?".color(:yellow))
    generate("jquery:install --ui")
  end
end

#install_routesObject



74
75
# File 'lib/generators/cable/install_generator.rb', line 74

def install_routes
end

hook_for :orm, :as => :migration



78
79
80
81
82
83
84
85
86
# File 'lib/generators/cable/install_generator.rb', line 78

def print_setup_instructions
  puts ""
  puts "Run rake db:migrate to complete setup.".color(:yellow)
  puts ""
  puts "To begin using Cable Menu and Resources use:".color(:green)
  puts "rails generate cable:menu MENU_NAME"
  puts "rails generate cable:resource RESOURCE_NAME field:type field:type ..."
  puts ""
end