Merge branch 'master' of git://github.com/mhw/liquid into mhw/master

This commit is contained in:
Tobias Lütke
2008-11-02 10:06:02 -08:00
4 changed files with 48 additions and 59 deletions
+5 -13
View File
@@ -1,5 +1,5 @@
# Copyright (c) 2005 Tobias Luetke
#
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -22,7 +22,7 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
module Liquid
FilterSperator = /\|/
FilterSeparator = /\|/
ArgumentSeparator = ','
FilterArgumentSeparator = ':'
VariableAttributeSeparator = '.'
@@ -57,14 +57,6 @@ require 'liquid/standardfilters'
require 'liquid/condition'
require 'liquid/module_ex'
# Load all the tags of the standard library
# Load all the tags of the standard library
#
Dir[File.dirname(__FILE__) + '/liquid/tags/*.rb'].each { |f| require f }
+12 -12
View File
@@ -1,5 +1,5 @@
module Liquid
# Holds variables. Variables are only loaded "just in time"
# and are not evaluated as part of the render stage
#
@@ -10,30 +10,30 @@ module Liquid
#
# {{ user | link }}
#
class Variable
class Variable
attr_accessor :filters, :name
def initialize(markup)
@markup = markup
@markup = markup
@name = nil
@filters = []
if match = markup.match(/\s*(#{QuotedFragment})/)
@name = match[1]
if markup.match(/#{FilterSperator}\s*(.*)/)
filters = Regexp.last_match(1).split(/#{FilterSperator}/)
filters.each do |f|
if markup.match(/#{FilterSeparator}\s*(.*)/)
filters = Regexp.last_match(1).split(/#{FilterSeparator}/)
filters.each do |f|
if matches = f.match(/\s*(\w+)/)
filtername = matches[1]
filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten
filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten
@filters << [filtername.to_sym, filterargs]
end
end
end
end
end
end
def render(context)
def render(context)
return '' if @name.nil?
output = context[@name]
@filters.inject(output) do |output, filter|
@@ -45,7 +45,7 @@ module Liquid
rescue FilterNotFound
raise FilterNotFound, "Error - filter '#{filter[0]}' in '#{@markup.strip}' could not be found."
end
end
end
output
end
end