support properties as hashes, too
This commit is contained in:
parent
1ac9b52ae2
commit
6679a65cdf
@ -263,3 +263,18 @@ Feature: Gemfiles
|
|||||||
# generated by penchant, environment: local
|
# generated by penchant, environment: local
|
||||||
gem "one", {:git=>"git://github.com/john/one.git"}
|
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"}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@ -151,8 +151,8 @@ module Penchant
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def property(name, &block)
|
def property(name, hash = nil, &block)
|
||||||
@properties[name] = block
|
@properties[name] = hash || block
|
||||||
end
|
end
|
||||||
|
|
||||||
def for_environment?(envs)
|
def for_environment?(envs)
|
||||||
@ -204,10 +204,19 @@ module Penchant
|
|||||||
while !property_stack.empty?
|
while !property_stack.empty?
|
||||||
key, value = property_stack.shift
|
key, value = property_stack.shift
|
||||||
|
|
||||||
if @properties[key]
|
if property = @properties[key]
|
||||||
@properties[key].call(*([ value ].flatten)).each do |k, v|
|
values = [ value ].flatten
|
||||||
|
|
||||||
|
if property.respond_to?(:call)
|
||||||
|
property.call(*values).each do |k, v|
|
||||||
property_stack.push([ k, v ])
|
property_stack.push([ k, v ])
|
||||||
end
|
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
|
else
|
||||||
value = value % gem_name if value.respond_to?(:%)
|
value = value % gem_name if value.respond_to?(:%)
|
||||||
|
|
||||||
@ -238,6 +247,8 @@ module Penchant
|
|||||||
|
|
||||||
class ERBFile < FileProcessor
|
class ERBFile < FileProcessor
|
||||||
def handle_result(data)
|
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)
|
@output << ERB.new(data, nil, nil, '@_erbout').result(binding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
module Penchant
|
module Penchant
|
||||||
VERSION = "0.2.10"
|
VERSION = "0.2.11"
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user