Support a new relative_include tag

This commit is contained in:
Garen Torikian
2014-09-03 15:43:51 -07:00
parent 18eb8e6fb7
commit aa97f1025d
7 changed files with 90 additions and 8 deletions

View File

@@ -0,0 +1,25 @@
---
title: Post
layout: post
include1: rel_include.html
include2: relative_includes/rel_include
include3: rel_INCLUDE
include4: params
include5: clude
---
Liquid tests
- 1 {% relative_include relative_includes/{{ page.include1 }} %}
- 2 {% relative_include {{ page.include2 | append: '.html' }} %}
- 3 {% relative_include relative_includes/{{ page.include3 | downcase | append: '.html' }} %}
Whitespace tests
- 4 {% relative_include relative_includes/{{page.include1}} %}
- 5 {% relative_include relative_includes/{{ page.include1}} %}
- 6 {% relative_include relative_includes/{{ page.include3 | downcase | append: '.html'}} %}
Parameters test
- 7 {% relative_include relative_includes/{{ page.include4 | append: '.html' }} var1='foo' var2='bar' %}
Partial variable test
- 8 {% relative_include relative_includes/rel_in{{ page.include5 }}.html %}

View File

@@ -0,0 +1,7 @@
<span id='include-param'>{{include.param}}</span>
<ul id='param-list'>
{% for param in include %}
<li>{{param[0]}} = {{param[1]}}</li>
{% endfor %}
</ul>

View File

@@ -0,0 +1 @@
relative_included

View File

@@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
end
should "ensure post count is as expected" do
assert_equal 42, @site.posts.size
assert_equal 43, @site.posts.size
end
should "insert site.posts into the index" do

View File

@@ -48,7 +48,7 @@ class TestSite < Test::Unit::TestCase
Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir})
end
@site = Site.new(Jekyll.configuration)
@num_invalid_posts = 2
@num_invalid_posts = 4
end
should "have an empty tag hash by default" do

View File

@@ -509,5 +509,40 @@ CONTENT
assert_match %r{8 included}, @content
end
end
context "relative include tag with variable and liquid filters" do
setup do
stub(Jekyll).configuration do
site_configuration({'pygments' => true})
end
site = Site.new(Jekyll.configuration)
post = Post.new(site, source_dir, '', "2014-09-02-relative-includes.markdown")
layouts = { "default" => Layout.new(site, source_dir('_layouts'), "simple.html")}
post.render(layouts, {"site" => {"posts" => []}})
@content = post.content
end
should "include file as variable with liquid filters" do
assert_match %r{1 relative_include}, @content
assert_match %r{2 relative_include}, @content
assert_match %r{3 relative_include}, @content
end
should "include file as variable and liquid filters with arbitrary whitespace" do
assert_match %r{4 relative_include}, @content
assert_match %r{5 relative_include}, @content
assert_match %r{6 relative_include}, @content
end
should "include file as variable and filters with additional parameters" do
assert_match '<li>var1 = foo</li>', @content
assert_match '<li>var2 = bar</li>', @content
end
should "include file as partial variable" do
assert_match %r{8 relative_include}, @content
end
end
end
end