move parameter parsing to render time

This commit is contained in:
maul.esel 2013-06-22 15:30:10 +02:00
parent 00ed567f99
commit f8f6784305
1 changed files with 6 additions and 4 deletions

View File

@ -10,14 +10,14 @@ module Jekyll
if markup.include?(' ') if markup.include?(' ')
separator = markup.index(' ') separator = markup.index(' ')
@file = markup[0..separator].strip @file = markup[0..separator].strip
parse_params(markup[separator..-1]) @params = markup[separator..-1]
else else
@file = markup @file = markup
end end
end end
def parse_params(markup) def parse_params(markup)
@params = {} params = {}
pos = 0 pos = 0
# ensure the entire markup string from start to end is valid syntax, and params are separated by spaces # ensure the entire markup string from start to end is valid syntax, and params are separated by spaces
@ -44,8 +44,9 @@ eos
value = match[3].gsub(/\\'/, "'") value = match[3].gsub(/\\'/, "'")
end end
@params[match[1]] = value params[match[1]] = value
end end
params
end end
def render(context) def render(context)
@ -64,8 +65,9 @@ eos
if choices.include?(@file) if choices.include?(@file)
source = File.read(@file) source = File.read(@file)
partial = Liquid::Template.parse(source) partial = Liquid::Template.parse(source)
context['include'] = @params
context.stack do context.stack do
context['include'] = parse_params(@params) if @params
partial.render(context) partial.render(context)
end end
else else