Fix minor code style recommendations and typos.

This commit is contained in:
Thomas Wood 2016-04-12 18:52:34 +01:00
parent 66c4ff8800
commit 1ef7653fed
2 changed files with 11 additions and 11 deletions

View File

@ -235,13 +235,13 @@ module Jekyll
# Returns the filtered array of objects # Returns the filtered array of objects
def where_exp(input, variable, expression) def where_exp(input, variable, expression)
return input unless input.is_a?(Enumerable) return input unless input.is_a?(Enumerable)
input = input.values if input.is_a?(Hash) input = input.values if input.is_a?(Hash) # FIXME
c = parse_condition(expression) condition = parse_condition(expression)
@context.stack do @context.stack do
input.select do |object| input.select do |object|
@context[variable] = object @context[variable] = object
c.evaluate(@context) condition.evaluate(@context)
end end
end end
end end
@ -388,13 +388,13 @@ module Jekyll
# Parse a string to a Liquid Condition # Parse a string to a Liquid Condition
def parse_condition(exp) def parse_condition(exp)
parser = Liquid::Parser.new(exp) parser = Liquid::Parser.new(exp)
a = parser.expression left_expr = parser.expression
if op = parser.consume?(:comparison) condition =
b = parser.expression if operator = parser.consume?(:comparison)
condition = Liquid::Condition.new(a, op, b) Liquid::Condition.new(left_expr, operator, parser.expression)
else else
condition = Liquid::Condition.new(a) Liquid::Condition.new(left_expr)
end end
parser.consume(:end_of_string) parser.consume(:end_of_string)
condition condition

View File

@ -100,7 +100,7 @@ common tasks easier.
<code class="filter">{% raw %}{{ site.members | where_exp:"item", <code class="filter">{% raw %}{{ site.members | where_exp:"item",
"item.graduation_year < 2014" }}{% endraw %}</code> "item.graduation_year < 2014" }}{% endraw %}</code>
<code class="filter">{% raw %}{{ site.members | where_exp:"item", <code class="filter">{% raw %}{{ site.members | where_exp:"item",
"item.projects includes 'foo'" }}{% endraw %}</code> "item.projects contains 'foo'" }}{% endraw %}</code>
</p> </p>
</td> </td>
</tr> </tr>