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 !
Remove trailing whitespace.
mhw (author)
Tue Aug 12 10:17:47 -0700 2008
commit  7eeb8951924fbb3692afd4c3b203082f01718372
tree    e0d3d6d3a50ebd63ae78edbaafdcfa2748d2d8ad
parent  7acdac2a1c771c92fb04fd208d11dae5aa7054dc
...
1
2
 
3
4
5
...
7
8
9
10
 
11
12
13
 
14
15
16
...
55
56
57
58
 
59
60
61
62
63
64
65
66
67
68
...
1
 
2
3
4
5
...
7
8
9
 
10
11
12
 
13
14
15
16
...
55
56
57
 
58
59
60
 
 
 
 
 
 
 
 
0
@@ -1,5 +1,5 @@
0
 # Copyright (c) 2005 Tobias Luetke
0
-# 
0
+#
0
 # Permission is hereby granted, free of charge, to any person obtaining
0
 # a copy of this software and associated documentation files (the
0
 # "Software"), to deal in the Software without restriction, including
0
@@ -7,10 +7,10 @@
0
 # distribute, sublicense, and/or sell copies of the Software, and to
0
 # permit persons to whom the Software is furnished to do so, subject to
0
 # the following conditions:
0
-# 
0
+#
0
 # The above copyright notice and this permission notice shall be
0
 # included in all copies or substantial portions of the Software.
0
-# 
0
+#
0
 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0
 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0
@@ -55,14 +55,6 @@ require 'liquid/standardfilters'
0
 require 'liquid/condition'
0
 require 'liquid/module_ex'
0
 
0
-# Load all the tags of the standard library 
0
+# Load all the tags of the standard library
0
 #
0
 Dir[File.dirname(__FILE__) + '/liquid/tags/*.rb'].each { |f| require f }
0
-
0
-
0
-
0
-
0
-
0
-
0
-
0
-
...
1
2
 
3
4
5
...
10
11
12
13
 
14
15
 
16
17
 
18
19
20
21
22
23
24
25
 
 
26
27
28
 
29
30
31
32
33
34
 
35
36
 
37
38
39
...
45
46
47
48
 
49
50
51
...
1
 
2
3
4
5
...
10
11
12
 
13
14
 
15
16
 
17
18
19
20
21
22
23
 
 
24
25
26
27
 
28
29
30
31
32
33
 
34
35
 
36
37
38
39
...
45
46
47
 
48
49
50
51
0
@@ -1,5 +1,5 @@
0
 module Liquid
0
-  
0
+
0
   # Holds variables. Variables are only loaded "just in time"
0
   # and are not evaluated as part of the render stage
0
   #
0
@@ -10,30 +10,30 @@ module Liquid
0
   #
0
   #   {{ user | link }}
0
   #
0
-  class Variable    
0
+  class Variable
0
     attr_accessor :filters, :name
0
-    
0
+
0
     def initialize(markup)
0
-      @markup  = markup                            
0
+      @markup  = markup
0
       @name    = nil
0
       @filters = []
0
       if match = markup.match(/\s*(#{QuotedFragment})/)
0
         @name = match[1]
0
         if markup.match(/#{FilterSperator}\s*(.*)/)
0
           filters = Regexp.last_match(1).split(/#{FilterSperator}/)
0
-        
0
-          filters.each do |f|    
0
+
0
+          filters.each do |f|
0
             if matches = f.match(/\s*(\w+)/)
0
               filtername = matches[1]
0
-              filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten            
0
+              filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten
0
               @filters << [filtername.to_sym, filterargs]
0
             end
0
           end
0
         end
0
       end
0
-    end                        
0
+    end
0
 
0
-    def render(context)      
0
+    def render(context)
0
       return '' if @name.nil?
0
       output = context[@name]
0
       @filters.inject(output) do |output, filter|
0
@@ -45,7 +45,7 @@ module Liquid
0
         rescue FilterNotFound
0
           raise FilterNotFound, "Error - filter '#{filter[0]}' in '#{@markup.strip}' could not be found."
0
         end
0
-      end  
0
+      end
0
       output
0
     end
0
   end
...
1
2
3
4
5
6
7
8
9
 
10
11
12
...
18
19
20
21
22
23
24
 
25
26
27
28
29
 
 
30
31
32
33
34
 
 
35
36
37
38
39
40
41
 
42
43
44
45
 
 
46
47
 
48
49
50
...
53
54
55
56
 
57
58
59
...
67
68
69
70
 
71
72
73
 
74
75
76
77
78
 
79
80
81
...
84
85
86
87
 
88
89
90
91
92
 
93
94
95
96
97
98
...
1
2
3
 
4
5
6
7
 
8
9
10
11
...
17
18
19
 
20
21
 
22
23
24
25
 
 
26
27
28
29
30
 
 
31
32
33
34
35
36
37
38
 
39
40
41
 
 
42
43
44
 
45
46
47
48
...
51
52
53
 
54
55
56
57
...
65
66
67
 
68
69
70
 
71
72
73
74
75
 
76
77
78
79
...
82
83
84
 
85
86
87
88
89
 
90
91
92
93
94
 
95
0
@@ -1,12 +1,11 @@
0
 #!/usr/bin/env ruby
0
 require File.dirname(__FILE__) + '/helper'
0
 
0
-
0
 module MoneyFilter
0
   def money(input)
0
     sprintf(' %d$ ', input)
0
   end
0
-  
0
+
0
   def money_with_underscore(input)
0
     sprintf(' %d$ ', input)
0
   end
0
@@ -18,33 +17,32 @@ module CanadianMoneyFilter
0
   end
0
 end
0
 
0
-
0
 class FiltersTest < Test::Unit::TestCase
0
   include Liquid
0
-  
0
+
0
   def setup
0
     @context = Context.new
0
   end
0
-    
0
-  def test_local_filter    
0
+
0
+  def test_local_filter
0
     @context['var'] = 1000
0
     @context.add_filters(MoneyFilter)
0
     assert_equal ' 1000$ ', Variable.new("var | money").render(@context)
0
-  end  
0
-  
0
+  end
0
+
0
   def test_underscore_in_filter_name
0
     @context['var'] = 1000
0
     @context.add_filters(MoneyFilter)
0
     assert_equal ' 1000$ ', Variable.new("var | money_with_underscore").render(@context)
0
   end
0
 
0
-  def test_second_filter_overwrites_first    
0
+  def test_second_filter_overwrites_first
0
     @context['var'] = 1000
0
     @context.add_filters(MoneyFilter)
0
-    @context.add_filters(CanadianMoneyFilter)  
0
-    assert_equal ' 1000$ CAD ', Variable.new("var | money").render(@context)    
0
+    @context.add_filters(CanadianMoneyFilter)
0
+    assert_equal ' 1000$ CAD ', Variable.new("var | money").render(@context)
0
   end
0
-  
0
+
0
   def test_size
0
     @context['var'] = 'abcd'
0
     @context.add_filters(MoneyFilter)
0
@@ -53,7 +51,7 @@ class FiltersTest < Test::Unit::TestCase
0
 
0
   def test_join
0
     @context['var'] = [1,2,3,4]
0
-    assert_equal "1 2 3 4", Variable.new("var | join").render(@context)    
0
+    assert_equal "1 2 3 4", Variable.new("var | join").render(@context)
0
   end
0
 
0
   def test_sort
0
@@ -67,15 +65,15 @@ class FiltersTest < Test::Unit::TestCase
0
     assert_equal [3], Variable.new("value | sort").render(@context)
0
     assert_equal ['are', 'flattened'], Variable.new("arrays | sort").render(@context)
0
   end
0
-  
0
+
0
   def test_strip_html
0
     @context['var'] = "<b>bla blub</a>"
0
-    assert_equal "bla blub", Variable.new("var | strip_html").render(@context)    
0
+    assert_equal "bla blub", Variable.new("var | strip_html").render(@context)
0
   end
0
 
0
   def test_capitalize
0
     @context['var'] = "blub"
0
-    assert_equal "Blub", Variable.new("var | capitalize").render(@context)    
0
+    assert_equal "Blub", Variable.new("var | capitalize").render(@context)
0
   end
0
 end
0
 
0
@@ -84,15 +82,14 @@ class FiltersInTemplate < Test::Unit::TestCase
0
 
0
   def test_local_global
0
     Template.register_filter(MoneyFilter)
0
-    
0
+
0
     assert_equal " 1000$ ", Template.parse("{{1000 | money}}").render(nil, nil)
0
     assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, :filters => CanadianMoneyFilter)
0
     assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, :filters => [CanadianMoneyFilter])
0
   end
0
-  
0
+
0
   def test_local_filter_with_deprecated_syntax
0
     assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, CanadianMoneyFilter)
0
     assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, [CanadianMoneyFilter])
0
   end
0
-  
0
 end
...
8
9
10
11
 
12
13
14
...
25
26
27
28
 
29
30
31
32
 
33
34
35
36
 
37
38
39
...
45
46
47
48
 
49
50
51
52
53
 
54
55
56
57
58
59
 
60
61
 
62
63
64
...
68
69
70
71
 
72
73
74
75
 
76
77
78
...
84
85
86
87
 
88
89
90
...
94
95
96
97
 
98
99
100
...
109
110
111
112
113
 
 
114
115
116
117
118
119
 
120
121
122
...
8
9
10
 
11
12
13
14
...
25
26
27
 
28
29
30
31
 
32
33
34
35
 
36
37
38
39
...
45
46
47
 
48
49
50
51
52
 
53
54
55
56
57
58
 
59
60
 
61
62
63
64
...
68
69
70
 
71
72
73
74
 
75
76
77
78
...
84
85
86
 
87
88
89
90
...
94
95
96
 
97
98
99
100
...
109
110
111
 
 
112
113
114
115
116
117
118
 
119
120
121
122
0
@@ -8,7 +8,7 @@ class VariableTest < Test::Unit::TestCase
0
     var = Variable.new('hello')
0
     assert_equal 'hello', var.name
0
   end
0
-  
0
+
0
   def test_filters
0
     var = Variable.new('hello | textileze')
0
     assert_equal 'hello', var.name
0
@@ -25,15 +25,15 @@ class VariableTest < Test::Unit::TestCase
0
     var = Variable.new(%! 'typo' | link_to: 'Typo', true !)
0
     assert_equal %!'typo'!, var.name
0
     assert_equal [[:link_to,["'Typo'", "true"]]], var.filters
0
-    
0
+
0
     var = Variable.new(%! 'typo' | link_to: 'Typo', false !)
0
     assert_equal %!'typo'!, var.name
0
     assert_equal [[:link_to,["'Typo'", "false"]]], var.filters
0
-    
0
+
0
     var = Variable.new(%! 'foo' | repeat: 3 !)
0
     assert_equal %!'foo'!, var.name
0
     assert_equal [[:repeat,["3"]]], var.filters
0
-    
0
+
0
     var = Variable.new(%! 'foo' | repeat: 3, 3 !)
0
     assert_equal %!'foo'!, var.name
0
     assert_equal [[:repeat,["3","3"]]], var.filters
0
@@ -45,20 +45,20 @@ class VariableTest < Test::Unit::TestCase
0
     var = Variable.new(%! hello | strftime: '%Y, okay?'!)
0
     assert_equal 'hello', var.name
0
     assert_equal [[:strftime,["'%Y, okay?'"]]], var.filters
0
-  
0
+
0
     var = Variable.new(%! hello | things: "%Y, okay?", 'the other one'!)
0
     assert_equal 'hello', var.name
0
     assert_equal [[:things,["\"%Y, okay?\"","'the other one'"]]], var.filters
0
   end
0
-  
0
+
0
   def test_filter_with_date_parameter
0
 
0
     var = Variable.new(%! '2006-06-06' | date: "%m/%d/%Y"!)
0
     assert_equal "'2006-06-06'", var.name
0
     assert_equal [[:date,["\"%m/%d/%Y\""]]], var.filters
0
-    
0
+
0
   end
0
-  
0
+
0
   def test_filters_without_whitespace
0
     var = Variable.new('hello | textileze | paragraph')
0
     assert_equal 'hello', var.name
0
@@ -68,11 +68,11 @@ class VariableTest < Test::Unit::TestCase
0
     assert_equal 'hello', var.name
0
     assert_equal [[:textileze,[]], [:paragraph,[]]], var.filters
0
   end
0
-  
0
+
0
   def test_symbol
0
     var = Variable.new("http://disney.com/logo.gif | image: 'med' ")
0
     assert_equal 'http://disney.com/logo.gif', var.name
0
-    assert_equal [[:image,["'med'"]]], var.filters    
0
+    assert_equal [[:image,["'med'"]]], var.filters
0
   end
0
 
0
   def test_string_single_quoted
0
@@ -84,7 +84,7 @@ class VariableTest < Test::Unit::TestCase
0
     var = Variable.new(%| 'hello' |)
0
     assert_equal "'hello'", var.name
0
   end
0
-  
0
+
0
   def test_integer
0
     var = Variable.new(%| 1000 |)
0
     assert_equal "1000", var.name
0
@@ -94,7 +94,7 @@ class VariableTest < Test::Unit::TestCase
0
     var = Variable.new(%| 1000.01 |)
0
     assert_equal "1000.01", var.name
0
   end
0
-  
0
+
0
   def test_string_with_special_chars
0
     var = Variable.new(%| 'hello! $!@.;"ddasd" ' |)
0
     assert_equal %|'hello! $!@.;"ddasd" '|, var.name
0
@@ -109,14 +109,14 @@ end
0
 
0
 class VariableResolutionTest < Test::Unit::TestCase
0
   include Liquid
0
-  
0
-  def test_simple_variable    
0
+
0
+  def test_simple_variable
0
     template = Template.parse(%|{{test}}|)
0
     assert_equal 'worked', template.render('test' => 'worked')
0
     assert_equal 'worked wonderfully', template.render('test' => 'worked wonderfully')
0
   end
0
 
0
-  def test_simple_with_whitespaces    
0
+  def test_simple_with_whitespaces
0
     template = Template.parse(%|  {{ test }}  |)
0
     assert_equal '  worked  ', template.render('test' => 'worked')
0
     assert_equal '  worked wonderfully  ', template.render('test' => 'worked wonderfully')

Comments