Merge pull request #4362 from jekyll/liquid-4

Merge pull request 4362
This commit is contained in:
jekyllbot 2017-01-27 11:10:53 -05:00 committed by GitHub
commit 2cf685feb2
6 changed files with 46 additions and 24 deletions

View File

@ -34,7 +34,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("jekyll-sass-converter", "~> 1.0")
s.add_runtime_dependency("jekyll-watch", "~> 1.1")
s.add_runtime_dependency("kramdown", "~> 1.3")
s.add_runtime_dependency("liquid", "~> 3.0")
s.add_runtime_dependency("liquid", "~> 4.0")
s.add_runtime_dependency("mercenary", "~> 0.3.3")
s.add_runtime_dependency("pathutil", "~> 0.9")
s.add_runtime_dependency("rouge", "~> 1.7")

View File

@ -19,6 +19,10 @@ module Jekyll
end
end
def key?(key)
(@obj.collections.key?(key) && key != "posts") || super
end
def posts
@site_posts ||= @obj.posts.docs.sort { |a, b| b <=> a }
end

View File

@ -280,10 +280,11 @@ module Jekyll
end
end
def pop(array, input = 1)
def pop(array, num = 1)
return array unless array.is_a?(Array)
num = Liquid::Utils.to_integer(num)
new_ary = array.dup
new_ary.pop(input.to_i || 1)
new_ary.pop(num)
new_ary
end
@ -294,10 +295,11 @@ module Jekyll
new_ary
end
def shift(array, input = 1)
def shift(array, num = 1)
return array unless array.is_a?(Array)
num = Liquid::Utils.to_integer(num)
new_ary = array.dup
new_ary.shift(input.to_i || 1)
new_ary.shift(num)
new_ary
end
@ -310,11 +312,11 @@ module Jekyll
def sample(input, num = 1)
return input unless input.respond_to?(:sample)
n = num.to_i rescue 1
if n == 1
num = Liquid::Utils.to_integer(num) rescue 1
if num == 1
input.sample
else
input.sample(n)
input.sample(num)
end
end
@ -345,19 +347,12 @@ module Jekyll
private
def time(input)
case input
when Time
input.clone
when Date
input.to_time
when String
Time.parse(input) rescue Time.at(input.to_i)
when Numeric
Time.at(input)
else
date = Liquid::Utils.to_date(input)
unless date.respond_to?(:to_time)
raise Errors::InvalidDateError,
"Invalid Date: '#{input.inspect}' is not a valid datetime."
end.localtime
end
date.to_time.localtime
end
private
@ -402,9 +397,11 @@ module Jekyll
operator = parser.consume?(:comparison)
condition =
if operator
Liquid::Condition.new(left_expr, operator, parser.expression)
Liquid::Condition.new(Liquid::Expression.parse(left_expr),
operator,
Liquid::Expression.parse(parser.expression))
else
Liquid::Condition.new(left_expr)
Liquid::Condition.new(Liquid::Expression.parse(left_expr))
end
parser.consume(:end_of_string)

View File

@ -40,7 +40,7 @@ module Jekyll
private
def parse_expression(str)
Liquid::Variable.new(str, {})
Liquid::Variable.new(str, Liquid::ParseContext.new)
end
private

21
test/test_site_drop.rb Normal file
View File

@ -0,0 +1,21 @@
require "helper"
class TestSiteDrop < JekyllUnitTest
context "a site drop" do
setup do
@site = fixture_site({
"collections" => ["thanksgiving"]
})
@site.process
@drop = @site.to_liquid.site
end
should "respond to `key?`" do
assert @drop.respond_to?(:key?)
end
should "find a key if it's in the collection of the drop" do
assert @drop.key?("thanksgiving")
end
end
end

View File

@ -46,8 +46,8 @@ CONTENT
Jekyll::Tags::HighlightBlock.parse(
"highlight",
options_string,
["test", "{% endhighlight %}", "\n"],
{}
Liquid::Tokenizer.new("test{% endhighlight %}\n"),
Liquid::ParseContext.new
)
end