mirror of https://github.com/rails/rails
Merge pull request #3494 from sinisterchipmunk/usage-erb
treat USAGE as an ERB template
This commit is contained in:
commit
982a0f37f5
|
@ -34,7 +34,7 @@ module Rails
|
|||
usage = source_root && File.expand_path("../USAGE", source_root)
|
||||
|
||||
@desc ||= if usage && File.exist?(usage)
|
||||
File.read(usage)
|
||||
ERB.new(File.read(usage)).result(binding)
|
||||
else
|
||||
"Description:\n Create #{base_name.humanize.downcase} files for #{generator_name} generator."
|
||||
end
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
:: <%= 1 + 1 %> ::
|
5
railties/test/fixtures/lib/generators/usage_template/usage_template_generator.rb
vendored
Normal file
5
railties/test/fixtures/lib/generators/usage_template/usage_template_generator.rb
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'rails/generators'
|
||||
|
||||
class UsageTemplateGenerator < Rails::Generators::Base
|
||||
source_root File.expand_path("templates", File.dirname(__FILE__))
|
||||
end
|
|
@ -201,4 +201,10 @@ class GeneratorsTest < Rails::Generators::TestCase
|
|||
mspec = Rails::Generators.find_by_namespace :fixjour
|
||||
assert mspec.source_paths.include?(File.join(Rails.root, "lib", "templates", "fixjour"))
|
||||
end
|
||||
|
||||
def test_usage_with_embedded_ruby
|
||||
require File.expand_path("fixtures/lib/generators/usage_template/usage_template_generator", File.dirname(__FILE__))
|
||||
output = capture(:stdout) { Rails::Generators.invoke :usage_template, ['--help'] }
|
||||
assert_match /:: 2 ::/, output
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue