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 !
Fix attribute expansion to index only once in all cases.

Also drop array.<digits> syntax
mhw (author)
Wed Jul 09 00:23:51 -0700 2008
commit  7acdac2a1c771c92fb04fd208d11dae5aa7054dc
tree    d8e77e85b454646ed8e3f5e5a8f07d306beea037
parent  50edd0f5b92cc38f7da032fc0caea6dbdadd9f07
...
188
189
190
 
191
192
193
 
 
 
 
 
194
195
196
 
 
 
 
197
198
199
 
 
 
 
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
 
221
222
223
224
225
226
227
228
 
 
 
 
229
230
231
...
235
236
237
238
239
240
241
242
243
244
245
...
188
189
190
191
192
 
 
193
194
195
196
197
198
 
 
199
200
201
202
203
 
 
204
205
206
207
208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
210
 
 
 
 
 
 
 
211
212
213
214
215
216
217
...
221
222
223
 
 
 
 
 
 
224
225
0
@@ -188,44 +188,30 @@ module Liquid
0
       if object = find_variable(first_part)
0
 
0
         parts.each do |part|
0
+          part = resolve($1) if part_resolved = (part =~ square_bracketed)
0
 
0
-          # If object is a hash we look for the presence of the key and if its available
0
-          # we return it
0
+          # If object is a hash- or array-like object we look for the
0
+          # presence of the key and if its available we return it
0
+          if object.respond_to?(:[]) and
0
+            ((object.respond_to?(:has_key?) and object.has_key?(part)) or
0
+             (object.respond_to?(:fetch) and part.is_a?(Integer)))
0
 
0
-          if part =~ square_bracketed
0
-            part = resolve($1)
0
+            # if its a proc we will replace the entry with the proc
0
+            res = object[part]
0
+            res = object[part] = res.call(self) if res.is_a?(Proc) and object.respond_to?(:[]=)
0
+            object = res.to_liquid
0
 
0
-            object[pos] = object[part].call(self) if object[part].is_a?(Proc) and object.respond_to?(:[]=)
0
-            object      = object[part].to_liquid
0
+          # Some special cases. If the part wasn't in square brackets and
0
+          # no key with the same name was found we interpret following calls
0
+          # as commands and call them on the current object
0
+          elsif !part_resolved and object.respond_to?(part) and ['size', 'first', 'last'].include?(part)
0
 
0
-          else
0
-
0
-            # Hash
0
-            if object.respond_to?(:has_key?) and object.has_key?(part)
0
-
0
-              # if its a proc we will replace the entry in the hash table with the proc
0
-              res = object[part]
0
-              res = object[part] = res.call(self) if res.is_a?(Proc) and object.respond_to?(:[]=)
0
-              object = res.to_liquid
0
-
0
-            # Array
0
-            elsif object.respond_to?(:fetch) and part =~ /^\d+$/
0
-              pos = part.to_i
0
-
0
-              object[pos] = object[pos].call(self) if object[pos].is_a?(Proc) and object.respond_to?(:[]=)
0
-              object = object[pos].to_liquid
0
-
0
-            # Some special cases. If no key with the same name was found we interpret following calls
0
-            # as commands and call them on the current object
0
-            elsif object.respond_to?(part) and ['size', 'first', 'last'].include?(part)
0
+            object = object.send(part.intern).to_liquid
0
 
0
-              object = object.send(part.intern).to_liquid
0
-
0
-            # No key was present with the desired value and it wasn't one of the directly supported
0
-            # keywords either. The only thing we got left is to return nil
0
-            else
0
-              return nil
0
-            end
0
+          # No key was present with the desired value and it wasn't one of the directly supported
0
+          # keywords either. The only thing we got left is to return nil
0
+          else
0
+            return nil
0
           end
0
 
0
           # If we are dealing with a drop here we have to
0
@@ -235,11 +221,5 @@ module Liquid
0
 
0
       object
0
     end
0
-
0
-    private
0
-
0
-    def execute_proc(proc)
0
-      proc.call(self)
0
-    end
0
   end
0
 end

Comments