Skip to content
Permalink
Browse files

Add `type` attribute to Document instances (#7406)

Merge pull request 7406
  • Loading branch information...
ashmaroli authored and jekyllbot committed May 16, 2019
1 parent db2de73 commit 49ffbbd4c761a67fc930acd257ae932111464b28
Showing with 19 additions and 7 deletions.
  1. +5 −6 lib/jekyll/document.rb
  2. +1 −1 lib/jekyll/excerpt.rb
  3. +4 −0 test/test_document.rb
  4. +9 −0 test/test_excerpt.rb
@@ -5,7 +5,7 @@ class Document
include Comparable
extend Forwardable

attr_reader :path, :site, :extname, :collection
attr_reader :path, :site, :extname, :collection, :type
attr_accessor :content, :output

def_delegator :self, :read_post_data, :post_read
@@ -44,6 +44,8 @@ def initialize(path, relations = {})
@path = path
@extname = File.extname(path)
@collection = relations[:collection]
@type = @collection.label.to_sym

@has_yaml_header = nil

if draft?
@@ -53,7 +55,7 @@ def initialize(path, relations = {})
end

data.default_proc = proc do |_, key|
site.frontmatter_defaults.find(relative_path, collection.label, key)
site.frontmatter_defaults.find(relative_path, type, key)
end

trigger_hooks(:post_init)
@@ -462,10 +464,7 @@ def merge_date!(source)
end

def merge_defaults
defaults = @site.frontmatter_defaults.all(
relative_path,
collection.label.to_sym
)
defaults = @site.frontmatter_defaults.all(relative_path, type)
merge_data!(defaults, :source => "front matter defaults") unless defaults.empty?
end

@@ -10,7 +10,7 @@ class Excerpt

def_delegators :@doc,
:site, :name, :ext, :extname,
:collection, :related_posts,
:collection, :related_posts, :type,
:coffeescript_file?, :yaml_file?,
:url, :next_doc, :previous_doc

@@ -58,6 +58,10 @@ def setup_document_with_dates(filename)
assert_equal "configuration", @document.basename_without_ext
end

should "know its type" do
assert_equal :methods, @document.type
end

should "know whether it's a YAML file" do
assert_equal false, @document.yaml_file?
end
@@ -56,6 +56,15 @@ def do_render(document)
end
end

context "#type" do
should "return the post's type" do
assert_equal @excerpt.type, @post.type
end
should "return a symbol" do
assert_same @excerpt.type.class, Symbol
end
end

context "#to_s" do
should "return rendered output" do
assert_equal @excerpt.output, @excerpt.to_s

0 comments on commit 49ffbbd

Please sign in to comment.
You can’t perform that action at this time.