1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

treat USAGE as an ERB template

This commit is contained in:
Colin MacKenzie IV 2011-11-02 09:00:18 -04:00
parent 836b620850
commit 5745a5e85e
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