Class: Batman::Generators::AppGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Common
Defined in:
lib/generators/batman/app_generator.rb

Instance Method Summary collapse

Methods included from Common

included

Instance Method Details

#app_requiresObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/generators/batman/app_generator.rb', line 94

def app_requires
"#= require_self\n\n#= require_tree ./lib\n#= require_tree ./controllers\n#= require_tree ./models\n#= require_tree ./views\\n\n"
end

#batman_requiresObject



80
81
82
83
84
85
# File 'lib/generators/batman/app_generator.rb', line 80

def batman_requires
"#= require batman/batman\n#= require batman/batman.rails\\n\n"
end

#create_appObject



34
35
36
37
38
# File 'lib/generators/batman/app_generator.rb', line 34

def create_app
  with_app_name do
    template "batman/batman_app.coffee", "#{app_path}/#{application_name}.js.coffee"
  end
end

#create_default_controllersObject



47
48
49
50
51
52
53
54
55
# File 'lib/generators/batman/app_generator.rb', line 47

def create_default_controllers
  with_app_name do
    empty_directory "#{app_path}/html/main"

    template "batman/application_controller.coffee", "#{app_path}/controllers/application_controller.js.coffee"
    template "batman/main_controller.coffee", "#{app_path}/controllers/main_controller.js.coffee"
    template "batman/html/main_index.html", "#{app_path}/html/main/index.html"
  end
end

#create_directoriesObject



40
41
42
43
44
45
# File 'lib/generators/batman/app_generator.rb', line 40

def create_directories
  %w(models views controllers html lib).each do |dir|
    empty_directory "#{app_path}/#{dir}"
    create_file "#{app_path}/#{dir}/.gitkeep" unless options[:skip_git]
  end
end

#es5_requiresObject



74
75
76
77
78
# File 'lib/generators/batman/app_generator.rb', line 74

def es5_requires
"#= require batman/es5-shim\\n\n"
end

#inject_batmanObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/generators/batman/app_generator.rb', line 57

def inject_batman
  with_app_name do
    application_file = File.join(app_path, "#{application_name}.js.coffee")

    prepend_file application_file, app_requires
    prepend_file application_file, jquery_requires unless options[:skip_jquery]
    prepend_file application_file, batman_requires
    prepend_file application_file, es5_requires unless options[:skip_es5]
  end
end

#jquery_requiresObject



87
88
89
90
91
92
# File 'lib/generators/batman/app_generator.rb', line 87

def jquery_requires
"#= require jquery\n#= require batman/batman.jquery\\n\n"
end

#route_catchallObject



68
69
70
71
72
# File 'lib/generators/batman/app_generator.rb', line 68

def route_catchall
"\\n  get \"(*redirect_path)\", to: \"\#{app_name}\\#index\", constraints: lambda { |request| request.format == \"text/html\" }\\n\n"
end

#setup_railsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/batman/app_generator.rb', line 20

def setup_rails
  with_app_name do
    template "rails/controller.rb", "app/controllers/#{app_name}_controller.rb"
    template "rails/layout.html", "app/views/layouts/#{app_name}.html.erb"

    unless ENV["RAILS_ENV"] == "test"
      inject_into_file "config/routes.rb", :after => "#{js_application_name}::Application.routes.draw do\n"  do
        route_catchall
      end
    end

  end
end