From f72365da4fee5e69cb96d20dc61c7fbdafe0f198 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 8 Jul 2013 18:48:47 +0200 Subject: [PATCH] more code improvements Remove unused variable, extract validation to method (@mattr-). Do not require markup to be passed to parse_params as argument. --- lib/jekyll/tags/include.rb | 40 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 38b20a7e..5acb5391 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -9,24 +9,11 @@ module Jekyll @file, @params = markup.strip.split(' ', 2); end - def parse_params(markup, context) + def parse_params(context) + validate_syntax + params = {} - pos = 0 - - # 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 + markup = @params while match = MATCHER.match(markup) do markup = markup[match.end(0)..-1] @@ -44,6 +31,23 @@ eos params 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) includes_dir = File.join(context.registers[:site].source, '_includes') @@ -62,7 +66,7 @@ eos partial = Liquid::Template.parse(source) context.stack do - context['include'] = parse_params(@params, context) if @params + context['include'] = parse_params(context) if @params partial.render(context) end else