Permalink
Browse files

treat USAGE as an ERB template

  • Loading branch information...
1 parent 836b620 commit 5745a5e85e1900c52d169f79ec0802060e110e21 @sinisterchipmunk committed Nov 2, 2011
@@ -34,7 +34,7 @@ def self.desc(description=nil)
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 %> ::
@@ -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 @@ def test_source_paths_for_not_namespaced_generators
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

0 comments on commit 5745a5e

Please sign in to comment.