diff --git a/features/ruby_gemfile.feature b/features/ruby_gemfile.feature index 8156346..5621bef 100644 --- a/features/ruby_gemfile.feature +++ b/features/ruby_gemfile.feature @@ -263,3 +263,18 @@ Feature: Gemfiles # generated by penchant, environment: local gem "one", {:git=>"git://github.com/john/one.git"} """ + + Scenario: Define special expansions for properties as a hash + Given I have the file "Gemfile.penchant" with the content: + """ + defaults_for env(:local), :path => '../%s' + property :github, :git => "git://github.com/$1/%s.git" + gem 'one', :github => 'john' + """ + When I rebuild the Gemfile for "local" mode + Then the file "Gemfile" should have the following content: + """ + # generated by penchant, environment: local + gem "one", {:git=>"git://github.com/john/one.git"} + """ + diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 27b9f30..9a45b53 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -151,8 +151,8 @@ module Penchant end end - def property(name, &block) - @properties[name] = block + def property(name, hash = nil, &block) + @properties[name] = hash || block end def for_environment?(envs) @@ -204,9 +204,18 @@ module Penchant while !property_stack.empty? key, value = property_stack.shift - if @properties[key] - @properties[key].call(*([ value ].flatten)).each do |k, v| - property_stack.push([ k, v ]) + if property = @properties[key] + values = [ value ].flatten + + if property.respond_to?(:call) + property.call(*values).each do |k, v| + property_stack.push([ k, v ]) + end + else + property.each do |k, v| + v = v.dup.gsub(%r{\$(\d+)}) { |m| values[m.to_i - 1 ] } + property_stack.push([ k, v ]) + end end else value = value % gem_name if value.respond_to?(:%) @@ -238,6 +247,8 @@ module Penchant class ERBFile < FileProcessor def handle_result(data) + $stderr.puts "ERB files are deprecated. Please convert them to the Ruby format." + @output << ERB.new(data, nil, nil, '@_erbout').result(binding) end diff --git a/lib/penchant/version.rb b/lib/penchant/version.rb index 022bebb..f755ab7 100644 --- a/lib/penchant/version.rb +++ b/lib/penchant/version.rb @@ -1,3 +1,3 @@ module Penchant - VERSION = "0.2.10" + VERSION = "0.2.11" end