From 2b01b06ec884ab149c619333ed94fdb89dea69fb Mon Sep 17 00:00:00 2001 From: imathis Date: Sat, 22 Jun 2013 15:46:19 +0200 Subject: [PATCH] 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. --- lib/jekyll/tags/include.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index b98b6041..6956f6a3 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -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