diff --git a/lib/jekyll/drops/document_drop.rb b/lib/jekyll/drops/document_drop.rb index 10e069ac..2600baa5 100644 --- a/lib/jekyll/drops/document_drop.rb +++ b/lib/jekyll/drops/document_drop.rb @@ -5,9 +5,9 @@ module Jekyll class DocumentDrop < Drop extend Forwardable - NESTED_OBJECT_FIELD_BLACKLIST = %w{ + NESTED_OBJECT_FIELD_BLACKLIST = %w( content output excerpt next previous - }.freeze + ).freeze mutable false @@ -40,6 +40,8 @@ module Jekyll # Generate a Hash for use in generating JSON. # This is useful if fields need to be cleared before the JSON can generate. # + # state - the JSON::State object which determines the state of current processing. + # # Returns a Hash ready for JSON generation. def hash_for_json(state = nil) to_h.tap do |hash| diff --git a/lib/jekyll/drops/drop.rb b/lib/jekyll/drops/drop.rb index dcabb190..ebd3b4d2 100644 --- a/lib/jekyll/drops/drop.rb +++ b/lib/jekyll/drops/drop.rb @@ -88,7 +88,9 @@ module Jekyll # Returns an Array of strings which represent method-specific keys. def content_methods @content_methods ||= ( - self.class.instance_methods - Jekyll::Drops::Drop.instance_methods - NON_CONTENT_METHODS + self.class.instance_methods \ + - Jekyll::Drops::Drop.instance_methods \ + - NON_CONTENT_METHODS ).map(&:to_s).reject do |method| method.end_with?("=") end @@ -144,15 +146,17 @@ module Jekyll # This is useful if fields need to be cleared before the JSON can generate. # # Returns a Hash ready for JSON generation. - def hash_for_json(state = nil) + def hash_for_json(*) to_h end # Generate a JSON representation of the Drop. # + # state - the JSON::State object which determines the state of current processing. + # # Returns a JSON representation of the Drop in a String. def to_json(state = nil) - require 'json' + require "json" JSON.generate(hash_for_json(state), state) end @@ -165,7 +169,7 @@ module Jekyll keys.each(&block) end - def each(&block) + def each each_key.each do |key| yield key, self[key] end diff --git a/lib/jekyll/drops/jekyll_drop.rb b/lib/jekyll/drops/jekyll_drop.rb index 7ff19f9a..50163d74 100644 --- a/lib/jekyll/drops/jekyll_drop.rb +++ b/lib/jekyll/drops/jekyll_drop.rb @@ -19,13 +19,13 @@ module Jekyll def to_h @to_h ||= { - "version" => version, + "version" => version, "environment" => environment } end def to_json(state = nil) - require 'json' + require "json" JSON.generate(to_h, state) end end