Skip to content

Commit

Permalink
improve ordering of options
Browse files Browse the repository at this point in the history
  • Loading branch information
rvicinus committed Feb 20, 2016
1 parent 93b218e commit 664f18c
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions templates/fragments/_options.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
<%-
# non mentioned option have a value of 0
# lower values come first
option_order = {
'acl' => -1,
'tcp-request' => 2,
'block' => 3,
'http-request' => 4,
'reqallow' => 5,
'reqdel' => 5,
'reqdeny' => 5,
'reqidel' => 5,
'reqideny' => 5,
'reqipass' => 5,
'reqirep' => 5,
'reqitarpit' => 5,
'reqpass' => 5,
'reqrep' => 5,
'reqtarpit' => 5,
'reqadd' => 6,
'redirect' => 7,
'use_backend' => 8,
'use-server' => 9,
}
-%>
<% if @options.is_a?(Hash) -%>
<% @options.sort.each do |key, val| -%>
<% @options.sort{|a,b| [option_order.fetch(a[0],0), a[0]] <=> [option_order.fetch(b[0],0), b[0]] }.each do |key, val| -%>
<% Array(val).each do |item| -%>
<%= key %> <%= item %>
<% end -%>
Expand All @@ -10,7 +35,7 @@
<%# sorted by key name before outputting the key name (= option name) and its -%>
<%# value (or values, one per line) -%>
<% @options.each do |option| -%>
<% option.sort.map do |key, val| -%>
<% option.sort{|a,b| [option_order.fetch(a[0],0), a[0]] <=> [option_order.fetch(b[0],0), b[0]] }.map do |key, val| -%>
<% Array(val).each do |item| -%>
<%= key %> <%= item %>
<% end -%>
Expand Down

0 comments on commit 664f18c

Please sign in to comment.