rubocop: fix code style

This commit is contained in:
Anatoliy Yastreb 2016-06-25 15:11:50 +03:00
parent 6dd3cc21c4
commit 2bbad7cb43
1 changed files with 30 additions and 20 deletions

View File

@ -1,6 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
require 'set' require "set"
# Convertible provides methods for converting a pagelike item # Convertible provides methods for converting a pagelike item
# from a certain type of markup into actual content # from a certain type of markup into actual content
@ -20,12 +20,12 @@ module Jekyll
module Convertible module Convertible
# Returns the contents as a String. # Returns the contents as a String.
def to_s def to_s
content || '' content || ""
end end
# Whether the file is published or not, as indicated in YAML front-matter # Whether the file is published or not, as indicated in YAML front-matter
def published? def published?
!(data.key?('published') && data['published'] == false) !(data.key?("published") && data["published"] == false)
end end
# Read the YAML frontmatter. # Read the YAML frontmatter.
@ -47,7 +47,7 @@ module Jekyll
end end
rescue SyntaxError => e rescue SyntaxError => e
Jekyll.logger.warn "YAML Exception reading #{filename}: #{e.message}" Jekyll.logger.warn "YAML Exception reading #{filename}: #{e.message}"
rescue Exception => e rescue => e
Jekyll.logger.warn "Error reading file #{filename}: #{e.message}" Jekyll.logger.warn "Error reading file #{filename}: #{e.message}"
end end
@ -61,12 +61,13 @@ module Jekyll
def validate_data!(filename) def validate_data!(filename)
unless self.data.is_a?(Hash) unless self.data.is_a?(Hash)
raise Errors::InvalidYAMLFrontMatterError, "Invalid YAML front matter in #{filename}" raise Errors::InvalidYAMLFrontMatterError,
"Invalid YAML front matter in #{filename}"
end end
end end
def validate_permalink!(filename) def validate_permalink!(filename)
if self.data['permalink'] && self.data['permalink'].size == 0 if self.data["permalink"] && self.data["permalink"].empty?
raise Errors::InvalidPermalinkError, "Invalid permalink in #{filename}" raise Errors::InvalidPermalinkError, "Invalid permalink in #{filename}"
end end
end end
@ -79,7 +80,10 @@ module Jekyll
begin begin
converter.convert output converter.convert output
rescue => e rescue => e
Jekyll.logger.error "Conversion error:", "#{converter.class} encountered an error while converting '#{path}':" Jekyll.logger.error(
"Conversion error:",
"#{converter.class} encountered an error while converting '#{path}':"
)
Jekyll.logger.error("", e.to_s) Jekyll.logger.error("", e.to_s)
raise e raise e
end end
@ -112,12 +116,17 @@ module Jekyll
def render_liquid(content, payload, info, path) def render_liquid(content, payload, info, path)
site.liquid_renderer.file(path).parse(content).render!(payload, info) site.liquid_renderer.file(path).parse(content).render!(payload, info)
rescue Tags::IncludeTagError => e rescue Tags::IncludeTagError => e
Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{e.path}, included in #{path || self.path}" Jekyll.logger.error(
"Liquid Exception:",
"#{e.message} in #{e.path}, included in #{path || self.path}"
)
raise e raise e
# rubocop: disable RescueException
rescue Exception => e rescue Exception => e
Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{path || self.path}" Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{path || self.path}"
raise e raise e
end end
# rubocop: enable RescueException
# Convert this Convertible's data to a Hash suitable for use by Liquid. # Convert this Convertible's data to a Hash suitable for use by Liquid.
# #
@ -168,7 +177,7 @@ module Jekyll
# #
# Returns true if extname == .coffee, false otherwise. # Returns true if extname == .coffee, false otherwise.
def coffeescript_file? def coffeescript_file?
'.coffee'.eql?(ext) ".coffee" == ext
end end
# Determine whether the file should be rendered with Liquid. # Determine whether the file should be rendered with Liquid.
@ -205,7 +214,10 @@ module Jekyll
# recursively render layouts # recursively render layouts
layout = layouts[data["layout"]] layout = layouts[data["layout"]]
Jekyll.logger.warn("Build Warning:", "Layout '#{data["layout"]}' requested in #{path} does not exist.") if invalid_layout? layout Jekyll.logger.warn(
"Build Warning:",
"Layout '#{data["layout"]}' requested in #{path} does not exist."
) if invalid_layout? layout
used = Set.new([layout]) used = Set.new([layout])
@ -228,12 +240,9 @@ module Jekyll
site.in_source_dir(layout.path) site.in_source_dir(layout.path)
) )
if layout = layouts[layout.data["layout"]] if (layout = layouts[layout.data["layout"]])
if used.include?(layout) break if used.include?(layout)
layout = nil # avoid recursive chain used << layout
else
used << layout
end
end end
end end
end end
@ -249,7 +258,10 @@ module Jekyll
Jekyll.logger.debug "Pre-Render Hooks:", self.relative_path Jekyll.logger.debug "Pre-Render Hooks:", self.relative_path
Jekyll::Hooks.trigger hook_owner, :pre_render, self, payload Jekyll::Hooks.trigger hook_owner, :pre_render, self, payload
info = { :filters => [Jekyll::Filters], :registers => { :site => site, :page => payload["page"] } } info = {
:filters => [Jekyll::Filters],
:registers => { :site => site, :page => payload["page"] }
}
# render and transform content (this becomes the final content of the object) # render and transform content (this becomes the final content of the object)
payload["highlighter_prefix"] = converters.first.highlighter_prefix payload["highlighter_prefix"] = converters.first.highlighter_prefix
@ -278,9 +290,7 @@ module Jekyll
def write(dest) def write(dest)
path = destination(dest) path = destination(dest)
FileUtils.mkdir_p(File.dirname(path)) FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'wb') do |f| File.write(path, output, :mode => "wb")
f.write(output)
end
Jekyll::Hooks.trigger hook_owner, :post_write, self Jekyll::Hooks.trigger hook_owner, :post_write, self
end end