rubocop: fix code style
This commit is contained in:
		
							parent
							
								
									e97fd34479
								
							
						
					
					
						commit
						597e8ee5d5
					
				| 
						 | 
					@ -11,7 +11,6 @@ AllCops:
 | 
				
			||||||
  - lib/jekyll/deprecator.rb
 | 
					  - lib/jekyll/deprecator.rb
 | 
				
			||||||
  - lib/jekyll/document.rb
 | 
					  - lib/jekyll/document.rb
 | 
				
			||||||
  - lib/jekyll/filters.rb
 | 
					  - lib/jekyll/filters.rb
 | 
				
			||||||
  - lib/jekyll/frontmatter_defaults.rb
 | 
					 | 
				
			||||||
  - lib/jekyll/regenerator.rb
 | 
					  - lib/jekyll/regenerator.rb
 | 
				
			||||||
  - lib/jekyll/renderer.rb
 | 
					  - lib/jekyll/renderer.rb
 | 
				
			||||||
  - lib/jekyll/site.rb
 | 
					  - lib/jekyll/site.rb
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,37 +11,42 @@ module Jekyll
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def update_deprecated_types(set)
 | 
					    def update_deprecated_types(set)
 | 
				
			||||||
      return set unless set.key?('scope') && set['scope'].key?('type')
 | 
					      return set unless set.key?("scope") && set["scope"].key?("type")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      set['scope']['type'] =
 | 
					      set["scope"]["type"] =
 | 
				
			||||||
        case set['scope']['type']
 | 
					        case set["scope"]["type"]
 | 
				
			||||||
        when 'page'
 | 
					        when "page"
 | 
				
			||||||
          Deprecator.defaults_deprecate_type('page', 'pages')
 | 
					          Deprecator.defaults_deprecate_type("page", "pages")
 | 
				
			||||||
          'pages'
 | 
					          "pages"
 | 
				
			||||||
        when 'post'
 | 
					        when "post"
 | 
				
			||||||
          Deprecator.defaults_deprecate_type('post', 'posts')
 | 
					          Deprecator.defaults_deprecate_type("post", "posts")
 | 
				
			||||||
          'posts'
 | 
					          "posts"
 | 
				
			||||||
        when 'draft'
 | 
					        when "draft"
 | 
				
			||||||
          Deprecator.defaults_deprecate_type('draft', 'drafts')
 | 
					          Deprecator.defaults_deprecate_type("draft", "drafts")
 | 
				
			||||||
          'drafts'
 | 
					          "drafts"
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
          set['scope']['type']
 | 
					          set["scope"]["type"]
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      set
 | 
					      set
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def ensure_time!(set)
 | 
					    def ensure_time!(set)
 | 
				
			||||||
      return set unless set.key?('values') && set['values'].key?('date')
 | 
					      return set unless set.key?("values") && set["values"].key?("date")
 | 
				
			||||||
      return set if set['values']['date'].is_a?(Time)
 | 
					      return set if set["values"]["date"].is_a?(Time)
 | 
				
			||||||
      set['values']['date'] = Utils.parse_date(set['values']['date'], "An invalid date format was found in a front-matter default set: #{set}")
 | 
					      set["values"]["date"] = Utils.parse_date(
 | 
				
			||||||
 | 
					        set["values"]["date"],
 | 
				
			||||||
 | 
					        "An invalid date format was found in a front-matter default set: #{set}"
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
      set
 | 
					      set
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Finds a default value for a given setting, filtered by path and type
 | 
					    # Finds a default value for a given setting, filtered by path and type
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # path - the path (relative to the source) of the page, post or :draft the default is used in
 | 
					    # path - the path (relative to the source) of the page,
 | 
				
			||||||
    # type - a symbol indicating whether a :page, a :post or a :draft calls this method
 | 
					    # post or :draft the default is used in
 | 
				
			||||||
 | 
					    # type - a symbol indicating whether a :page,
 | 
				
			||||||
 | 
					    # a :post or a :draft calls this method
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns the default value or nil if none was found
 | 
					    # Returns the default value or nil if none was found
 | 
				
			||||||
    def find(path, type, setting)
 | 
					    def find(path, type, setting)
 | 
				
			||||||
| 
						 | 
					@ -49,9 +54,9 @@ module Jekyll
 | 
				
			||||||
      old_scope = nil
 | 
					      old_scope = nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      matching_sets(path, type).each do |set|
 | 
					      matching_sets(path, type).each do |set|
 | 
				
			||||||
        if set['values'].key?(setting) && has_precedence?(old_scope, set['scope'])
 | 
					        if set["values"].key?(setting) && precedence?(old_scope, set["scope"])
 | 
				
			||||||
          value = set['values'][setting]
 | 
					          value = set["values"][setting]
 | 
				
			||||||
          old_scope = set['scope']
 | 
					          old_scope = set["scope"]
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
      value
 | 
					      value
 | 
				
			||||||
| 
						 | 
					@ -67,11 +72,11 @@ module Jekyll
 | 
				
			||||||
      defaults = {}
 | 
					      defaults = {}
 | 
				
			||||||
      old_scope = nil
 | 
					      old_scope = nil
 | 
				
			||||||
      matching_sets(path, type).each do |set|
 | 
					      matching_sets(path, type).each do |set|
 | 
				
			||||||
        if has_precedence?(old_scope, set['scope'])
 | 
					        if precedence?(old_scope, set["scope"])
 | 
				
			||||||
          defaults = Utils.deep_merge_hashes(defaults, set['values'])
 | 
					          defaults = Utils.deep_merge_hashes(defaults, set["values"])
 | 
				
			||||||
          old_scope = set['scope']
 | 
					          old_scope = set["scope"]
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
          defaults = Utils.deep_merge_hashes(set['values'], defaults)
 | 
					          defaults = Utils.deep_merge_hashes(set["values"], defaults)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
      defaults
 | 
					      defaults
 | 
				
			||||||
| 
						 | 
					@ -91,9 +96,9 @@ module Jekyll
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def applies_path?(scope, path)
 | 
					    def applies_path?(scope, path)
 | 
				
			||||||
      return true if !scope.key?('path') || scope['path'].empty?
 | 
					      return true if !scope.key?("path") || scope["path"].empty?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      scope_path = Pathname.new(scope['path'])
 | 
					      scope_path = Pathname.new(scope["path"])
 | 
				
			||||||
      Pathname.new(sanitize_path(path)).ascend do |ascended_path|
 | 
					      Pathname.new(sanitize_path(path)).ascend do |ascended_path|
 | 
				
			||||||
        if ascended_path.to_s == scope_path.to_s
 | 
					        if ascended_path.to_s == scope_path.to_s
 | 
				
			||||||
          return true
 | 
					          return true
 | 
				
			||||||
| 
						 | 
					@ -113,7 +118,7 @@ module Jekyll
 | 
				
			||||||
    # Returns true if either of the above conditions are satisfied,
 | 
					    # Returns true if either of the above conditions are satisfied,
 | 
				
			||||||
    #   otherwise returns false
 | 
					    #   otherwise returns false
 | 
				
			||||||
    def applies_type?(scope, type)
 | 
					    def applies_type?(scope, type)
 | 
				
			||||||
      !scope.key?('type') || scope['type'].eql?(type.to_s)
 | 
					      !scope.key?("type") || scope["type"].eql?(type.to_s)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Checks if a given set of default values is valid
 | 
					    # Checks if a given set of default values is valid
 | 
				
			||||||
| 
						 | 
					@ -122,7 +127,7 @@ module Jekyll
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns true if the set is valid and can be used in this class
 | 
					    # Returns true if the set is valid and can be used in this class
 | 
				
			||||||
    def valid?(set)
 | 
					    def valid?(set)
 | 
				
			||||||
      set.is_a?(Hash) && set['values'].is_a?(Hash)
 | 
					      set.is_a?(Hash) && set["values"].is_a?(Hash)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Determines if a new scope has precedence over an old one
 | 
					    # Determines if a new scope has precedence over an old one
 | 
				
			||||||
| 
						 | 
					@ -131,18 +136,18 @@ module Jekyll
 | 
				
			||||||
    # new_scope - the new scope hash
 | 
					    # new_scope - the new scope hash
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns true if the new scope has precedence over the older
 | 
					    # Returns true if the new scope has precedence over the older
 | 
				
			||||||
    def has_precedence?(old_scope, new_scope)
 | 
					    def precedence?(old_scope, new_scope)
 | 
				
			||||||
      return true if old_scope.nil?
 | 
					      return true if old_scope.nil?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      new_path = sanitize_path(new_scope['path'])
 | 
					      new_path = sanitize_path(new_scope["path"])
 | 
				
			||||||
      old_path = sanitize_path(old_scope['path'])
 | 
					      old_path = sanitize_path(old_scope["path"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if new_path.length != old_path.length
 | 
					      if new_path.length != old_path.length
 | 
				
			||||||
        new_path.length >= old_path.length
 | 
					        new_path.length >= old_path.length
 | 
				
			||||||
      elsif new_scope.key? 'type'
 | 
					      elsif new_scope.key? "type"
 | 
				
			||||||
        true
 | 
					        true
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
        !old_scope.key? 'type'
 | 
					        !old_scope.key? "type"
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -151,7 +156,7 @@ module Jekyll
 | 
				
			||||||
    # Returns an array of hashes
 | 
					    # Returns an array of hashes
 | 
				
			||||||
    def matching_sets(path, type)
 | 
					    def matching_sets(path, type)
 | 
				
			||||||
      valid_sets.select do |set|
 | 
					      valid_sets.select do |set|
 | 
				
			||||||
        !set.key?('scope') || applies?(set['scope'], path, type)
 | 
					        !set.key?("scope") || applies?(set["scope"], path, type)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -162,7 +167,7 @@ module Jekyll
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns an array of hashes
 | 
					    # Returns an array of hashes
 | 
				
			||||||
    def valid_sets
 | 
					    def valid_sets
 | 
				
			||||||
      sets = @site.config['defaults']
 | 
					      sets = @site.config["defaults"]
 | 
				
			||||||
      return [] unless sets.is_a?(Array)
 | 
					      return [] unless sets.is_a?(Array)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      sets.map do |set|
 | 
					      sets.map do |set|
 | 
				
			||||||
| 
						 | 
					@ -170,7 +175,7 @@ module Jekyll
 | 
				
			||||||
          ensure_time!(update_deprecated_types(set))
 | 
					          ensure_time!(update_deprecated_types(set))
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
          Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:"
 | 
					          Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:"
 | 
				
			||||||
          Jekyll.logger.warn "#{set}"
 | 
					          Jekyll.logger.warn set.to_s
 | 
				
			||||||
          nil
 | 
					          nil
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end.compact
 | 
					      end.compact
 | 
				
			||||||
| 
						 | 
					@ -181,7 +186,7 @@ module Jekyll
 | 
				
			||||||
      if path.nil? || path.empty?
 | 
					      if path.nil? || path.empty?
 | 
				
			||||||
        ""
 | 
					        ""
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
        path.gsub(/\A\//, '').gsub(/([^\/])\z/, '\1')
 | 
					        path.gsub(%r!\A/!, "").gsub(%r!([^/])\z!, '\1')
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue