diff --git a/features/fixtures/regex/common.yaml b/features/fixtures/regex/common.yaml index edc54e9..6142ef3 100644 --- a/features/fixtures/regex/common.yaml +++ b/features/fixtures/regex/common.yaml @@ -8,10 +8,15 @@ template_sources: environments: development: - temp.erb!regex: + temp!regex: target: temp.txt regex: - find: confined replace: free - find: '^#some\.comment' replace: some.comment + temp2!regex: + target: temp2.txt + regex: + - find: //m + replace: "" diff --git a/features/fixtures/regex/temp2.txt b/features/fixtures/regex/temp2.txt new file mode 100644 index 0000000..8052d2b --- /dev/null +++ b/features/fixtures/regex/temp2.txt @@ -0,0 +1,13 @@ +Before comment + + + +After comment \ No newline at end of file diff --git a/features/regex.feature b/features/regex.feature index 78035a9..c21d317 100644 --- a/features/regex.feature +++ b/features/regex.feature @@ -10,7 +10,7 @@ Feature: Reusable template plugin Given I use a fixture named "regex" When I successfully run `tiller -b . -v -n` Then a file named "temp.txt" should exist - And the file "temp.txt" should contain: + And the file "temp.txt" should contain exactly: """ Village did removed enjoyed explain nor ham saw calling talking. Securing as freeinformed declared or margaret. @@ -19,9 +19,23 @@ Request norland neither mistake for yet. Between the for morning free assured country believe. On even feet time have an no at. Relation so in free smallest children unpacked delicate. -some.comment +#some.comment Why sir end believe uncivil respect. -some.comment +#some.comment Always get adieus nature day course for common. My little garret repair to desire he esteem. - """ \ No newline at end of file +""" + Scenario: Create two configs from one template + Given I use a fixture named "regex" + When I successfully run `tiller -b . -v -n` + Then a file named "temp2.txt" should exist + And the file "temp2.txt" should contain exactly: +""" +Before comment + + + +After comment +""" diff --git a/lib/tiller/template/regex.rb b/lib/tiller/template/regex.rb index 93bda68..1c3685f 100644 --- a/lib/tiller/template/regex.rb +++ b/lib/tiller/template/regex.rb @@ -43,9 +43,12 @@ def template(template_name) end content = open(template_absolute).read @config_hash[template_name]['regex'].each{ |item| - find = String.new(item['find']) replace = String.new(item['replace']) - content.gsub!(Regexp.new(find), replace) + find = String.new(item['find']) + if find.start_with?('/') + find = eval(item['find']) + end + content.gsub!(find, replace) } target = open(template_absolute, 'w') target.puts(content)