Class: Quails::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_action_mailer, :skip_javascript, :skip_action_cable, :skip_sprockets, :database, :javascript, :skip_yarn, :api, :quiet, :pretend, :skip ]
Instance Method Summary collapse
- #app ⇒ Object
- #assets_manifest ⇒ 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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 20 def app if mountable? if api? directory "app", exclude_pattern: %r{app/(views|helpers)} else directory "app" empty_directory_with_keep_file "app/assets/images/#{namespaced_name}" end elsif full? empty_directory_with_keep_file "app/models" empty_directory_with_keep_file "app/controllers" empty_directory_with_keep_file "app/mailers" unless api? empty_directory_with_keep_file "app/assets/images/#{namespaced_name}" empty_directory_with_keep_file "app/helpers" empty_directory_with_keep_file "app/views" end end end |
#assets_manifest ⇒ Object
133 134 135 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 133 def assets_manifest template "quails/engine_manifest.js", "app/assets/config/#{underscored_name}_manifest.js" end |
#bin(force = false) ⇒ Object
157 158 159 160 161 162 163 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 157 def bin(force = false) bin_file = engine? ? "bin/quails.tt" : "bin/test.tt" template bin_file, force: force do |content| "#{shebang}\n" + content end chmod "bin", 0755, verbose: false end |
#config ⇒ Object
73 74 75 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 73 def config template "config/routes.rb" if engine? end |
#gemfile ⇒ Object
45 46 47 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 45 def gemfile template "Gemfile" end |
#gemfile_entry ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 165 def gemfile_entry return unless inside_application? gemfile_in_app_path = File.join(quails_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
53 54 55 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 53 def gemspec template "%name%.gemspec" end |
#generate_test_dummy(force = false) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 95 def generate_test_dummy(force = false) opts = ( || {}).slice(*PASSTHROUGH_OPTIONS) opts[:force] = force opts[:skip_bundle] = true opts[:skip_listen] = true opts[:skip_git] = true opts[:skip_turbolinks] = true invoke Quails::Generators::AppGenerator, [ File.(dummy_path, destination_root) ], opts end |
#gitignore ⇒ Object
57 58 59 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 57 def gitignore template "gitignore", ".gitignore" end |
#javascripts ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 146 def javascripts return if .skip_javascript? if mountable? template "quails/javascripts.js", "app/assets/javascripts/#{namespaced_name}/application.js" elsif full? empty_directory_with_keep_file "app/assets/javascripts/#{namespaced_name}" end end |
#lib ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 61 def lib template "lib/%namespaced_name%.rb" template "lib/tasks/%namespaced_name%_tasks.rake" template "lib/%namespaced_name%/version.rb" if engine? template "lib/%namespaced_name%/engine.rb" else template "lib/%namespaced_name%/railtie.rb" end end |
#license ⇒ Object
49 50 51 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 49 def license template "MIT-LICENSE" end |
#rakefile ⇒ Object
16 17 18 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 16 def rakefile template "Rakefile" end |
#readme ⇒ Object
41 42 43 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 41 def readme template "README.md" end |
#stylesheets ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 137 def stylesheets if mountable? copy_file "quails/stylesheets.css", "app/assets/stylesheets/#{namespaced_name}/application.css" elsif full? empty_directory_with_keep_file "app/assets/stylesheets/#{namespaced_name}" end end |
#test ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 77 def test template "test/test_helper.rb" template "test/%namespaced_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
115 116 117 118 119 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 115 def test_dummy_assets template "quails/javascripts.js", "#{dummy_path}/app/assets/javascripts/application.js", force: true template "quails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true template "quails/dummy_manifest.js", "#{dummy_path}/app/assets/config/manifest.js", force: true end |
#test_dummy_clean ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 121 def test_dummy_clean inside dummy_path do remove_file "db/seeds.rb" remove_file "Gemfile" remove_file "lib/tasks" remove_file "public/robots.txt" remove_file "README.md" remove_file "test" remove_file "vendor" end end |
#test_dummy_config ⇒ Object
107 108 109 110 111 112 113 |
# File 'railties/lib/rails/generators/rails/plugin/plugin_generator.rb', line 107 def test_dummy_config template "quails/boot.rb", "#{dummy_path}/config/boot.rb", force: true template "quails/application.rb", "#{dummy_path}/config/application.rb", force: true if mountable? template "quails/routes.rb", "#{dummy_path}/config/routes.rb", force: true end end |