more code improvements
Remove unused variable, extract validation to method (@mattr-). Do not require markup to be passed to parse_params as argument.
This commit is contained in:
parent
ef22ebd7f1
commit
f72365da4f
|
@ -9,24 +9,11 @@ module Jekyll
|
||||||
@file, @params = markup.strip.split(' ', 2);
|
@file, @params = markup.strip.split(' ', 2);
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_params(markup, context)
|
def parse_params(context)
|
||||||
|
validate_syntax
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
pos = 0
|
markup = @params
|
||||||
|
|
||||||
# ensure the entire markup string from start to end is valid syntax, and params are separated by spaces
|
|
||||||
full_matcher = Regexp.compile('\A\s*(?:' + MATCHER.to_s + '(?=\s|\z)\s*)*\z')
|
|
||||||
unless markup =~ full_matcher
|
|
||||||
raise SyntaxError.new <<-eos
|
|
||||||
Invalid syntax for include tag:
|
|
||||||
|
|
||||||
#{markup}
|
|
||||||
|
|
||||||
Valid syntax:
|
|
||||||
|
|
||||||
{% include file.ext param='value' param2="value" %}
|
|
||||||
|
|
||||||
eos
|
|
||||||
end
|
|
||||||
|
|
||||||
while match = MATCHER.match(markup) do
|
while match = MATCHER.match(markup) do
|
||||||
markup = markup[match.end(0)..-1]
|
markup = markup[match.end(0)..-1]
|
||||||
|
@ -44,6 +31,23 @@ eos
|
||||||
params
|
params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ensure the entire markup string from start to end is valid syntax, and params are separated by spaces
|
||||||
|
def validate_syntax
|
||||||
|
full_matcher = Regexp.compile('\A\s*(?:' + MATCHER.to_s + '(?=\s|\z)\s*)*\z')
|
||||||
|
unless @params =~ full_matcher
|
||||||
|
raise SyntaxError.new <<-eos
|
||||||
|
Invalid syntax for include tag:
|
||||||
|
|
||||||
|
#{@params}
|
||||||
|
|
||||||
|
Valid syntax:
|
||||||
|
|
||||||
|
{% include file.ext param='value' param2="value" %}
|
||||||
|
|
||||||
|
eos
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
includes_dir = File.join(context.registers[:site].source, '_includes')
|
includes_dir = File.join(context.registers[:site].source, '_includes')
|
||||||
|
|
||||||
|
@ -62,7 +66,7 @@ eos
|
||||||
partial = Liquid::Template.parse(source)
|
partial = Liquid::Template.parse(source)
|
||||||
|
|
||||||
context.stack do
|
context.stack do
|
||||||
context['include'] = parse_params(@params, context) if @params
|
context['include'] = parse_params(context) if @params
|
||||||
partial.render(context)
|
partial.render(context)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue