octopress-hooks 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd69c98bc8337275d5b72a08567470fd2ca44ec2
4
- data.tar.gz: 5feead0c6d8d1e7be2fbef7e05146bf9e66936e6
3
+ metadata.gz: b5489d93d6480735a17b982c3cbe72eaa2ac0158
4
+ data.tar.gz: 4d845ad77101c20506aa6d0f73a1ce70910d1046
5
5
  SHA512:
6
- metadata.gz: 46edce7df9ba106fd554da4da903ce0e876f3badb6eee0477775dfa17fda127c0c2d8499d36920ea9e3665dc76569be9dc9ad7341d86d1a2a8ff30d105711cdf
7
- data.tar.gz: 768660aec8ebb54a39df0d0ad9fd60ed2c088c9ea0652e922e39be2d37905690fc5215603a06ad8b1f02b47883a8e8f0b7c6eba1b40f6ff0ba6c127461ef0f1d
6
+ metadata.gz: 4b1e7f334b3976066a6050c289d4c3495bac4c7e2d28eedd2d6d0a5ff8d65df5280c5e50a27766881b3e0429e0cb631893ccace3603e092e512b780551b7a111
7
+ data.tar.gz: 13038c6045c7560470a228ebbe99edf46ad41d117a655bb0d15c286d2cea62eca362e5ff2613225de7f5ffde657d0e2849e5dd579e253c13583a9d7a14143ae4
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 2.5.0 - 2015-02-16
4
+ - New: `deep_merge_payload` hook allows Posts, Pages, and Documents to have control over the way the payload is merged. (Expert level)
5
+
3
6
  ### 2.4.1 - 2015-01-30
4
7
  - Fix: Collection rendering issues for no-output collection items.
5
8
 
data/README.md CHANGED
@@ -20,6 +20,21 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install octopress-hooks
22
22
 
23
+ ## Hook timeline
24
+
25
+ This is the order in which hooks are triggered.
26
+
27
+ 1. Site `pre_read`
28
+ 2. Site `post_read`
29
+ 3. Post/Page/Document `post_init`
30
+ 4. Site `pre_render`
31
+ 5. Site `merge_payload`
32
+ 6. Post/Page/Document `pre_render`
33
+ 5. Post/Page/Document `merge_payload`
34
+ 7. Post/Page/Document `post_render`
35
+ 8. Post/Page/Document `post_write`
36
+ 9. Site `post_write`
37
+
23
38
  ## Usage
24
39
 
25
40
  First extend the appropriate Hook class.
@@ -142,21 +157,6 @@ module Samurai
142
157
  end
143
158
  ```
144
159
 
145
- ### Hook timeline
146
-
147
- Just to be clear, this is the order in which these hooks are triggered.
148
-
149
- 1. Site `pre_read`
150
- 2. Site `post_read`
151
- 3. Post/Page/Document `post_init`
152
- 4. Site `pre_render`
153
- 5. Site `merge_payload`
154
- 6. Post/Page/Document `pre_render`
155
- 5. Post/Page/Document `merge_payload`
156
- 7. Post/Page/Document `post_render`
157
- 8. Post/Page/Document `post_write`
158
- 9. Site `post_write`
159
-
160
160
  ## Contributing
161
161
 
162
162
  1. Fork it ( https://github.com/octopress/hooks/fork )
@@ -63,6 +63,17 @@ module Octopress
63
63
  payload
64
64
  end
65
65
 
66
+ # Merges payload with original page payload
67
+ # Allowing merged_payload to return hash fragments, for example:
68
+ # merge_payload can return { awesome => true } and it will be merged
69
+ # into the full payload.
70
+ #
71
+ # Retuns: a payload that has been deep merged with the original page's payload
72
+ #
73
+ def deep_merge_payload(page_payload, hook_payload)
74
+ Jekyll::Utils.deep_merge_hashes(page_payload, hook_payload)
75
+ end
76
+
66
77
  # Called after the post is rendered with the converter.
67
78
  # Use the post object to modify it's contents before the
68
79
  # post is inserted into the template.
@@ -81,6 +92,9 @@ module Octopress
81
92
  class Post < Jekyll::Plugin
82
93
  def post_init(post); end
83
94
  def merge_payload(payload, post); payload; end
95
+ def deep_merge_payload(page_payload, hook_payload)
96
+ Jekyll::Utils.deep_merge_hashes(page_payload, hook_payload)
97
+ end
84
98
  def pre_render(post); end
85
99
  def post_render(post); end
86
100
  def post_write(post); end
@@ -89,6 +103,9 @@ module Octopress
89
103
  class Document < Jekyll::Plugin
90
104
  def post_init(doc); end
91
105
  def merge_payload(payload, doc); payload; end
106
+ def deep_merge_payload(page_payload, hook_payload)
107
+ Jekyll::Utils.deep_merge_hashes(page_payload, hook_payload)
108
+ end
92
109
  def pre_render(doc); end
93
110
  def post_render(doc); end
94
111
  def post_write(doc); end
@@ -97,6 +114,9 @@ module Octopress
97
114
  class All < Jekyll::Plugin
98
115
  def post_init(item); end
99
116
  def merge_payload(payload, item); payload; end
117
+ def deep_merge_payload(page_payload, hook_payload)
118
+ Jekyll::Utils.deep_merge_hashes(page_payload, hook_payload)
119
+ end
100
120
  def pre_render(item); end
101
121
  def post_render(item); end
102
122
  def post_write(item); end
@@ -175,10 +195,9 @@ module Jekyll
175
195
  payload = old_site_payload
176
196
 
177
197
  site_hooks.each do |hook|
178
- p = hook.merge_payload(payload, self) || {}
179
- if p != {}
180
- payload = Jekyll::Utils.deep_merge_hashes(payload, p)
181
- end
198
+ p = hook.merge_payload(payload, self)
199
+ next unless p && p.is_a?(Hash)
200
+ payload = Jekyll::Utils.deep_merge_hashes(payload, p)
182
201
  end
183
202
  payload
184
203
  end
@@ -248,9 +267,8 @@ module Jekyll
248
267
  def merge_payload(payload)
249
268
  hooks.each do |hook|
250
269
  p = hook.merge_payload(payload, self)
251
- if p && p.is_a?(Hash)
252
- payload = Jekyll::Utils.deep_merge_hashes(payload, p)
253
- end
270
+ next unless p && p.is_a?(Hash)
271
+ payload = hook.deep_merge_payload(payload, p)
254
272
  end
255
273
  payload
256
274
  end
@@ -350,9 +368,8 @@ module Jekyll
350
368
  def merge_payload(payload)
351
369
  hooks.each do |hook|
352
370
  p = hook.merge_payload(payload, self)
353
- if p && p.is_a?(Hash)
354
- payload = Jekyll::Utils.deep_merge_hashes(payload, p)
355
- end
371
+ next unless p && p.is_a?(Hash)
372
+ payload = hook.deep_merge_payload(payload, p)
356
373
  end
357
374
  payload
358
375
  end
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Hooks
3
- VERSION = "2.4.1"
3
+ VERSION = "2.5.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll