Merge pull request #4624 from jeffkole/feature/add-collection-url-tag
Merge pull request 4624
This commit is contained in:
commit
da4a664290
|
@ -0,0 +1,26 @@
|
|||
module Jekyll
|
||||
module Tags
|
||||
class Link < Liquid::Tag
|
||||
TagName = 'link'
|
||||
|
||||
def initialize(tag_name, relative_path, tokens)
|
||||
super
|
||||
|
||||
@relative_path = relative_path.strip
|
||||
end
|
||||
|
||||
def render(context)
|
||||
site = context.registers[:site]
|
||||
|
||||
site.docs_to_write.each do |document|
|
||||
return document.url if document.relative_path == @relative_path
|
||||
end
|
||||
|
||||
raise ArgumentError, "Could not find document '#{@relative_path}' in tag '#{TagName}'.\n\n" \
|
||||
"Make sure the document exists and the path is correct."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag(Jekyll::Tags::Link::TagName, Jekyll::Tags::Link)
|
|
@ -11,9 +11,8 @@ class TestTags < JekyllUnitTest
|
|||
def create_post(content, override = {}, converter_class = Jekyll::Converters::Markdown)
|
||||
site = fixture_site({"highlighter" => "rouge"}.merge(override))
|
||||
|
||||
if override['read_posts']
|
||||
site.posts.docs.concat(PostReader.new(site).read_posts(''))
|
||||
end
|
||||
site.posts.docs.concat(PostReader.new(site).read_posts('')) if override['read_posts']
|
||||
CollectionReader.new(site).read if override['read_collections']
|
||||
|
||||
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
|
||||
@converter = site.converters.find { |c| c.class == converter_class }
|
||||
|
@ -521,6 +520,69 @@ CONTENT
|
|||
end
|
||||
end
|
||||
|
||||
context "simple page with linking" do
|
||||
setup do
|
||||
content = <<CONTENT
|
||||
---
|
||||
title: linking
|
||||
---
|
||||
|
||||
{% link _methods/yaml_with_dots.md %}
|
||||
CONTENT
|
||||
create_post(content, {'source' => source_dir, 'destination' => dest_dir, 'collections' => { 'methods' => { 'output' => true }}, 'read_collections' => true})
|
||||
end
|
||||
|
||||
should "not cause an error" do
|
||||
refute_match /markdown\-html\-error/, @result
|
||||
end
|
||||
|
||||
should "have the url to the \"yaml_with_dots\" item" do
|
||||
assert_match %r{/methods/yaml_with_dots\.html}, @result
|
||||
end
|
||||
end
|
||||
|
||||
context "simple page with nested linking" do
|
||||
setup do
|
||||
content = <<CONTENT
|
||||
---
|
||||
title: linking
|
||||
---
|
||||
|
||||
- 1 {% link _methods/sanitized_path.md %}
|
||||
- 2 {% link _methods/site/generate.md %}
|
||||
CONTENT
|
||||
create_post(content, {'source' => source_dir, 'destination' => dest_dir, 'collections' => { 'methods' => { 'output' => true }}, 'read_collections' => true})
|
||||
end
|
||||
|
||||
should "not cause an error" do
|
||||
refute_match /markdown\-html\-error/, @result
|
||||
end
|
||||
|
||||
should "have the url to the \"sanitized_path\" item" do
|
||||
assert_match %r{1\s/methods/sanitized_path\.html}, @result
|
||||
end
|
||||
|
||||
should "have the url to the \"site/generate\" item" do
|
||||
assert_match %r{2\s/methods/site/generate\.html}, @result
|
||||
end
|
||||
end
|
||||
|
||||
context "simple page with invalid linking" do
|
||||
should "cause an error" do
|
||||
content = <<CONTENT
|
||||
---
|
||||
title: Invalid linking
|
||||
---
|
||||
|
||||
{% link non-existent-collection-item %}
|
||||
CONTENT
|
||||
|
||||
assert_raises ArgumentError do
|
||||
create_post(content, {'source' => source_dir, 'destination' => dest_dir, 'collections' => { 'methods' => { 'output' => true }}, 'read_collections' => true})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "include tag with parameters" do
|
||||
|
||||
context "with symlink'd include" do
|
||||
|
|
Loading…
Reference in New Issue