mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add config.generators.templates to provide alternative paths for template lookup.
This commit is contained in:
parent
1d9d9d2d89
commit
6958eac1a0
7 changed files with 18 additions and 14 deletions
|
@ -88,12 +88,13 @@ module Rails
|
|||
end
|
||||
|
||||
class Generators #:nodoc:
|
||||
attr_accessor :aliases, :options, :fallbacks, :colorize_logging
|
||||
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
|
||||
|
||||
def initialize
|
||||
@aliases = Hash.new { |h,k| h[k] = {} }
|
||||
@options = Hash.new { |h,k| h[k] = {} }
|
||||
@fallbacks = {}
|
||||
@templates = []
|
||||
@colorize_logging = true
|
||||
end
|
||||
|
||||
|
|
|
@ -102,6 +102,10 @@ module Rails
|
|||
app.metal_loader.paths.unshift(*paths.app.metals.to_a)
|
||||
end
|
||||
|
||||
initializer :add_generator_templates do |app|
|
||||
config.generators.templates.unshift(*paths.lib.templates.to_a)
|
||||
end
|
||||
|
||||
initializer :load_application_initializers do
|
||||
paths.config.initializers.to_a.sort.each do |initializer|
|
||||
load(initializer)
|
||||
|
|
|
@ -21,6 +21,7 @@ module Rails
|
|||
paths.app.views "app/views"
|
||||
paths.lib "lib", :load_path => true
|
||||
paths.lib.tasks "lib/tasks", :glob => "**/*.rake"
|
||||
paths.lib.templates "lib/templates"
|
||||
paths.config "config"
|
||||
paths.config.initializers "config/initializers", :glob => "**/*.rb"
|
||||
paths.config.locales "config/locales", :glob => "*.{rb,yml}"
|
||||
|
|
|
@ -66,6 +66,11 @@ module Rails
|
|||
aliases.deep_merge! config.aliases
|
||||
options.deep_merge! config.options
|
||||
fallbacks.merge! config.fallbacks
|
||||
templates_path.concat config.templates
|
||||
end
|
||||
|
||||
def self.templates_path
|
||||
@templates_path ||= []
|
||||
end
|
||||
|
||||
def self.aliases #:nodoc:
|
||||
|
|
|
@ -213,8 +213,7 @@ module Rails
|
|||
if base.name && base.name !~ /Base$/
|
||||
Rails::Generators.subclasses << base
|
||||
|
||||
if defined?(Rails.root) && Rails.root
|
||||
path = File.expand_path(File.join(Rails.root, 'lib', 'templates'))
|
||||
Rails::Generators.templates_path.each do |path|
|
||||
if base.name.include?('::')
|
||||
base.source_paths << File.join(path, base.base_name, base.generator_name)
|
||||
else
|
||||
|
|
|
@ -52,30 +52,23 @@ module ApplicationTests
|
|||
end
|
||||
end
|
||||
|
||||
test "generators set rails fallbacks" do
|
||||
with_config do |c|
|
||||
c.generators.fallbacks[:shoulda] = :test_unit
|
||||
expected = { :shoulda => :test_unit }
|
||||
assert_equal expected, c.generators.fallbacks
|
||||
end
|
||||
end
|
||||
|
||||
test "generators aliases, options and fallbacks on initialization" do
|
||||
test "generators aliases, options, templates and fallbacks on initialization" do
|
||||
add_to_config <<-RUBY
|
||||
config.generators.rails :aliases => { :test_framework => "-w" }
|
||||
config.generators.orm :datamapper
|
||||
config.generators.test_framework :rspec
|
||||
config.generators.fallbacks[:shoulda] = :test_unit
|
||||
config.generators.templates << "some/where"
|
||||
RUBY
|
||||
|
||||
# Initialize the application
|
||||
require "#{app_path}/config/environment"
|
||||
require "rails/generators"
|
||||
Rails::Generators.configure!
|
||||
|
||||
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
|
||||
assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
|
||||
assert_equal :test_unit, Rails::Generators.fallbacks[:shoulda]
|
||||
assert_equal Hash[:shoulda => :test_unit], Rails::Generators.fallbacks
|
||||
assert_equal ["#{app_path}/lib/templates", "some/where"], Rails::Generators.templates_path
|
||||
end
|
||||
|
||||
test "generators no color on initialization" do
|
||||
|
|
|
@ -6,6 +6,7 @@ module Rails
|
|||
end
|
||||
end
|
||||
Rails.application.config.root = Rails.root
|
||||
Rails.application.config.generators.templates = [File.join(Rails.root, "lib", "templates")]
|
||||
|
||||
require 'rails/generators'
|
||||
require 'rails/generators/test_case'
|
||||
|
|
Loading…
Reference in a new issue