rubocop: fix code style
This commit is contained in:
parent
2f95517bfd
commit
5f2bb5d0aa
|
@ -9,7 +9,6 @@ AllCops:
|
||||||
- lib/jekyll/configuration.rb
|
- lib/jekyll/configuration.rb
|
||||||
- lib/jekyll/convertible.rb
|
- lib/jekyll/convertible.rb
|
||||||
- lib/jekyll/document.rb
|
- lib/jekyll/document.rb
|
||||||
- lib/jekyll/filters.rb
|
|
||||||
- lib/jekyll/regenerator.rb
|
- lib/jekyll/regenerator.rb
|
||||||
- lib/jekyll/renderer.rb
|
- lib/jekyll/renderer.rb
|
||||||
- lib/jekyll/static_file.rb
|
- lib/jekyll/static_file.rb
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'uri'
|
require "uri"
|
||||||
require 'json'
|
require "json"
|
||||||
require 'date'
|
require "date"
|
||||||
require 'liquid'
|
require "liquid"
|
||||||
|
|
||||||
module Jekyll
|
module Jekyll
|
||||||
module Filters
|
module Filters
|
||||||
|
@ -56,7 +56,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the given filename or title as a lowercase URL String.
|
# Returns the given filename or title as a lowercase URL String.
|
||||||
# See Utils.slugify for more detail.
|
# See Utils.slugify for more detail.
|
||||||
def slugify(input, mode=nil)
|
def slugify(input, mode = nil)
|
||||||
Utils.slugify(input, :mode => mode)
|
Utils.slugify(input, :mode => mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the escaped String.
|
# Returns the escaped String.
|
||||||
def xml_escape(input)
|
def xml_escape(input)
|
||||||
input.to_s.encode(:xml => :attr).gsub(/\A"|"\Z/, "")
|
input.to_s.encode(:xml => :attr).gsub(%r!\A"|"\Z!, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
# CGI escape a string for use in a URL. Replaces any special characters
|
# CGI escape a string for use in a URL. Replaces any special characters
|
||||||
|
@ -133,7 +133,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the escaped String.
|
# Returns the escaped String.
|
||||||
def cgi_escape(input)
|
def cgi_escape(input)
|
||||||
CGI::escape(input)
|
CGI.escape(input)
|
||||||
end
|
end
|
||||||
|
|
||||||
# URI escape a string.
|
# URI escape a string.
|
||||||
|
@ -180,7 +180,7 @@ module Jekyll
|
||||||
when 2
|
when 2
|
||||||
"#{array[0]} #{connector} #{array[1]}"
|
"#{array[0]} #{connector} #{array[1]}"
|
||||||
else
|
else
|
||||||
"#{array[0...-1].join(', ')}, #{connector} #{array[-1]}"
|
"#{array[0...-1].join(", ")}, #{connector} #{array[-1]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -203,10 +203,13 @@ module Jekyll
|
||||||
# "items" => [...] } # all the items where `property` == "larry"
|
# "items" => [...] } # all the items where `property` == "larry"
|
||||||
def group_by(input, property)
|
def group_by(input, property)
|
||||||
if groupable?(input)
|
if groupable?(input)
|
||||||
input.group_by do |item|
|
input.group_by { |item| item_property(item, property).to_s }
|
||||||
item_property(item, property).to_s
|
.each_with_object([]) do |item, array|
|
||||||
end.inject([]) do |memo, i|
|
array << {
|
||||||
memo << { "name" => i.first, "items" => i.last, "size" => i.last.size }
|
"name" => item.first,
|
||||||
|
"items" => item.last,
|
||||||
|
"size" => item.last.size
|
||||||
|
}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
input
|
input
|
||||||
|
@ -223,7 +226,9 @@ module Jekyll
|
||||||
def where(input, property, value)
|
def where(input, property, value)
|
||||||
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)
|
||||||
input.select { |object| Array(item_property(object, property)).map(&:to_s).include?(value.to_s) }
|
input.select do |object|
|
||||||
|
Array(item_property(object, property)).map(&:to_s).include?(value.to_s)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Filters an array of objects against an expression
|
# Filters an array of objects against an expression
|
||||||
|
@ -255,33 +260,21 @@ module Jekyll
|
||||||
# Returns the filtered array of objects
|
# Returns the filtered array of objects
|
||||||
def sort(input, property = nil, nils = "first")
|
def sort(input, property = nil, nils = "first")
|
||||||
if input.nil?
|
if input.nil?
|
||||||
raise ArgumentError.new("Cannot sort a null object.")
|
raise ArgumentError, "Cannot sort a null object."
|
||||||
end
|
end
|
||||||
if property.nil?
|
if property.nil?
|
||||||
input.sort
|
input.sort
|
||||||
else
|
else
|
||||||
case
|
if nils == "first"
|
||||||
when nils == "first"
|
|
||||||
order = - 1
|
order = - 1
|
||||||
when nils == "last"
|
elsif nils == "last"
|
||||||
order = + 1
|
order = + 1
|
||||||
else
|
else
|
||||||
raise ArgumentError.new("Invalid nils order: " \
|
raise ArgumentError, "Invalid nils order: " \
|
||||||
"'#{nils}' is not a valid nils order. It must be 'first' or 'last'.")
|
"'#{nils}' is not a valid nils order. It must be 'first' or 'last'."
|
||||||
end
|
end
|
||||||
|
|
||||||
input.sort do |apple, orange|
|
sort_input(input, property, order)
|
||||||
apple_property = item_property(apple, property)
|
|
||||||
orange_property = item_property(orange, property)
|
|
||||||
|
|
||||||
if !apple_property.nil? && orange_property.nil?
|
|
||||||
- order
|
|
||||||
elsif apple_property.nil? && !orange_property.nil?
|
|
||||||
+ order
|
|
||||||
else
|
|
||||||
apple_property <=> orange_property
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -332,6 +325,22 @@ module Jekyll
|
||||||
xml_escape(input.inspect)
|
xml_escape(input.inspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def sort_input(input, property, order)
|
||||||
|
input.sort do |apple, orange|
|
||||||
|
apple_property = item_property(apple, property)
|
||||||
|
orange_property = item_property(orange, property)
|
||||||
|
|
||||||
|
if !apple_property.nil? && orange_property.nil?
|
||||||
|
- order
|
||||||
|
elsif apple_property.nil? && !orange_property.nil?
|
||||||
|
+ order
|
||||||
|
else
|
||||||
|
apple_property <=> orange_property
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def time(input)
|
def time(input)
|
||||||
case input
|
case input
|
||||||
|
@ -349,10 +358,12 @@ module Jekyll
|
||||||
end.localtime
|
end.localtime
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
def groupable?(element)
|
def groupable?(element)
|
||||||
element.respond_to?(:group_by)
|
element.respond_to?(:group_by)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
def item_property(item, property)
|
def item_property(item, property)
|
||||||
if item.respond_to?(:to_liquid)
|
if item.respond_to?(:to_liquid)
|
||||||
item.to_liquid[property.to_s]
|
item.to_liquid[property.to_s]
|
||||||
|
@ -363,6 +374,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
def as_liquid(item)
|
def as_liquid(item)
|
||||||
case item
|
case item
|
||||||
when Hash
|
when Hash
|
||||||
|
@ -386,6 +398,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse a string to a Liquid Condition
|
# Parse a string to a Liquid Condition
|
||||||
|
private
|
||||||
def parse_condition(exp)
|
def parse_condition(exp)
|
||||||
parser = Liquid::Parser.new(exp)
|
parser = Liquid::Parser.new(exp)
|
||||||
left_expr = parser.expression
|
left_expr = parser.expression
|
||||||
|
|
Loading…
Reference in New Issue