diff --git a/lib/jekyll/tags/link.rb b/lib/jekyll/tags/link.rb new file mode 100644 index 00000000..f81e43b4 --- /dev/null +++ b/lib/jekyll/tags/link.rb @@ -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) diff --git a/test/test_tags.rb b/test/test_tags.rb index b6402150..bd481265 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -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 = < 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 = < 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 = < 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