diff options
Diffstat (limited to 'railties')
4 files changed, 13 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 911f80cf3a..f38a487a4e 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -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 diff --git a/railties/test/fixtures/lib/generators/usage_template/USAGE b/railties/test/fixtures/lib/generators/usage_template/USAGE new file mode 100644 index 0000000000..bcd63c52e2 --- /dev/null +++ b/railties/test/fixtures/lib/generators/usage_template/USAGE @@ -0,0 +1 @@ +:: <%= 1 + 1 %> ::
\ No newline at end of file diff --git a/railties/test/fixtures/lib/generators/usage_template/usage_template_generator.rb b/railties/test/fixtures/lib/generators/usage_template/usage_template_generator.rb new file mode 100644 index 0000000000..078b0f9412 --- /dev/null +++ b/railties/test/fixtures/lib/generators/usage_template/usage_template_generator.rb @@ -0,0 +1,5 @@ +require 'rails/generators' + +class UsageTemplateGenerator < Rails::Generators::Base + source_root File.expand_path("templates", File.dirname(__FILE__)) +end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 56329f3183..5f9ee220dc 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -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 |