mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Initial options passing
This commit is contained in:
+4
-2
@@ -28,7 +28,9 @@ module Liquid
|
||||
|
||||
# fetch the tag from registered blocks
|
||||
if tag = Template.tags[$1]
|
||||
new_tag = tag.new($1, $2, tokens)
|
||||
new_tag = tag.allocate
|
||||
new_tag.options = @options || {}
|
||||
new_tag.send(:initialize, $1, $2, tokens)
|
||||
@blank &&= new_tag.blank?
|
||||
@nodelist << new_tag
|
||||
else
|
||||
@@ -80,7 +82,7 @@ module Liquid
|
||||
|
||||
def create_variable(token)
|
||||
token.scan(ContentOfVariable) do |content|
|
||||
return Variable.new(content.first)
|
||||
return Variable.new(content.first, @options)
|
||||
end
|
||||
raise SyntaxError.new("Variable '#{token}' was not properly terminated with regexp: #{VariableEnd.inspect} ")
|
||||
end
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
module Liquid
|
||||
class Document < Block
|
||||
# we don't need markup to open this block
|
||||
def initialize(tokens)
|
||||
def initialize(tokens, options = {})
|
||||
@options = options
|
||||
parse(tokens)
|
||||
end
|
||||
|
||||
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
module Liquid
|
||||
class Tag
|
||||
attr_accessor :nodelist
|
||||
attr_accessor :nodelist, :options
|
||||
|
||||
def initialize(tag_name, markup, tokens)
|
||||
@tag_name = tag_name
|
||||
@markup = markup
|
||||
@options ||= {} # needs || because might be set before initialize
|
||||
parse(tokens)
|
||||
end
|
||||
|
||||
@@ -24,7 +25,7 @@ module Liquid
|
||||
end
|
||||
|
||||
def switch_parse(markup)
|
||||
case Template.error_mode
|
||||
case @options[:error_mode] || Template.error_mode
|
||||
when :strict then strict_parse(markup)
|
||||
when :lax then lax_parse(markup)
|
||||
when :warn
|
||||
|
||||
@@ -53,9 +53,9 @@ module Liquid
|
||||
end
|
||||
|
||||
# creates a new <tt>Template</tt> object from liquid source code
|
||||
def parse(source)
|
||||
def parse(source, options = {})
|
||||
template = Template.new
|
||||
template.parse(source)
|
||||
template.parse(source, options)
|
||||
template
|
||||
end
|
||||
end
|
||||
@@ -67,8 +67,8 @@ module Liquid
|
||||
|
||||
# Parse source code.
|
||||
# Returns self for easy chaining
|
||||
def parse(source)
|
||||
@root = Document.new(tokenize(source))
|
||||
def parse(source, options = {})
|
||||
@root = Document.new(tokenize(source), options)
|
||||
self
|
||||
end
|
||||
|
||||
|
||||
@@ -15,13 +15,14 @@ module Liquid
|
||||
EasyParse = /^ *(\w+(?:\.\w+)*) *$/
|
||||
attr_accessor :filters, :name
|
||||
|
||||
def initialize(markup)
|
||||
def initialize(markup, options = {})
|
||||
@markup = markup
|
||||
@name = nil
|
||||
@warning = nil
|
||||
@options = options || {}
|
||||
|
||||
|
||||
case Template.error_mode
|
||||
case @options[:error_mode] || Template.error_mode
|
||||
when :strict then strict_parse(markup)
|
||||
when :lax then lax_parse(markup)
|
||||
when :warn
|
||||
|
||||
Reference in New Issue
Block a user