Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Added support for complex regular expressions with flags #72

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion features/fixtures/regex/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: /<!--\s+?<Connector\s+port="8443".+?certificateKeystoreFile="conf\/localhost-rsa.jks".+?<\/Connector>\s+?-->/m
replace: "<Connector protocol=\"org.apache.coyote.http11.Http11NioProtocol\"\n \t\tport=\"8443\" maxThreads=\"200\"\n \t</Connector>"
13 changes: 13 additions & 0 deletions features/fixtures/regex/temp2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Before comment

<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
type="RSA" />
</SSLHostConfig>
</Connector>
-->

After comment
22 changes: 18 additions & 4 deletions features/regex.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
"""
"""
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

<Connector protocol="org.apache.coyote.http11.Http11NioProtocol"
port="8443" maxThreads="200"
</Connector>

After comment
"""
7 changes: 5 additions & 2 deletions lib/tiller/template/regex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down