From d7e3d4df8fae5c70619eba9cfcc1ff83c4aae22e Mon Sep 17 00:00:00 2001 From: David Williamson Date: Thu, 20 Nov 2014 14:38:17 -0600 Subject: [PATCH 1/2] Add support for collections documents to have YAML front matter ending in dots. --- lib/jekyll/document.rb | 2 +- test/source/_methods/yaml_with_dots.md | 8 ++++++++ test/test_collections.rb | 1 + test/test_document.rb | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/source/_methods/yaml_with_dots.md diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 003c04eb..babc974a 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -210,7 +210,7 @@ module Jekyll @data = defaults end @content = File.read(path, merged_file_read_opts(opts)) - if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m + if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m @content = $POSTMATCH data_file = SafeYAML.load($1) unless data_file.nil? diff --git a/test/source/_methods/yaml_with_dots.md b/test/source/_methods/yaml_with_dots.md new file mode 100644 index 00000000..eb0b6675 --- /dev/null +++ b/test/source/_methods/yaml_with_dots.md @@ -0,0 +1,8 @@ +--- +title: "YAML with Dots" +whatever: foo.bar +... + +Use `{{ page.title }}` to build a full configuration for use w/Jekyll. + +Whatever: {{ page.whatever }} diff --git a/test/test_collections.rb b/test/test_collections.rb index 1975e402..de4dfa07 100644 --- a/test/test_collections.rb +++ b/test/test_collections.rb @@ -138,6 +138,7 @@ class TestCollections < Test::Unit::TestCase _methods/site/generate.md _methods/site/initialize.md _methods/um_hi.md + _methods/yaml_with_dots.md ], doc.relative_path end end diff --git a/test/test_document.rb b/test/test_document.rb index 90c16b82..60a56421 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -44,6 +44,26 @@ class TestDocument < Test::Unit::TestCase }, @document.data) end + context "with YAML ending in three dots" do + + setup do + @site = Site.new(Jekyll.configuration({ + "collections" => ["methods"], + "source" => source_dir, + "destination" => dest_dir + })) + @site.process + @document = @site.collections["methods"].docs.last + end + + should "know its data" do + assert_equal({ + "title" => "YAML with Dots", + "whatever" => "foo.bar" + }, @document.data) + end + end + should "output the collection name in the #to_liquid method" do assert_equal @document.to_liquid['collection'], "methods" end From c7d92c4e6d0ba4750c7955b43f51da4b30b3902f Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 17 Jan 2015 15:23:33 -0800 Subject: [PATCH 2/2] Move YAML Front Matter regexp into a constant. --- lib/jekyll/document.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index babc974a..a1287a20 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -7,6 +7,8 @@ module Jekyll attr_reader :path, :site, :extname attr_accessor :content, :collection, :output + YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m + # Create a new Document. # # site - the Jekyll::Site instance to which this Document belongs @@ -210,7 +212,7 @@ module Jekyll @data = defaults end @content = File.read(path, merged_file_read_opts(opts)) - if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m + if content =~ YAML_FRONT_MATTER_REGEXP @content = $POSTMATCH data_file = SafeYAML.load($1) unless data_file.nil?