jekyll 4.2.1 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +350 -350
  3. data/LICENSE +21 -21
  4. data/README.markdown +86 -86
  5. data/exe/jekyll +57 -57
  6. data/lib/blank_template/_config.yml +3 -3
  7. data/lib/blank_template/_layouts/default.html +12 -12
  8. data/lib/blank_template/_sass/main.scss +9 -9
  9. data/lib/blank_template/assets/css/main.scss +4 -4
  10. data/lib/blank_template/index.md +8 -8
  11. data/lib/jekyll/cache.rb +190 -190
  12. data/lib/jekyll/cleaner.rb +111 -111
  13. data/lib/jekyll/collection.rb +309 -309
  14. data/lib/jekyll/command.rb +105 -105
  15. data/lib/jekyll/commands/build.rb +93 -93
  16. data/lib/jekyll/commands/clean.rb +45 -45
  17. data/lib/jekyll/commands/doctor.rb +177 -177
  18. data/lib/jekyll/commands/help.rb +34 -34
  19. data/lib/jekyll/commands/new.rb +172 -169
  20. data/lib/jekyll/commands/new_theme.rb +40 -40
  21. data/lib/jekyll/commands/serve/live_reload_reactor.rb +122 -122
  22. data/lib/jekyll/commands/serve/livereload_assets/livereload.js +1183 -1183
  23. data/lib/jekyll/commands/serve/servlet.rb +202 -202
  24. data/lib/jekyll/commands/serve/websockets.rb +81 -81
  25. data/lib/jekyll/commands/serve.rb +362 -362
  26. data/lib/jekyll/configuration.rb +313 -313
  27. data/lib/jekyll/converter.rb +54 -54
  28. data/lib/jekyll/converters/identity.rb +41 -41
  29. data/lib/jekyll/converters/markdown/kramdown_parser.rb +199 -199
  30. data/lib/jekyll/converters/markdown.rb +113 -113
  31. data/lib/jekyll/converters/smartypants.rb +70 -70
  32. data/lib/jekyll/convertible.rb +257 -257
  33. data/lib/jekyll/deprecator.rb +50 -50
  34. data/lib/jekyll/document.rb +544 -544
  35. data/lib/jekyll/drops/collection_drop.rb +20 -20
  36. data/lib/jekyll/drops/document_drop.rb +70 -70
  37. data/lib/jekyll/drops/drop.rb +293 -293
  38. data/lib/jekyll/drops/excerpt_drop.rb +19 -19
  39. data/lib/jekyll/drops/jekyll_drop.rb +32 -32
  40. data/lib/jekyll/drops/site_drop.rb +66 -66
  41. data/lib/jekyll/drops/static_file_drop.rb +14 -14
  42. data/lib/jekyll/drops/unified_payload_drop.rb +26 -26
  43. data/lib/jekyll/drops/url_drop.rb +140 -140
  44. data/lib/jekyll/entry_filter.rb +121 -121
  45. data/lib/jekyll/errors.rb +20 -20
  46. data/lib/jekyll/excerpt.rb +201 -201
  47. data/lib/jekyll/external.rb +79 -79
  48. data/lib/jekyll/filters/date_filters.rb +110 -110
  49. data/lib/jekyll/filters/grouping_filters.rb +64 -64
  50. data/lib/jekyll/filters/url_filters.rb +98 -98
  51. data/lib/jekyll/filters.rb +535 -535
  52. data/lib/jekyll/frontmatter_defaults.rb +240 -240
  53. data/lib/jekyll/generator.rb +5 -5
  54. data/lib/jekyll/hooks.rb +107 -107
  55. data/lib/jekyll/inclusion.rb +32 -32
  56. data/lib/jekyll/layout.rb +67 -67
  57. data/lib/jekyll/liquid_extensions.rb +22 -22
  58. data/lib/jekyll/liquid_renderer/file.rb +77 -77
  59. data/lib/jekyll/liquid_renderer/table.rb +55 -55
  60. data/lib/jekyll/liquid_renderer.rb +80 -80
  61. data/lib/jekyll/log_adapter.rb +151 -151
  62. data/lib/jekyll/mime.types +866 -866
  63. data/lib/jekyll/page.rb +217 -217
  64. data/lib/jekyll/page_excerpt.rb +25 -25
  65. data/lib/jekyll/page_without_a_file.rb +14 -14
  66. data/lib/jekyll/path_manager.rb +74 -74
  67. data/lib/jekyll/plugin.rb +92 -92
  68. data/lib/jekyll/plugin_manager.rb +115 -115
  69. data/lib/jekyll/profiler.rb +58 -58
  70. data/lib/jekyll/publisher.rb +23 -23
  71. data/lib/jekyll/reader.rb +192 -192
  72. data/lib/jekyll/readers/collection_reader.rb +23 -23
  73. data/lib/jekyll/readers/data_reader.rb +79 -79
  74. data/lib/jekyll/readers/layout_reader.rb +62 -62
  75. data/lib/jekyll/readers/page_reader.rb +25 -25
  76. data/lib/jekyll/readers/post_reader.rb +85 -85
  77. data/lib/jekyll/readers/static_file_reader.rb +25 -25
  78. data/lib/jekyll/readers/theme_assets_reader.rb +52 -52
  79. data/lib/jekyll/regenerator.rb +195 -195
  80. data/lib/jekyll/related_posts.rb +52 -52
  81. data/lib/jekyll/renderer.rb +265 -265
  82. data/lib/jekyll/site.rb +551 -551
  83. data/lib/jekyll/static_file.rb +208 -208
  84. data/lib/jekyll/stevenson.rb +60 -60
  85. data/lib/jekyll/tags/highlight.rb +110 -110
  86. data/lib/jekyll/tags/include.rb +275 -275
  87. data/lib/jekyll/tags/link.rb +42 -42
  88. data/lib/jekyll/tags/post_url.rb +106 -106
  89. data/lib/jekyll/theme.rb +86 -86
  90. data/lib/jekyll/theme_builder.rb +121 -121
  91. data/lib/jekyll/url.rb +167 -167
  92. data/lib/jekyll/utils/ansi.rb +57 -57
  93. data/lib/jekyll/utils/exec.rb +26 -26
  94. data/lib/jekyll/utils/internet.rb +37 -37
  95. data/lib/jekyll/utils/platforms.rb +67 -67
  96. data/lib/jekyll/utils/thread_event.rb +31 -31
  97. data/lib/jekyll/utils/win_tz.rb +75 -75
  98. data/lib/jekyll/utils.rb +367 -367
  99. data/lib/jekyll/version.rb +5 -5
  100. data/lib/jekyll.rb +195 -195
  101. data/lib/site_template/.gitignore +5 -5
  102. data/lib/site_template/404.html +25 -25
  103. data/lib/site_template/_config.yml +55 -55
  104. data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +29 -29
  105. data/lib/site_template/about.markdown +18 -18
  106. data/lib/site_template/index.markdown +6 -6
  107. data/lib/theme_template/CODE_OF_CONDUCT.md.erb +74 -74
  108. data/lib/theme_template/Gemfile +4 -4
  109. data/lib/theme_template/LICENSE.txt.erb +21 -21
  110. data/lib/theme_template/README.md.erb +52 -52
  111. data/lib/theme_template/_layouts/default.html +1 -1
  112. data/lib/theme_template/_layouts/page.html +5 -5
  113. data/lib/theme_template/_layouts/post.html +5 -5
  114. data/lib/theme_template/example/_config.yml.erb +1 -1
  115. data/lib/theme_template/example/_post.md +12 -12
  116. data/lib/theme_template/example/index.html +14 -14
  117. data/lib/theme_template/example/style.scss +7 -7
  118. data/lib/theme_template/gitignore.erb +6 -6
  119. data/lib/theme_template/theme.gemspec.erb +16 -16
  120. data/rubocop/jekyll/assert_equal_literal_actual.rb +149 -149
  121. data/rubocop/jekyll/no_p_allowed.rb +23 -23
  122. data/rubocop/jekyll/no_puts_allowed.rb +23 -23
  123. data/rubocop/jekyll.rb +5 -5
  124. metadata +3 -3
@@ -1,293 +1,293 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Drops
5
- class Drop < Liquid::Drop
6
- include Enumerable
7
-
8
- NON_CONTENT_METHODS = [:fallback_data, :collapse_document].freeze
9
- NON_CONTENT_METHOD_NAMES = NON_CONTENT_METHODS.map(&:to_s).freeze
10
- private_constant :NON_CONTENT_METHOD_NAMES
11
-
12
- # A private stash to avoid repeatedly generating the setter method name string for
13
- # a call to `Drops::Drop#[]=`.
14
- # The keys of the stash below have a very high probability of being called upon during
15
- # the course of various `Jekyll::Renderer#run` calls.
16
- SETTER_KEYS_STASH = {
17
- "content" => "content=",
18
- "layout" => "layout=",
19
- "page" => "page=",
20
- "paginator" => "paginator=",
21
- "highlighter_prefix" => "highlighter_prefix=",
22
- "highlighter_suffix" => "highlighter_suffix=",
23
- }.freeze
24
- private_constant :SETTER_KEYS_STASH
25
-
26
- class << self
27
- # Get or set whether the drop class is mutable.
28
- # Mutability determines whether or not pre-defined fields may be
29
- # overwritten.
30
- #
31
- # is_mutable - Boolean set mutability of the class (default: nil)
32
- #
33
- # Returns the mutability of the class
34
- def mutable(is_mutable = nil)
35
- @is_mutable = is_mutable || false
36
- end
37
-
38
- def mutable?
39
- @is_mutable
40
- end
41
-
42
- # public delegation helper methods that calls onto Drop's instance
43
- # variable `@obj`.
44
-
45
- # Generate private Drop instance_methods for each symbol in the given list.
46
- #
47
- # Returns nothing.
48
- def private_delegate_methods(*symbols)
49
- symbols.each { |symbol| private delegate_method(symbol) }
50
- nil
51
- end
52
-
53
- # Generate public Drop instance_methods for each symbol in the given list.
54
- #
55
- # Returns nothing.
56
- def delegate_methods(*symbols)
57
- symbols.each { |symbol| delegate_method(symbol) }
58
- nil
59
- end
60
-
61
- # Generate public Drop instance_method for given symbol that calls `@obj.<sym>`.
62
- #
63
- # Returns delegated method symbol.
64
- def delegate_method(symbol)
65
- define_method(symbol) { @obj.send(symbol) }
66
- end
67
-
68
- # Generate public Drop instance_method named `delegate` that calls `@obj.<original>`.
69
- #
70
- # Returns delegated method symbol.
71
- def delegate_method_as(original, delegate)
72
- define_method(delegate) { @obj.send(original) }
73
- end
74
-
75
- # Generate public Drop instance_methods for each string entry in the given list.
76
- # The generated method(s) access(es) `@obj`'s data hash.
77
- #
78
- # Returns nothing.
79
- def data_delegators(*strings)
80
- strings.each do |key|
81
- data_delegator(key) if key.is_a?(String)
82
- end
83
- nil
84
- end
85
-
86
- # Generate public Drop instance_methods for given string `key`.
87
- # The generated method access(es) `@obj`'s data hash.
88
- #
89
- # Returns method symbol.
90
- def data_delegator(key)
91
- define_method(key.to_sym) { @obj.data[key] }
92
- end
93
-
94
- # Array of stringified instance methods that do not end with the assignment operator.
95
- #
96
- # (<klass>.instance_methods always generates a new Array object so it can be mutated)
97
- #
98
- # Returns array of strings.
99
- def getter_method_names
100
- @getter_method_names ||= instance_methods.map!(&:to_s).tap do |list|
101
- list.reject! { |item| item.end_with?("=") }
102
- end
103
- end
104
- end
105
-
106
- # Create a new Drop
107
- #
108
- # obj - the Jekyll Site, Collection, or Document required by the
109
- # drop.
110
- #
111
- # Returns nothing
112
- def initialize(obj)
113
- @obj = obj
114
- end
115
-
116
- # Access a method in the Drop or a field in the underlying hash data.
117
- # If mutable, checks the mutations first. Then checks the methods,
118
- # and finally check the underlying hash (e.g. document front matter)
119
- # if all the previous places didn't match.
120
- #
121
- # key - the string key whose value to fetch
122
- #
123
- # Returns the value for the given key, or nil if none exists
124
- def [](key)
125
- if self.class.mutable? && mutations.key?(key)
126
- mutations[key]
127
- elsif self.class.invokable? key
128
- public_send key
129
- else
130
- fallback_data[key]
131
- end
132
- end
133
- alias_method :invoke_drop, :[]
134
-
135
- # Set a field in the Drop. If mutable, sets in the mutations and
136
- # returns. If not mutable, checks first if it's trying to override a
137
- # Drop method and raises a DropMutationException if so. If not
138
- # mutable and the key is not a method on the Drop, then it sets the
139
- # key to the value in the underlying hash (e.g. document front
140
- # matter)
141
- #
142
- # key - the String key whose value to set
143
- # val - the Object to set the key's value to
144
- #
145
- # Returns the value the key was set to unless the Drop is not mutable
146
- # and the key matches a method in which case it raises a
147
- # DropMutationException.
148
- def []=(key, val)
149
- setter = SETTER_KEYS_STASH[key] || "#{key}="
150
- if respond_to?(setter)
151
- public_send(setter, val)
152
- elsif respond_to?(key.to_s)
153
- if self.class.mutable?
154
- mutations[key] = val
155
- else
156
- raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."
157
- end
158
- else
159
- fallback_data[key] = val
160
- end
161
- end
162
-
163
- # Generates a list of strings which correspond to content getter
164
- # methods.
165
- #
166
- # Returns an Array of strings which represent method-specific keys.
167
- def content_methods
168
- @content_methods ||= \
169
- self.class.getter_method_names \
170
- - Jekyll::Drops::Drop.getter_method_names \
171
- - NON_CONTENT_METHOD_NAMES
172
- end
173
-
174
- # Check if key exists in Drop
175
- #
176
- # key - the string key whose value to fetch
177
- #
178
- # Returns true if the given key is present
179
- def key?(key)
180
- return false if key.nil?
181
- return true if self.class.mutable? && mutations.key?(key)
182
-
183
- respond_to?(key) || fallback_data.key?(key)
184
- end
185
-
186
- # Generates a list of keys with user content as their values.
187
- # This gathers up the Drop methods and keys of the mutations and
188
- # underlying data hashes and performs a set union to ensure a list
189
- # of unique keys for the Drop.
190
- #
191
- # Returns an Array of unique keys for content for the Drop.
192
- def keys
193
- (content_methods |
194
- mutations.keys |
195
- fallback_data.keys).flatten
196
- end
197
-
198
- # Generate a Hash representation of the Drop by resolving each key's
199
- # value. It includes Drop methods, mutations, and the underlying object's
200
- # data. See the documentation for Drop#keys for more.
201
- #
202
- # Returns a Hash with all the keys and values resolved.
203
- def to_h
204
- keys.each_with_object({}) do |(key, _), result|
205
- result[key] = self[key]
206
- end
207
- end
208
- alias_method :to_hash, :to_h
209
-
210
- # Inspect the drop's keys and values through a JSON representation
211
- # of its keys and values.
212
- #
213
- # Returns a pretty generation of the hash representation of the Drop.
214
- def inspect
215
- JSON.pretty_generate to_h
216
- end
217
-
218
- # Generate a Hash for use in generating JSON.
219
- # This is useful if fields need to be cleared before the JSON can generate.
220
- #
221
- # Returns a Hash ready for JSON generation.
222
- def hash_for_json(*)
223
- to_h
224
- end
225
-
226
- # Generate a JSON representation of the Drop.
227
- #
228
- # state - the JSON::State object which determines the state of current processing.
229
- #
230
- # Returns a JSON representation of the Drop in a String.
231
- def to_json(state = nil)
232
- JSON.generate(hash_for_json(state), state)
233
- end
234
-
235
- # Collects all the keys and passes each to the block in turn.
236
- #
237
- # block - a block which accepts one argument, the key
238
- #
239
- # Returns nothing.
240
- def each_key(&block)
241
- keys.each(&block)
242
- end
243
-
244
- def each
245
- each_key.each do |key|
246
- yield key, self[key]
247
- end
248
- end
249
-
250
- def merge(other, &block)
251
- dup.tap do |me|
252
- if block.nil?
253
- me.merge!(other)
254
- else
255
- me.merge!(other, block)
256
- end
257
- end
258
- end
259
-
260
- def merge!(other)
261
- other.each_key do |key|
262
- if block_given?
263
- self[key] = yield key, self[key], other[key]
264
- else
265
- if Utils.mergable?(self[key]) && Utils.mergable?(other[key])
266
- self[key] = Utils.deep_merge_hashes(self[key], other[key])
267
- next
268
- end
269
-
270
- self[key] = other[key] unless other[key].nil?
271
- end
272
- end
273
- end
274
-
275
- # Imitate Hash.fetch method in Drop
276
- #
277
- # Returns value if key is present in Drop, otherwise returns default value
278
- # KeyError is raised if key is not present and no default value given
279
- def fetch(key, default = nil, &block)
280
- return self[key] if key?(key)
281
- raise KeyError, %(key not found: "#{key}") if default.nil? && block.nil?
282
- return yield(key) unless block.nil?
283
- return default unless default.nil?
284
- end
285
-
286
- private
287
-
288
- def mutations
289
- @mutations ||= {}
290
- end
291
- end
292
- end
293
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Drops
5
+ class Drop < Liquid::Drop
6
+ include Enumerable
7
+
8
+ NON_CONTENT_METHODS = [:fallback_data, :collapse_document].freeze
9
+ NON_CONTENT_METHOD_NAMES = NON_CONTENT_METHODS.map(&:to_s).freeze
10
+ private_constant :NON_CONTENT_METHOD_NAMES
11
+
12
+ # A private stash to avoid repeatedly generating the setter method name string for
13
+ # a call to `Drops::Drop#[]=`.
14
+ # The keys of the stash below have a very high probability of being called upon during
15
+ # the course of various `Jekyll::Renderer#run` calls.
16
+ SETTER_KEYS_STASH = {
17
+ "content" => "content=",
18
+ "layout" => "layout=",
19
+ "page" => "page=",
20
+ "paginator" => "paginator=",
21
+ "highlighter_prefix" => "highlighter_prefix=",
22
+ "highlighter_suffix" => "highlighter_suffix=",
23
+ }.freeze
24
+ private_constant :SETTER_KEYS_STASH
25
+
26
+ class << self
27
+ # Get or set whether the drop class is mutable.
28
+ # Mutability determines whether or not pre-defined fields may be
29
+ # overwritten.
30
+ #
31
+ # is_mutable - Boolean set mutability of the class (default: nil)
32
+ #
33
+ # Returns the mutability of the class
34
+ def mutable(is_mutable = nil)
35
+ @is_mutable = is_mutable || false
36
+ end
37
+
38
+ def mutable?
39
+ @is_mutable
40
+ end
41
+
42
+ # public delegation helper methods that calls onto Drop's instance
43
+ # variable `@obj`.
44
+
45
+ # Generate private Drop instance_methods for each symbol in the given list.
46
+ #
47
+ # Returns nothing.
48
+ def private_delegate_methods(*symbols)
49
+ symbols.each { |symbol| private delegate_method(symbol) }
50
+ nil
51
+ end
52
+
53
+ # Generate public Drop instance_methods for each symbol in the given list.
54
+ #
55
+ # Returns nothing.
56
+ def delegate_methods(*symbols)
57
+ symbols.each { |symbol| delegate_method(symbol) }
58
+ nil
59
+ end
60
+
61
+ # Generate public Drop instance_method for given symbol that calls `@obj.<sym>`.
62
+ #
63
+ # Returns delegated method symbol.
64
+ def delegate_method(symbol)
65
+ define_method(symbol) { @obj.send(symbol) }
66
+ end
67
+
68
+ # Generate public Drop instance_method named `delegate` that calls `@obj.<original>`.
69
+ #
70
+ # Returns delegated method symbol.
71
+ def delegate_method_as(original, delegate)
72
+ define_method(delegate) { @obj.send(original) }
73
+ end
74
+
75
+ # Generate public Drop instance_methods for each string entry in the given list.
76
+ # The generated method(s) access(es) `@obj`'s data hash.
77
+ #
78
+ # Returns nothing.
79
+ def data_delegators(*strings)
80
+ strings.each do |key|
81
+ data_delegator(key) if key.is_a?(String)
82
+ end
83
+ nil
84
+ end
85
+
86
+ # Generate public Drop instance_methods for given string `key`.
87
+ # The generated method access(es) `@obj`'s data hash.
88
+ #
89
+ # Returns method symbol.
90
+ def data_delegator(key)
91
+ define_method(key.to_sym) { @obj.data[key] }
92
+ end
93
+
94
+ # Array of stringified instance methods that do not end with the assignment operator.
95
+ #
96
+ # (<klass>.instance_methods always generates a new Array object so it can be mutated)
97
+ #
98
+ # Returns array of strings.
99
+ def getter_method_names
100
+ @getter_method_names ||= instance_methods.map!(&:to_s).tap do |list|
101
+ list.reject! { |item| item.end_with?("=") }
102
+ end
103
+ end
104
+ end
105
+
106
+ # Create a new Drop
107
+ #
108
+ # obj - the Jekyll Site, Collection, or Document required by the
109
+ # drop.
110
+ #
111
+ # Returns nothing
112
+ def initialize(obj)
113
+ @obj = obj
114
+ end
115
+
116
+ # Access a method in the Drop or a field in the underlying hash data.
117
+ # If mutable, checks the mutations first. Then checks the methods,
118
+ # and finally check the underlying hash (e.g. document front matter)
119
+ # if all the previous places didn't match.
120
+ #
121
+ # key - the string key whose value to fetch
122
+ #
123
+ # Returns the value for the given key, or nil if none exists
124
+ def [](key)
125
+ if self.class.mutable? && mutations.key?(key)
126
+ mutations[key]
127
+ elsif self.class.invokable? key
128
+ public_send key
129
+ else
130
+ fallback_data[key]
131
+ end
132
+ end
133
+ alias_method :invoke_drop, :[]
134
+
135
+ # Set a field in the Drop. If mutable, sets in the mutations and
136
+ # returns. If not mutable, checks first if it's trying to override a
137
+ # Drop method and raises a DropMutationException if so. If not
138
+ # mutable and the key is not a method on the Drop, then it sets the
139
+ # key to the value in the underlying hash (e.g. document front
140
+ # matter)
141
+ #
142
+ # key - the String key whose value to set
143
+ # val - the Object to set the key's value to
144
+ #
145
+ # Returns the value the key was set to unless the Drop is not mutable
146
+ # and the key matches a method in which case it raises a
147
+ # DropMutationException.
148
+ def []=(key, val)
149
+ setter = SETTER_KEYS_STASH[key] || "#{key}="
150
+ if respond_to?(setter)
151
+ public_send(setter, val)
152
+ elsif respond_to?(key.to_s)
153
+ if self.class.mutable?
154
+ mutations[key] = val
155
+ else
156
+ raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."
157
+ end
158
+ else
159
+ fallback_data[key] = val
160
+ end
161
+ end
162
+
163
+ # Generates a list of strings which correspond to content getter
164
+ # methods.
165
+ #
166
+ # Returns an Array of strings which represent method-specific keys.
167
+ def content_methods
168
+ @content_methods ||= \
169
+ self.class.getter_method_names \
170
+ - Jekyll::Drops::Drop.getter_method_names \
171
+ - NON_CONTENT_METHOD_NAMES
172
+ end
173
+
174
+ # Check if key exists in Drop
175
+ #
176
+ # key - the string key whose value to fetch
177
+ #
178
+ # Returns true if the given key is present
179
+ def key?(key)
180
+ return false if key.nil?
181
+ return true if self.class.mutable? && mutations.key?(key)
182
+
183
+ respond_to?(key) || fallback_data.key?(key)
184
+ end
185
+
186
+ # Generates a list of keys with user content as their values.
187
+ # This gathers up the Drop methods and keys of the mutations and
188
+ # underlying data hashes and performs a set union to ensure a list
189
+ # of unique keys for the Drop.
190
+ #
191
+ # Returns an Array of unique keys for content for the Drop.
192
+ def keys
193
+ (content_methods |
194
+ mutations.keys |
195
+ fallback_data.keys).flatten
196
+ end
197
+
198
+ # Generate a Hash representation of the Drop by resolving each key's
199
+ # value. It includes Drop methods, mutations, and the underlying object's
200
+ # data. See the documentation for Drop#keys for more.
201
+ #
202
+ # Returns a Hash with all the keys and values resolved.
203
+ def to_h
204
+ keys.each_with_object({}) do |(key, _), result|
205
+ result[key] = self[key]
206
+ end
207
+ end
208
+ alias_method :to_hash, :to_h
209
+
210
+ # Inspect the drop's keys and values through a JSON representation
211
+ # of its keys and values.
212
+ #
213
+ # Returns a pretty generation of the hash representation of the Drop.
214
+ def inspect
215
+ JSON.pretty_generate to_h
216
+ end
217
+
218
+ # Generate a Hash for use in generating JSON.
219
+ # This is useful if fields need to be cleared before the JSON can generate.
220
+ #
221
+ # Returns a Hash ready for JSON generation.
222
+ def hash_for_json(*)
223
+ to_h
224
+ end
225
+
226
+ # Generate a JSON representation of the Drop.
227
+ #
228
+ # state - the JSON::State object which determines the state of current processing.
229
+ #
230
+ # Returns a JSON representation of the Drop in a String.
231
+ def to_json(state = nil)
232
+ JSON.generate(hash_for_json(state), state)
233
+ end
234
+
235
+ # Collects all the keys and passes each to the block in turn.
236
+ #
237
+ # block - a block which accepts one argument, the key
238
+ #
239
+ # Returns nothing.
240
+ def each_key(&block)
241
+ keys.each(&block)
242
+ end
243
+
244
+ def each
245
+ each_key.each do |key|
246
+ yield key, self[key]
247
+ end
248
+ end
249
+
250
+ def merge(other, &block)
251
+ dup.tap do |me|
252
+ if block.nil?
253
+ me.merge!(other)
254
+ else
255
+ me.merge!(other, block)
256
+ end
257
+ end
258
+ end
259
+
260
+ def merge!(other)
261
+ other.each_key do |key|
262
+ if block_given?
263
+ self[key] = yield key, self[key], other[key]
264
+ else
265
+ if Utils.mergable?(self[key]) && Utils.mergable?(other[key])
266
+ self[key] = Utils.deep_merge_hashes(self[key], other[key])
267
+ next
268
+ end
269
+
270
+ self[key] = other[key] unless other[key].nil?
271
+ end
272
+ end
273
+ end
274
+
275
+ # Imitate Hash.fetch method in Drop
276
+ #
277
+ # Returns value if key is present in Drop, otherwise returns default value
278
+ # KeyError is raised if key is not present and no default value given
279
+ def fetch(key, default = nil, &block)
280
+ return self[key] if key?(key)
281
+ raise KeyError, %(key not found: "#{key}") if default.nil? && block.nil?
282
+ return yield(key) unless block.nil?
283
+ return default unless default.nil?
284
+ end
285
+
286
+ private
287
+
288
+ def mutations
289
+ @mutations ||= {}
290
+ end
291
+ end
292
+ end
293
+ end
@@ -1,19 +1,19 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Drops
5
- class ExcerptDrop < DocumentDrop
6
- def layout
7
- @obj.doc.data["layout"]
8
- end
9
-
10
- def date
11
- @obj.doc.date
12
- end
13
-
14
- def excerpt
15
- nil
16
- end
17
- end
18
- end
19
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Drops
5
+ class ExcerptDrop < DocumentDrop
6
+ def layout
7
+ @obj.doc.data["layout"]
8
+ end
9
+
10
+ def date
11
+ @obj.doc.date
12
+ end
13
+
14
+ def excerpt
15
+ nil
16
+ end
17
+ end
18
+ end
19
+ end