Compare commits

...

6 Commits

Author SHA1 Message Date
Parker Moore
35848b9c06 Handle Liquid v4 'empty' and 'blank' values explicitly
Prevents a lookup error since Liquid::Expression::MethodLiteral doesn't exist in v5
2022-04-11 13:22:14 -07:00
Parker Moore
e2850341d2 Include MethodLiteral for Liquid v4 support 2022-04-11 13:11:05 -07:00
Parker Moore
7a3dd9a0e3 Gemfile: filter empty LIQUID_VERSION vars 2022-04-11 12:26:06 -07:00
Parker Moore
6a32be65e9 compare_property_vs_target: match "" for empty & blank
The MethodLiteral was a leaky abstraction. We needed to match against the to_liquid value, which is "" in both cases.
2022-04-11 12:25:06 -07:00
Parker Moore
03ac1d727b Add Liquid v4 to CI 2022-04-11 12:23:23 -07:00
Parker Moore
f8540633c3 Upgrade from Liquid 4 to Liquid 5 2022-04-10 11:54:27 -07:00
6 changed files with 24 additions and 13 deletions

View File

@@ -26,6 +26,9 @@ jobs:
ruby_version: "3.1"
- label: JRuby 9.3.4.0
ruby_version: "jruby-9.3.4.0"
- label: Liquid 4
ruby_version: 3.1
liquid_version: "~> 4.0"
steps:
- name: Checkout Repository
uses: actions/checkout@v3
@@ -34,6 +37,8 @@ jobs:
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
env:
LIQUID_VERSION: ${{ matrix.liquid_version }}
- name: Run Minitest based tests
run: bash script/test
- name: Run Cucumber based tests

View File

@@ -5,6 +5,10 @@ gemspec :name => "jekyll"
gem "rake", "~> 13.0"
if ENV["LIQUID_VERSION"] && ENV["LIQUID_VERSION"] != ""
gem "liquid", ENV["LIQUID_VERSION"]
end
group :development do
gem "launchy", "~> 2.3"
gem "pry"

View File

@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("jekyll-watch", "~> 2.0")
s.add_runtime_dependency("kramdown", "~> 2.3", ">= 2.3.1")
s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
s.add_runtime_dependency("liquid", "~> 4.0")
s.add_runtime_dependency("liquid", ">= 4.0", "< 6.0")
s.add_runtime_dependency("mercenary", ">= 0.3.6", "< 0.5")
s.add_runtime_dependency("pathutil", "~> 0.9")

View File

@@ -398,11 +398,17 @@ module Jekyll
# `where` filter helper
#
def compare_property_vs_target(property, target)
# Liquid v4 handles 'empty' and 'blank' keywords separately from v5.
# Delete when we remove Liquid v5 support.
if Liquid::VERSION.start_with?("4.") && target.is_a?(Liquid::Expression::MethodLiteral)
target = target.to_s
return true if property == target || Array(property).join == target
end
case target
when NilClass
return true if property.nil?
when Liquid::Expression::MethodLiteral # `empty` or `blank`
target = target.to_s
when "", Liquid::Expression::MethodLiteral # empty/blank hashes and arrays will match this
return true if property == target || Array(property).join == target
else
target = target.to_s

View File

@@ -918,13 +918,13 @@ class TestFilters < JekyllUnitTest
# `{{ hash | where: 'tags', empty }}`
assert_equal(
[{ "tags" => {} }, { "tags" => "" }, { "tags" => nil }, { "tags" => [] }],
@filter.where(hash, "tags", Liquid::Expression::LITERALS["empty"])
@filter.where(hash, "tags", Liquid::Condition.parse_expression(nil, "empty"))
)
# `{{ `hash | where: 'tags', blank }}`
assert_equal(
[{ "tags" => {} }, { "tags" => "" }, { "tags" => nil }, { "tags" => [] }],
@filter.where(hash, "tags", Liquid::Expression::LITERALS["blank"])
@filter.where(hash, "tags", Liquid::Condition.parse_expression(nil, "blank"))
)
end
@@ -1151,13 +1151,13 @@ class TestFilters < JekyllUnitTest
# `{{ hash | find: 'tags', empty }}`
assert_equal(
{ "tags" => {} },
@filter.find(hash, "tags", Liquid::Expression::LITERALS["empty"])
@filter.find(hash, "tags", Liquid::Condition.parse_expression(nil, "empty"))
)
# `{{ `hash | find: 'tags', blank }}`
assert_equal(
{ "tags" => {} },
@filter.find(hash, "tags", Liquid::Expression::LITERALS["blank"])
@filter.find(hash, "tags", Liquid::Condition.parse_expression(nil, "blank"))
)
end

View File

@@ -42,12 +42,8 @@ class TestTags < JekyllUnitTest
end
def highlight_block_with_opts(options_string)
Jekyll::Tags::HighlightBlock.parse(
"highlight",
options_string,
Liquid::Tokenizer.new("test{% endhighlight %}\n"),
Liquid::ParseContext.new
)
template = Liquid::Template.parse("{% highlight #{options_string} %}test{% endhighlight %}")
template.root.nodelist.first
end
context "language name" do