Merge pull request #2615 from alfredxing/collections-static-files

This commit is contained in:
Parker Moore 2014-08-02 14:44:45 -04:00
commit 81807cb5af
4 changed files with 41 additions and 4 deletions

View File

@ -83,6 +83,8 @@ Feature: frontmatter defaults
And I have a "index.html" file that contains "nothing" And I have a "index.html" file that contains "nothing"
And I have a "_slides/slide1.html" file with content: And I have a "_slides/slide1.html" file with content:
""" """
---
---
Value: {{ page.myval }} Value: {{ page.myval }}
""" """
And I have a "_config.yml" file with content: And I have a "_config.yml" file with content:

View File

@ -15,6 +15,7 @@ module Jekyll
@site = relations[:site] @site = relations[:site]
@path = path @path = path
@collection = relations[:collection] @collection = relations[:collection]
@has_yaml_header = nil
end end
# Fetch the Document's data. # Fetch the Document's data.
@ -80,12 +81,20 @@ module Jekyll
%w[.sass .scss .coffee].include?(extname) %w[.sass .scss .coffee].include?(extname)
end end
# Determine whether the document has a YAML header.
#
# Returns true if the file starts with three dashes
def has_yaml_header?
@has_yaml_header unless @has_yaml_header.nil?
@has_yaml_header = !!(File.open(path, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/)
end
# Determine whether the file should be rendered with Liquid. # Determine whether the file should be rendered with Liquid.
# #
# Returns false if the document is either an asset file or a yaml file, # Returns false if the document is either an asset file or a yaml file,
# true otherwise. # true otherwise.
def render_with_liquid? def render_with_liquid?
!(asset_file? || yaml_file?) !(asset_file? || yaml_file?) && has_yaml_header?
end end
# Determine whether the file should be placed into layouts. # Determine whether the file should be placed into layouts.
@ -93,7 +102,7 @@ module Jekyll
# Returns false if the document is either an asset file or a yaml file, # Returns false if the document is either an asset file or a yaml file,
# true otherwise. # true otherwise.
def place_in_layout? def place_in_layout?
!(asset_file? || yaml_file?) !(asset_file? || yaml_file?) && has_yaml_header?
end end
# The URL template where the document would be accessible. # The URL template where the document would be accessible.
@ -189,7 +198,7 @@ module Jekyll
unless defaults.empty? unless defaults.empty?
@data = defaults @data = defaults
end end
@content = File.read(path, merged_file_read_opts(opts)) @content = File.open(path, "rb") { |f| f.read }
if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
@content = $POSTMATCH @content = $POSTMATCH
data_file = SafeYAML.load($1) data_file = SafeYAML.load($1)

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -187,7 +187,33 @@ class TestDocument < Test::Unit::TestCase
end end
context " a document part of a rendered collection" do context "a static file in a collection" do
setup do
@site = Site.new(Jekyll.configuration({
"collections" => {
"slides" => {
"output" => true
}
},
"source" => source_dir,
"destination" => dest_dir
}))
@site.process
@document = @site.collections["slides"].docs.find { |doc| doc.relative_path == "_slides/octojekyll.png" }
@dest_file = dest_dir("slides/octojekyll.png")
end
should "be a document" do
assert !@document.nil?
end
should "not be rendered with Liquid" do
assert !@document.render_with_liquid?
end
should "be output in the correct place" do
assert File.file? @dest_file
end
end end
end end