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

Reduce template code duplication #91

Merged
merged 1 commit into from
Jun 10, 2014
Merged
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
6 changes: 3 additions & 3 deletions spec/defines/frontend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it { should contain_concat__fragment('croy_frontend_block').with(
'order' => '15-croy-00',
'target' => '/etc/haproxy/haproxy.cfg',
'content' => "\nfrontend croy\n bind 1.1.1.1:18140\n option tcplog\n"
'content' => "\nfrontend croy\n bind 1.1.1.1:18140 \n option tcplog\n"
) }
end
context "when an array of ports is provided" do
Expand All @@ -32,7 +32,7 @@
it { should contain_concat__fragment('apache_frontend_block').with(
'order' => '15-apache-00',
'target' => '/etc/haproxy/haproxy.cfg',
'content' => "\nfrontend apache\n bind 23.23.23.23:80\n bind 23.23.23.23:443\n option tcplog\n"
'content' => "\nfrontend apache\n bind 23.23.23.23:80 \n bind 23.23.23.23:443 \n option tcplog\n"
) }
end
context "when a comma-separated list of ports is provided" do
Expand All @@ -47,7 +47,7 @@
it { should contain_concat__fragment('apache_frontend_block').with(
'order' => '15-apache-00',
'target' => '/etc/haproxy/haproxy.cfg',
'content' => "\nfrontend apache\n bind 23.23.23.23:80\n bind 23.23.23.23:443\n option tcplog\n"
'content' => "\nfrontend apache\n bind 23.23.23.23:80 \n bind 23.23.23.23:443 \n option tcplog\n"
) }
end
end
3 changes: 3 additions & 0 deletions templates/fragments/_bind.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% Array(@ipaddress).uniq.each do |virtual_ip| (@ports.is_a?(Array) ? @ports : Array(@ports.split(","))).each do |port| -%>
bind <%= virtual_ip %>:<%= port %> <%= Array(@bind_options).join(" ") %>
<% end end -%>
3 changes: 3 additions & 0 deletions templates/fragments/_mode.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% if @mode -%>
mode <%= @mode %>
<% end -%>
5 changes: 5 additions & 0 deletions templates/fragments/_options.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% @options.sort.each do |key, val| -%>
<% Array(val).each do |item| -%>
<%= key %> <%= item %>
<% end -%>
<% end -%>
6 changes: 1 addition & 5 deletions templates/haproxy_backend_block.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

backend <%= @name %>
<% @options.sort.each do |key, val| -%>
<% Array(val).each do |item| -%>
<%= key %> <%= item %>
<% end -%>
<% end -%>
<%= scope.function_template(['haproxy/fragments/_options.erb']) -%>
14 changes: 3 additions & 11 deletions templates/haproxy_frontend_block.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@

frontend <%= @name %>
<% Array(@ipaddress).uniq.each do |virtual_ip| (@ports.is_a?(Array) ? @ports : Array(@ports.split(","))).each do |port| -%>
bind <%= virtual_ip %>:<%= port %>
<% end end -%>
<% if @mode -%>
mode <%= @mode %>
<% end -%>
<% @options.sort.each do |key, val| -%>
<% Array(val).each do |item| -%>
<%= key %> <%= item %>
<% end -%>
<% end -%>
<%= scope.function_template(['haproxy/fragments/_bind.erb']) -%>
<%= scope.function_template(['haproxy/fragments/_mode.erb']) -%>
<%= scope.function_template(['haproxy/fragments/_options.erb']) -%>
14 changes: 3 additions & 11 deletions templates/haproxy_listen_block.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@

listen <%= @name %>
<% Array(@ipaddress).uniq.each do |virtual_ip| (@ports.is_a?(Array) ? @ports : Array(@ports.split(","))).each do |port| -%>
bind <%= virtual_ip %>:<%= port %> <%= Array(@bind_options).join(" ") %>
<% end end -%>
<% if @mode -%>
mode <%= @mode %>
<% end -%>
<% @options.sort.each do |key, val| -%>
<% Array(val).each do |item| -%>
<%= key %> <%= item %>
<% end -%>
<% end -%>
<%= scope.function_template(['haproxy/fragments/_bind.erb']) -%>
<%= scope.function_template(['haproxy/fragments/_mode.erb']) -%>
<%= scope.function_template(['haproxy/fragments/_options.erb']) -%>