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 !
filtered variables for assign, case, and cycle
jamesmacaulay (author)
Wed Oct 15 12:16:29 -0700 2008
commit  edf7b5577b5aa60567335dff1e6bc1d2568eea68
tree    77f5044fdfa8f73d059b40505114fe2f5e498fc2
parent  282786d7e2deb728f82977d4db38b0f7a05e7e76
...
9
10
11
12
 
13
14
15
...
9
10
11
 
12
13
14
15
0
@@ -9,7 +9,7 @@ module Liquid
0
   #  {{ monkey }}
0
   #
0
   class Assign < Tag
0
-    Syntax = /(#{VariableSignature}+)\s*=\s*(#{QuotedFragment}+)/   
0
+    Syntax = /(#{VariableSignature}+)\s*=\s*(#{Expression}+)/   
0
   
0
     def initialize(tag_name, markup, tokens)          
0
       if markup =~ Syntax
...
1
2
3
4
 
 
5
6
7
...
1
2
 
 
3
4
5
6
7
0
@@ -1,7 +1,7 @@
0
 module Liquid
0
   class Case < Block
0
-    Syntax     = /(#{QuotedFragment})/
0
-    WhenSyntax = /(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/
0
+    Syntax     = /(#{Expression})/
0
+    WhenSyntax = /(#{Expression})(?:(?:\s+or\s+|\s*\,\s*)(#{Expression}.*))?/
0
 
0
     def initialize(tag_name, markup, tokens)      
0
       @blocks = []
...
13
14
15
16
17
 
 
18
19
20
...
49
50
51
52
 
53
54
55
...
13
14
15
 
 
16
17
18
19
20
...
49
50
51
 
52
53
54
55
0
@@ -13,8 +13,8 @@ module Liquid
0
   #    <div class="green"> Item five</div>
0
   #
0
   class Cycle < Tag
0
-    SimpleSyntax = /#{QuotedFragment}/        
0
-    NamedSyntax = /(#{QuotedFragment})\s*\:\s*(.*)/
0
+    SimpleSyntax = /#{Expression}/        
0
+    NamedSyntax = /(#{Expression})\s*\:\s*(.*)/
0
   
0
     def initialize(tag_name, markup, tokens)      
0
       case markup
0
@@ -49,7 +49,7 @@ module Liquid
0
   
0
     def variables_from_string(markup)
0
       markup.split(',').collect do |var|
0
-        var =~ /\s*(#{QuotedFragment})\s*/
0
+        var =~ /\s*(#{Expression})\s*/
0
         $1 ? $1 : nil
0
       end.compact
0
     end
...
117
118
119
 
 
 
 
 
 
 
 
 
 
 
 
120
121
122
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
0
@@ -117,6 +117,18 @@ class IfElseTest < Test::Unit::TestCase
0
     assert_template_result('yes','{% if "FOO BAR"|truncatewords:1,"--" == "FOO--" %}yes{% endif %}')
0
     assert_template_result('yes','{% if "FOO BAR"|truncatewords:1,"--"|downcase == "foo--" %}yes{% endif %}')
0
     assert_template_result('yes','{% if "foo--" == "FOO BAR"|truncatewords:1,"--"|downcase %}yes{% endif %}')
0
+    # array transformation, to make sure we aren't converting arrays to strings somewhere along the way:
0
+    assert_template_result('yes','{% if values|sort == sorted %}yes{% endif %}', 'values' => %w{foo bar baz}, 'sorted' => %w{bar baz foo})
0
+  end
0
+  
0
+  def test_allow_no_spaces_in_filtered_expressions
0
+    assert_template_result('','{% if "foo--" == "FOO BAR" |truncatewords:1,"--"|downcase %}yes{% endif %}')
0
+    assert_template_result('','{% if "foo--" == "FOO BAR"| truncatewords:1,"--"|downcase %}yes{% endif %}')
0
+    assert_template_result('','{% if "foo--" == "FOO BAR"|truncatewords :1,"--"|downcase %}yes{% endif %}')
0
+    assert_template_result('','{% if "foo--" == "FOO BAR"|truncatewords: 1,"--"|downcase %}yes{% endif %}')
0
+    assert_template_result('','{% if "foo--" == "FOO BAR"|truncatewords:1 ,"--"|downcase %}yes{% endif %}')
0
+    assert_template_result('','{% if "foo--" == "FOO BAR"|truncatewords:1, "--"|downcase %}yes{% endif %}')
0
+    assert_template_result('','{% if "foo--" == "FOO BAR"|truncatewords:1,"--" |downcase %}yes{% endif %}')
0
   end
0
   
0
   def test_syntax_error_no_variable

Comments