mirror of
https://github.com/jekyll/jekyll.git
synced 2026-01-30 17:28:29 -05:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user