Class: DragonRuby::Generators::MountGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- DragonRuby::Generators::MountGenerator
- Defined in:
- lib/generators/dragonruby/mount/mount_generator.rb
Overview
rails g dragonruby:mount underwater
Writes the one line that is easy to get subtly wrong: the mount has to point at a directory outside public/, and the game is linked with a trailing slash.
The namespace is declared rather than derived. Rails would camelize "dragonruby" to Dragonruby and look for that constant; the gem's module is DragonRuby, so the two are spelled out separately here.
Instance Method Summary collapse
Instance Method Details
#add_the_mount ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/dragonruby/mount/mount_generator.rb', line 30 def add_the_mount routes = File.join(destination_root, "config/routes.rb") unless File.exist?(routes) say_status :skip, "config/routes.rb not found — add this yourself:\n#{mount_line}", :yellow return end if File.read(routes).include?(%("#{url_path}")) say_status :identical, "#{url_path} is already mounted in config/routes.rb", :blue return end inject_into_file "config/routes.rb", comment + mount_line + "\n", after: /Rails\.application\.routes\.draw do\n/ end |
#create_bundle_directory ⇒ Object
25 26 27 28 |
# File 'lib/generators/dragonruby/mount/mount_generator.rb', line 25 def create_bundle_directory empty_directory bundle_path create_file File.join(bundle_path, ".keep"), "" unless File.exist?(File.join(destination_root, bundle_path, ".keep")) end |
#tell_them_what_is_missing ⇒ Object
46 47 48 49 50 |
# File 'lib/generators/dragonruby/mount/mount_generator.rb', line 46 def tell_them_what_is_missing say_status :next, "put an HTML5 export into #{bundle_path}, e.g.:", :green say " rake dragonruby:install[path/to/#{name}-html5.zip,#{name}]" say_status :link, "then the game is at #{url_path}/ (the trailing slash matters in links)", :green end |