Merge pull request #3494 from sinisterchipmunk/usage-erb

treat USAGE as an ERB template
This commit is contained in:
José Valim 2011-11-02 06:41:46 -07:00
commit 982a0f37f5
4 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1 @@
:: <%= 1 + 1 %> ::

View File

@ -0,0 +1,5 @@
require 'rails/generators'
class UsageTemplateGenerator < Rails::Generators::Base
source_root File.expand_path("templates", File.dirname(__FILE__))
end

View File

@ -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