Class: Batman::Generators::AppGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Batman::Generators::AppGenerator
- Includes:
- Common
- Defined in:
- lib/generators/batman/app_generator.rb
Instance Method Summary collapse
- #app_requires ⇒ Object
- #batman_requires ⇒ Object
- #create_app ⇒ Object
- #create_default_controllers ⇒ Object
- #create_directories ⇒ Object
- #es5_requires ⇒ Object
- #inject_batman ⇒ Object
- #jquery_requires ⇒ Object
- #precompile_app ⇒ Object
- #route_catchall ⇒ Object
- #setup_rails ⇒ Object
Methods included from Common
Instance Method Details
#app_requires ⇒ Object
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_requires ⇒ Object
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_app ⇒ Object
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_controllers ⇒ Object
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_directories ⇒ Object
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 [:skip_git] end end |
#es5_requires ⇒ Object
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_batman ⇒ Object
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 [:skip_jquery] prepend_file application_file, batman_requires prepend_file application_file, es5_requires unless [:skip_es5] end end |
#jquery_requires ⇒ Object
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_app ⇒ Object
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_catchall ⇒ Object
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_rails ⇒ Object
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 |