filters#sample: n == 1, return item; n > 1, return array

This commit is contained in:
Parker Moore 2015-12-04 10:25:13 -08:00
parent 0aa3c96d11
commit 2e91d094e5
2 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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