Class: Rails::PluginBuilder
- Defined in:
- railties/lib/rails/generators/rails/plugin/plugin_generator.rb
Overview
The plugin builder allows you to override elements of the plugin generator without being forced to reverse the operations of the default generator.
This allows you to override entire operations, like the creation of the Gemfile, README, or JavaScript files, without needing to know exactly what those operations do so you can create another template action.
Constant Summary collapse
- PASSTHROUGH_OPTIONS =
[ :skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip ]
Instance Method Summary collapse
- #app ⇒ Object
- #bin(force = false) ⇒ Object
- #config ⇒ Object
- #gemfile ⇒ Object
- #gemfile_entry ⇒ Object
- #gemspec ⇒ Object
- #generate_test_dummy(force = false) ⇒ Object
- #gitignore ⇒ Object
- #javascripts ⇒ Object
- #lib ⇒ Object
- #license ⇒ Object
- #rakefile ⇒ Object
- #readme ⇒ Object
- #stylesheets ⇒ Object
- #test ⇒ Object
- #test_dummy_assets ⇒ Object
- #test_dummy_clean ⇒ Object
- #test_dummy_config ⇒ Object
Instance Method Details
#app ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 18 def app if mountable? directory 'app' empty_directory_with_keep_file "app/assets/images/#{name}" elsif full? empty_directory_with_keep_file 'app/models' empty_directory_with_keep_file 'app/controllers' empty_directory_with_keep_file 'app/views' empty_directory_with_keep_file 'app/helpers' empty_directory_with_keep_file 'app/mailers' empty_directory_with_keep_file "app/assets/images/#{name}" end end |
#bin(force = false) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 136 def bin(force = false) return unless engine? directory "bin", force: force do |content| "#{shebang}\n" + content end chmod "bin", 0755, verbose: false end |
#config ⇒ Object
59 60 61 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 59 def config template "config/routes.rb" if engine? end |
#gemfile ⇒ Object
36 37 38 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 36 def gemfile template "Gemfile" end |
#gemfile_entry ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 145 def gemfile_entry return unless inside_application? gemfile_in_app_path = File.join(rails_app_path, "Gemfile") if File.exist? gemfile_in_app_path entry = "gem '#{name}', path: '#{relative_path}'" append_file gemfile_in_app_path, entry end end |
#gemspec ⇒ Object
44 45 46 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 44 def gemspec template "%name%.gemspec" end |
#generate_test_dummy(force = false) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 80 def generate_test_dummy(force = false) opts = ( || {}).slice(*PASSTHROUGH_OPTIONS) opts[:force] = force opts[:skip_bundle] = true invoke Rails::Generators::AppGenerator, [ File.(dummy_path, destination_root) ], opts end |
#gitignore ⇒ Object
48 49 50 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 48 def gitignore template "gitignore", ".gitignore" end |
#javascripts ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 125 def javascripts return if .skip_javascript? if mountable? template "rails/javascripts.js", "app/assets/javascripts/#{name}/application.js" elsif full? empty_directory_with_keep_file "app/assets/javascripts/#{name}" end end |
#lib ⇒ Object
52 53 54 55 56 57 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 52 def lib template "lib/%name%.rb" template "lib/tasks/%name%_tasks.rake" template "lib/%name%/version.rb" template "lib/%name%/engine.rb" if engine? end |
#license ⇒ Object
40 41 42 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 40 def license template "MIT-LICENSE" end |
#rakefile ⇒ Object
14 15 16 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 14 def rakefile template "Rakefile" end |
#readme ⇒ Object
32 33 34 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 32 def readme template "README.rdoc" end |
#stylesheets ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 116 def stylesheets if mountable? copy_file "rails/stylesheets.css", "app/assets/stylesheets/#{name}/application.css" elsif full? empty_directory_with_keep_file "app/assets/stylesheets/#{name}" end end |
#test ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 63 def test template "test/test_helper.rb" template "test/%name%_test.rb" append_file "Rakefile", <<-EOF #{rakefile_test_tasks} task default: :test EOF if engine? template "test/integration/navigation_test.rb" end end |
#test_dummy_assets ⇒ Object
97 98 99 100 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 97 def test_dummy_assets template "rails/javascripts.js", "#{dummy_path}/app/assets/javascripts/application.js", force: true template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true end |
#test_dummy_clean ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 102 def test_dummy_clean inside dummy_path do remove_file ".gitignore" remove_file "db/seeds.rb" remove_file "doc" remove_file "Gemfile" remove_file "lib/tasks" remove_file "public/robots.txt" remove_file "README" remove_file "test" remove_file "vendor" end end |
#test_dummy_config ⇒ Object
89 90 91 92 93 94 95 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 89 def test_dummy_config template "rails/boot.rb", "#{dummy_path}/config/boot.rb", force: true template "rails/application.rb", "#{dummy_path}/config/application.rb", force: true if mountable? template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true end end |