Skip to content
Permalink
Browse files

Optimize Jekyll::Filters#item_property (#7696)

Merge pull request 7696
  • Loading branch information
ashmaroli committed Feb 6, 2020
1 parent 4406256 commit 8bb76c865f5c17323a95ccf1d91d001580fa6769
Showing with 20 additions and 9 deletions.
  1. +2 −0 .rubocop.yml
  2. +18 −9 lib/jekyll/filters.rb
@@ -79,6 +79,8 @@ Metrics/MethodLength:
Severity: error
Metrics/ModuleLength:
Max: 240
Exclude:
- lib/jekyll/filters.rb
Metrics/ParameterLists:
Max: 4
Metrics/PerceivedComplexity:
@@ -356,15 +356,24 @@ def item_property(item, property)
@item_property_cache ||= {}
@item_property_cache[property] ||= {}
@item_property_cache[property][item] ||= begin
if item.respond_to?(:to_liquid)
property.to_s.split(".").reduce(item.to_liquid) do |subvalue, attribute|
parse_sort_input(subvalue[attribute])
end
elsif item.respond_to?(:data)
parse_sort_input(item.data[property.to_s])
else
parse_sort_input(item[property.to_s])
end
property = property.to_s
property = if item.respond_to?(:to_liquid)
read_liquid_attribute(item.to_liquid, property)
elsif item.respond_to?(:data)
item.data[property]
else
item[property]
end

parse_sort_input(property)
end
end

def read_liquid_attribute(liquid_data, property)
return liquid_data[property] unless property.include?(".")

property.split(".").reduce(liquid_data) do |data, key|
data.respond_to?(:[]) && data[key]
end
end

0 comments on commit 8bb76c8

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