Support passing Liquid variables to includes

Change the regex matching to allow Liquid variables and object fields
to be passed to the include. Use the render context to retrieve the
variable value. Also, relax syntax checks by allowing surrounding spaces
and dashes in parameter names.
This commit is contained in:
imathis 2013-06-22 15:46:19 +02:00 committed by maul.esel
parent f8f6784305
commit 2b01b06ec8
1 changed files with 5 additions and 3 deletions

View File

@ -2,7 +2,7 @@ module Jekyll
module Tags
class IncludeTag < Liquid::Tag
MATCHER = /(\w+)=(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)')/
MATCHER = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
def initialize(tag_name, markup, tokens)
super
@ -16,7 +16,7 @@ module Jekyll
end
end
def parse_params(markup)
def parse_params(markup, context)
params = {}
pos = 0
@ -42,6 +42,8 @@ eos
value = match[2].gsub(/\\"/, '"')
elsif match[3]
value = match[3].gsub(/\\'/, "'")
elsif match[4]
value = context[match[4]]
end
params[match[1]] = value
@ -67,7 +69,7 @@ eos
partial = Liquid::Template.parse(source)
context.stack do
context['include'] = parse_params(@params) if @params
context['include'] = parse_params(@params, context) if @params
partial.render(context)
end
else