filters#sample: n == 1, return item; n > 1, return array
This commit is contained in:
parent
0aa3c96d11
commit
2e91d094e5
|
@ -283,7 +283,12 @@ module Jekyll
|
|||
|
||||
def sample(input, num = 1)
|
||||
return input unless input.respond_to?(:sample)
|
||||
input.sample(num)
|
||||
sampling = input.sample(num)
|
||||
if num == 1
|
||||
sampling.first
|
||||
else
|
||||
sampling
|
||||
end
|
||||
end
|
||||
|
||||
# Convert an object into its String representation for debugging
|
||||
|
|
|
@ -397,7 +397,7 @@ class TestFilters < JekyllUnitTest
|
|||
should "allow sampling of multiple values (n > 1)" do
|
||||
input = %w(hey there bernie)
|
||||
@filter.sample(input, 2).each do |val|
|
||||
assert_includes val, input
|
||||
assert_includes input, val
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue