Merge pull request #1726 from maul-esel/include-fix
fix variable include tag in a loop
This commit is contained in:
commit
e0ef667dad
|
@ -46,3 +46,12 @@ Feature: Include tags
|
|||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "a snippet that works with parameters" in "_site/index.html"
|
||||
|
||||
Scenario: Include a variable file in a loop
|
||||
Given I have an _includes directory
|
||||
And I have an "_includes/one.html" file that contains "one"
|
||||
And I have an "_includes/two.html" file that contains "two"
|
||||
And I have an "index.html" page with files "[one.html, two.html]" that contains "{% for file in page.files %}{% include {{file}} %} {% endfor %}"
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "one two" in "_site/index.html"
|
||||
|
|
|
@ -43,8 +43,8 @@ module Jekyll
|
|||
params
|
||||
end
|
||||
|
||||
def validate_file_name
|
||||
if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
|
||||
def validate_file_name(file)
|
||||
if file !~ /^[a-zA-Z0-9_\/\.-]+$/ || file =~ /\.\// || file =~ /\/\./
|
||||
raise ArgumentError.new <<-eos
|
||||
Invalid syntax for include tag. File contains invalid characters or sequences:
|
||||
|
||||
|
@ -82,7 +82,7 @@ eos
|
|||
def retrieve_variable(context)
|
||||
if /\{\{([\w\-\.]+)\}\}/ =~ @file
|
||||
raise ArgumentError.new("No variable #{$1} was found in include tag") if context[$1].nil?
|
||||
@file = context[$1]
|
||||
context[$1]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -90,13 +90,13 @@ eos
|
|||
dir = File.join(context.registers[:site].source, INCLUDES_DIR)
|
||||
validate_dir(dir, context.registers[:site].safe)
|
||||
|
||||
retrieve_variable(context)
|
||||
validate_file_name
|
||||
file = retrieve_variable(context) || @file
|
||||
validate_file_name(file)
|
||||
|
||||
file = File.join(dir, @file)
|
||||
validate_file(file, context.registers[:site].safe)
|
||||
path = File.join(dir, file)
|
||||
validate_file(path, context.registers[:site].safe)
|
||||
|
||||
partial = Liquid::Template.parse(source(file, context))
|
||||
partial = Liquid::Template.parse(source(path, context))
|
||||
|
||||
context.stack do
|
||||
context['include'] = parse_params(context) if @params
|
||||
|
|
Loading…
Reference in New Issue