public
Rubygem
Description: Liquid markup language. Save, customer facing template language for flexible web apps.
Homepage: http://www.liquidmarkup.org
Clone URL: git://github.com/tobi/liquid.git
Click here to lend your support to: liquid and make a donation at www.pledgie.com !
Added filters for basic arithmetic
jamesmacaulay (author)
Mon May 12 14:11:42 -0700 2008
commit  69bc84b7774f7404067c1d553535f61a462d7313
tree    0200d8694ca77b5cbe26431910de7b6ef5c5a56d
parent  3bfde37a53edc8502052696e53fde3758686b718
...
155
156
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
159
160
...
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
0
@@ -155,6 +155,26 @@ module Liquid
0
       array.last if array.respond_to?(:last)
0
     end
0
     
0
+    # addition
0
+    def plus(input, operand)
0
+      input + operand if input.respond_to?('+')
0
+    end
0
+    
0
+    # subtraction
0
+    def minus(input, operand)
0
+      input - operand if input.respond_to?('-')
0
+    end
0
+    
0
+    # multiplication
0
+    def times(input, operand)
0
+      input * operand if input.respond_to?('*')
0
+    end
0
+    
0
+    # division
0
+    def divided_by(input, operand)
0
+      input / operand if input.respond_to?('/')
0
+    end
0
+    
0
   end
0
    
0
   Template.register_filter(StandardFilters)
...
118
119
120
 
 
 
 
121
 
 
 
122
 
 
 
 
123
 
 
 
 
 
124
125
126
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
0
@@ -118,9 +118,25 @@ class StandardFiltersTest < Test::Unit::TestCase
0
     assert_template_result "a<br />\nb<br />\nc", "{{ source | newline_to_br }}", 'source' => "a\nb\nc"
0
   end
0
   
0
+  def test_plus
0
+    assert_template_result "2", "{{ 1 | plus:1 }}"
0
+    assert_template_result "11", "{{ '1' | plus:'1' }}"
0
+  end
0
   
0
+  def test_minus
0
+    assert_template_result "4", "{{ input | minus:operand }}", 'input' => 5, 'operand' => 1
0
+  end
0
   
0
+  def test_times
0
+    assert_template_result "12", "{{ 3 | times:4 }}"
0
+    assert_template_result "foofoofoofoo", "{{ 'foo' | times:4 }}"
0
+  end
0
   
0
+  def test_divided_by
0
+    assert_template_result "4", "{{ 12 | divided_by:3 }}"
0
+    assert_template_result "4", "{{ 14 | divided_by:3 }}"
0
+    assert_template_result "5", "{{ 15 | divided_by:3 }}"
0
+  end
0
   
0
 end
0
 

Comments