Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type attribute to Document instances #7406

Merged
merged 2 commits into from
May 16, 2019

Conversation

ashmaroli
Copy link
Member

  • This is a 🙋 feature or enhancement.
  • I've added tests
  • The test suite passes locally

Summary

  • Maintains consistency between Jekyll::Page and Jekyll::StaticFile where instances the latter two classes respond to the :type method.
  • Optimizes Front Matter Defaults for Documents by not needing to check for both @doc.collection.label and @doc.collection.label.to_sym as is done currently

@ashmaroli ashmaroli added this to the 4.0 milestone Dec 6, 2018
@ashmaroli ashmaroli requested a review from a team December 6, 2018 18:53
@ashmaroli
Copy link
Member Author

Profiler summary

--- master branch https://travis-ci.org/jekyll/jekyll/jobs/532959217
+++ PR branch     https://travis-ci.org/jekyll/jekyll/jobs/533140377

- Total allocated: 532.65 MB (5301707 objects)
- Total retained:  18.34 MB (96237 objects)
+ Total allocated: 532.4 MB (5296981 objects)
+ Total retained:  18.33 MB (95977 objects)

test/test_excerpt.rb Show resolved Hide resolved
@@ -39,7 +41,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was collection.label already a symbol? If not, is our replacing it with a symbol here safe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is safe because, it is expected (from the comments):

# Finds a default value for a given setting, filtered by path and type
#
# path - the path (relative to the source) of the page,
# post or :draft the default is used in
# type - a symbol indicating whether a :page,
# a :post or a :draft calls this method
#
# Returns the default value or nil if none was found
def find(path, type, setting)
value = nil
old_scope = nil
matching_sets(path, type).each do |set|
if set["values"].key?(setting) && has_precedence?(old_scope, set["scope"])
value = set["values"][setting]
old_scope = set["scope"]
end
end
value
end

@mattr-
Copy link
Member

mattr- commented May 16, 2019

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit 49ffbbd into jekyll:master May 16, 2019
jekyllbot added a commit that referenced this pull request May 16, 2019
@ashmaroli ashmaroli deleted the document-type branch May 16, 2019 15:46
@jekyll jekyll locked and limited conversation to collaborators May 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants