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
Allow sorting by custom properties #1849
Conversation
K, ready for 👀! |
# | ||
# Returns the String value or nil if the property isn't included. | ||
def [](property) | ||
data[property] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only worry with this is that then folks won't be able to sort by layout
, name
, dir
, etc. data
doesn't encase everything, unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely true, since some of those will be covered by the respond_to?
. I'll add some more tests and make #[]
cover all of the attributes we could want.
K, made (most) other properties accessible via |
@afeld Awesome! Looks like Travis doesn't like your latest changes. Would you mind fixing up those broken tests? Thanks! |
Fixed! |
# | ||
# Returns the String value or nil if the property isn't included. | ||
def [](property) | ||
if self.class::ATTRIBUTES_FOR_LIQUID.include?(property) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this:
if respond_to?(property.to_sym)
send(property.to_sym)
elsif respond_to?(:data)
data[property]
else
""
end
Or something? What kind of precedent are you looking to take advantage of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking at the other uses of ATTRIBUTES_FOR_LIQUID, which I assume is a security measure so that arbitrary methods can't be called through Liquid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mm, the security vulnerabilities are definitely an important concern. What about using to_liquid.include?
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because then it's needlessly constructing the whole hash, where only the keys and the single value are needed. I think there's a lot of refactoring that could be done around to_liquid
, but I'm hoping to keep this PR from getting too complicated.
Looks pretty good to me. @mattr-, would love to get your 👀 on this. |
I'm 👍 on this. Just want @mattr-'s input then we'll be good to go. |
Looks fine to me. Although I beginning to think I'm the only person who still prefers hashrockets to the new ruby 1.9 syntax. 😃 |
This is in 2.0.0.rc1 latest, right? I've been struggling with trying to sort my Here's what I've got right now: (default.html template snippet)
|
Maybe @penibelst is experiencing the same issue with |
@qrohlf Is |
@penibelst yeah, it's empty. |
@qrohlf I would say the sorting feature is broken. |
Fixes #1802.
Added a failing test to support
sort:'some-custom-property'
. Have spent a couple hours poking around Jekyll/Liquid to figure out how to make those properties available to the filter, but haven't been able to figure it out yet.Presumably a fix would work for other filters as well? Not sure how to test more generically.
P.S. These things are called "variables" in http://jekyllrb.com/docs/frontmatter/, but are called "properties" in the Liquid docs (e.g. in
sort
). Sorry for my inconsistency... I'll clean up later./cc @parkr @haacked