diff --git a/features/frontmatter_defaults.feature b/features/frontmatter_defaults.feature index 41a7a35e..7ac2d0a8 100644 --- a/features/frontmatter_defaults.feature +++ b/features/frontmatter_defaults.feature @@ -83,6 +83,8 @@ Feature: frontmatter defaults And I have a "index.html" file that contains "nothing" And I have a "_slides/slide1.html" file with content: """ + --- + --- Value: {{ page.myval }} """ And I have a "_config.yml" file with content: diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index c1041a5c..9b0e9c9f 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -15,6 +15,7 @@ module Jekyll @site = relations[:site] @path = path @collection = relations[:collection] + @has_yaml_header = nil end # Fetch the Document's data. @@ -80,12 +81,20 @@ module Jekyll %w[.sass .scss .coffee].include?(extname) 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. # # Returns false if the document is either an asset file or a yaml file, # true otherwise. def render_with_liquid? - !(asset_file? || yaml_file?) + !(asset_file? || yaml_file?) && has_yaml_header? end # 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, # true otherwise. def place_in_layout? - !(asset_file? || yaml_file?) + !(asset_file? || yaml_file?) && has_yaml_header? end # The URL template where the document would be accessible. @@ -189,7 +198,7 @@ module Jekyll unless defaults.empty? @data = defaults 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 @content = $POSTMATCH data_file = SafeYAML.load($1) diff --git a/test/source/_slides/octojekyll.png b/test/source/_slides/octojekyll.png new file mode 100644 index 00000000..7c6d96d7 Binary files /dev/null and b/test/source/_slides/octojekyll.png differ diff --git a/test/test_document.rb b/test/test_document.rb index 17b15a67..3e3397c6 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -187,7 +187,33 @@ class TestDocument < Test::Unit::TestCase 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