Merge branch 'davidized-collection_yaml_dots'

* davidized-collection_yaml_dots:
  Move YAML Front Matter regexp into a constant.
  Add support for collections documents to have YAML front matter ending in dots.

Conflicts:
	test/test_collections.rb
This commit is contained in:
Parker Moore 2015-01-17 15:24:33 -08:00
commit b2099ac763
4 changed files with 32 additions and 1 deletions

View File

@ -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
@ -217,7 +219,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?

View File

@ -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 }}

View File

@ -139,6 +139,7 @@ class TestCollections < Test::Unit::TestCase
_methods/site/initialize.md
_methods/um_hi.md
_methods/escape-+\ #%20[].md
_methods/yaml_with_dots.md
], doc.relative_path
end
end

View File

@ -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