Merge pull request #2615 from alfredxing/collections-static-files
This commit is contained in:
		
						commit
						81807cb5af
					
				| 
						 | 
				
			
			@ -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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 22 KiB  | 
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue