class Rails::PluginBuilder
what those operations do so you can create another template action.
Gemfile, README, or JavaScript files, without needing to know exactly
This allows you to override entire operations, like the creation of the
generator.
generator without being forced to reverse the operations of the default
The plugin builder allows you to override elements of the plugin
def app
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
def bin(force = false)
def bin(force = false) return unless engine? directory "bin", force: force do |content| "#{shebang}\n" + content end chmod "bin", 0755, verbose: false end
def config
def config template "config/routes.rb" if engine? end
def gemfile
def gemfile template "Gemfile" end
def gemfile_entry
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
def gemspec
def gemspec template "%name%.gemspec" end
def generate_test_dummy(force = false)
def generate_test_dummy(force = false) opts = (options || {}).slice(*PASSTHROUGH_OPTIONS) opts[:force] = force opts[:skip_bundle] = true invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path, destination_root) ], opts end
def gitignore
def gitignore template "gitignore", ".gitignore" end
def javascripts
def javascripts return if options.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
def lib
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
def license
def license template "MIT-LICENSE" end
def rakefile
def rakefile template "Rakefile" end
def readme
def readme template "README.rdoc" end
def stylesheets
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
def test
def test template "test/test_helper.rb" template "test/%name%_test.rb" append_file "Rakefile", <<-EOF kefile_test_tasks} default: :test EOF if engine? template "test/integration/navigation_test.rb" end end
def test_dummy_assets
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
def test_dummy_clean
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
def test_dummy_config
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