mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
committed by
Tobias Lütke
parent
56f1aa9b4a
commit
daadb1a2d6
@@ -1,3 +1,5 @@
|
|||||||
|
* Ruby 1.9.1 bugfixes
|
||||||
|
|
||||||
* Fix LiquidView for Rails 2.2. Fix local assigns for all versions of Rails
|
* Fix LiquidView for Rails 2.2. Fix local assigns for all versions of Rails
|
||||||
|
|
||||||
* Fixed gem install rake task
|
* Fixed gem install rake task
|
||||||
@@ -5,7 +7,7 @@
|
|||||||
|
|
||||||
* Added If with or / and expressions
|
* Added If with or / and expressions
|
||||||
|
|
||||||
* Implemented .to_liquid for all objects which can be passed to liquid like Strings Arrays Hashes Numerics and Booleans. To export new objects to liquid just implement .to_liquid on them and return objects which themselves have .to_liquid methods.
|
* Implemented .to_liquid for all objects which can be passed to liquid like Strings Arrays Hashes Numerics and Booleans. To export new objects to liquid just implement .to_liquid on them and return objects which themselves have .to_liquid methods.
|
||||||
|
|
||||||
* Added more tags to standard library
|
* Added more tags to standard library
|
||||||
|
|
||||||
@@ -24,17 +26,17 @@
|
|||||||
* Fixed bug with string filter parameters failing to tolerate commas in strings. [Paul Hammond]
|
* Fixed bug with string filter parameters failing to tolerate commas in strings. [Paul Hammond]
|
||||||
|
|
||||||
* Improved filter parameters. Filter parameters are now context sensitive; Types are resolved according to the rules of the context. Multiple parameters are now separated by the Liquid::ArgumentSeparator: , by default [Paul Hammond]
|
* Improved filter parameters. Filter parameters are now context sensitive; Types are resolved according to the rules of the context. Multiple parameters are now separated by the Liquid::ArgumentSeparator: , by default [Paul Hammond]
|
||||||
|
|
||||||
{{ 'Typo' | link_to: 'http://typo.leetsoft.com', 'Typo - a modern weblog engine' }}
|
|
||||||
|
|
||||||
|
|
||||||
* Added Liquid::Drop. A base class which you can use for exporting proxy objects to liquid which can acquire more data when used in liquid. [Tobias Luetke]
|
{{ 'Typo' | link_to: 'http://typo.leetsoft.com', 'Typo - a modern weblog engine' }}
|
||||||
|
|
||||||
|
|
||||||
|
* Added Liquid::Drop. A base class which you can use for exporting proxy objects to liquid which can acquire more data when used in liquid. [Tobias Luetke]
|
||||||
|
|
||||||
class ProductDrop < Liquid::Drop
|
class ProductDrop < Liquid::Drop
|
||||||
def top_sales
|
def top_sales
|
||||||
Shop.current.products.find(:all, :order => 'sales', :limit => 10 )
|
Shop.current.products.find(:all, :order => 'sales', :limit => 10 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
t = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {% endfor %} ' )
|
t = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {% endfor %} ' )
|
||||||
t.render('product' => ProductDrop.new )
|
t.render('product' => ProductDrop.new )
|
||||||
|
|
||||||
|
|||||||
+17
-18
@@ -1,52 +1,51 @@
|
|||||||
require 'set'
|
require 'set'
|
||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
|
|
||||||
|
|
||||||
parent_object = if defined? BlankObject
|
parent_object = if defined? BlankObject
|
||||||
BlankObject
|
BlankObject
|
||||||
else
|
else
|
||||||
Object
|
Object
|
||||||
end
|
end
|
||||||
|
|
||||||
# Strainer is the parent class for the filters system.
|
# Strainer is the parent class for the filters system.
|
||||||
# New filters are mixed into the strainer class which is then instanciated for each liquid template render run.
|
# New filters are mixed into the strainer class which is then instanciated for each liquid template render run.
|
||||||
#
|
#
|
||||||
# One of the strainer's responsibilities is to keep malicious method calls out
|
# One of the strainer's responsibilities is to keep malicious method calls out
|
||||||
class Strainer < parent_object #:nodoc:
|
class Strainer < parent_object #:nodoc:
|
||||||
INTERNAL_METHOD = /^__/
|
INTERNAL_METHOD = /^__/
|
||||||
@@required_methods = Set.new([:__send__, :__id__, :respond_to?, :extend, :methods, :class])
|
@@required_methods = Set.new([:__send__, :respond_to?, :extend, :methods, :class, :object_id])
|
||||||
|
|
||||||
@@filters = {}
|
@@filters = {}
|
||||||
|
|
||||||
def initialize(context)
|
def initialize(context)
|
||||||
@context = context
|
@context = context
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.global_filter(filter)
|
def self.global_filter(filter)
|
||||||
raise ArgumentError, "Passed filter is not a module" unless filter.is_a?(Module)
|
raise ArgumentError, "Passed filter is not a module" unless filter.is_a?(Module)
|
||||||
@@filters[filter.name] = filter
|
@@filters[filter.name] = filter
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create(context)
|
def self.create(context)
|
||||||
strainer = Strainer.new(context)
|
strainer = Strainer.new(context)
|
||||||
@@filters.each { |k,m| strainer.extend(m) }
|
@@filters.each { |k,m| strainer.extend(m) }
|
||||||
strainer
|
strainer
|
||||||
end
|
end
|
||||||
|
|
||||||
def respond_to?(method, include_private = false)
|
def respond_to?(method, include_private = false)
|
||||||
method_name = method.to_s
|
method_name = method.to_s
|
||||||
return false if method_name =~ INTERNAL_METHOD
|
return false if method_name =~ INTERNAL_METHOD
|
||||||
return false if @@required_methods.include?(method_name)
|
return false if @@required_methods.include?(method_name)
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove all standard methods from the bucket so circumvent security
|
# remove all standard methods from the bucket so circumvent security
|
||||||
# problems
|
# problems
|
||||||
instance_methods.each do |m|
|
instance_methods.each do |m|
|
||||||
unless @@required_methods.include?(m.to_sym)
|
unless @@required_methods.include?(m.to_sym)
|
||||||
undef_method m
|
undef_method m
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ module Liquid
|
|||||||
@name = match[1]
|
@name = match[1]
|
||||||
if markup.match(/#{FilterSeparator}\s*(.*)/)
|
if markup.match(/#{FilterSeparator}\s*(.*)/)
|
||||||
filters = Regexp.last_match(1).split(/#{FilterSeparator}/)
|
filters = Regexp.last_match(1).split(/#{FilterSeparator}/)
|
||||||
filters.each do |f|
|
filters.each do |f|
|
||||||
if matches = f.match(/\s*(\w+)/)
|
if matches = f.match(/\s*(\w+)/)
|
||||||
filtername = matches[1]
|
filtername = matches[1]
|
||||||
filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten
|
filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten
|
||||||
@@ -34,8 +34,7 @@ module Liquid
|
|||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
return '' if @name.nil?
|
return '' if @name.nil?
|
||||||
output = context[@name]
|
@filters.inject(context[@name]) do |output, filter|
|
||||||
@filters.inject(output) do |output, filter|
|
|
||||||
filterargs = filter[1].to_a.collect do |a|
|
filterargs = filter[1].to_a.collect do |a|
|
||||||
context[a]
|
context[a]
|
||||||
end
|
end
|
||||||
@@ -45,7 +44,6 @@ module Liquid
|
|||||||
raise FilterNotFound, "Error - filter '#{filter[0]}' in '#{@markup.strip}' could not be found."
|
raise FilterNotFound, "Error - filter '#{filter[0]}' in '#{@markup.strip}' could not be found."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
output
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{liquid}
|
s.name = %q{liquid}
|
||||||
s.version = "1.9.0"
|
s.version = "2.0.1"
|
||||||
s.specification_version = 2 if s.respond_to? :specification_version=
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Tobias Luetke"]
|
s.authors = ["Tobias Luetke"]
|
||||||
s.date = %q{2008-06-23}
|
s.date = %q{2009-04-13}
|
||||||
s.description = %q{A secure non evaling end user template engine with aesthetic markup.}
|
s.description = %q{A secure non evaling end user template engine with aesthetic markup.}
|
||||||
s.email = %q{[email protected]}
|
s.email = %q{[email protected]}
|
||||||
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
||||||
|
|||||||
Reference in New Issue
Block a user