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



105
106
107
108
109
110
111
112
113
114
# File 'lib/generators/batman/app_generator.rb', line 105

def app_requires
<<-CODE
#= require_self

#= require_tree ./lib
#= require_tree ./controllers
#= require_tree ./models
#= require_tree ./views\n
CODE
end

#batman_requiresObject



91
92
93
94
95
96
# File 'lib/generators/batman/app_generator.rb', line 91

def batman_requires
<<-CODE
#= require batman/batman
#= require batman/batman.rails\n
CODE
end

#create_appObject



38
39
40
41
42
# File 'lib/generators/batman/app_generator.rb', line 38

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

#create_default_controllersObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/generators/batman/app_generator.rb', line 51

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"
    template "batman/main_index_view.coffee", "#{app_path}/views/main/main_index_view.js.coffee"
  end
end

#create_directoriesObject



44
45
46
47
48
49
# File 'lib/generators/batman/app_generator.rb', line 44

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



85
86
87
88
89
# File 'lib/generators/batman/app_generator.rb', line 85

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

#inject_batmanObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/batman/app_generator.rb', line 62

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



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

def jquery_requires
<<-CODE
#= require jquery
#= require batman/batman.jquery\n
CODE
end

#precompile_appObject



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

def precompile_app
<<-CODE
\n    config.assets.precompile += ['#{application_name}.js']\n
CODE
end

#route_catchallObject



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

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

#setup_railsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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 => "Rails.application.routes.draw do\n"  do
        route_catchall
      end

      inject_into_file "config/application.rb", :after => "class Application < Rails::Application\n" do
        precompile_app
      end
    end

  end
end