octopress-hooks 2.3.2 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +17 -5
- data/lib/octopress-hooks.rb +50 -10
- data/lib/octopress-hooks/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 897a94043175acc88720a482f9d7a66c8d04949a
|
4
|
+
data.tar.gz: a6a4aac535cb14c7eeabbdc6f27c6a4c00e09b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b100527547ec43794f052775b04a66fae671ad642f152f57e2f4562ba8ed79cf9c3b7382a799fa4bf10757a25a2f096cb80ae6de3991852320f98adffd572bdd
|
7
|
+
data.tar.gz: ed07cf819b9901754e151bba0edfd2bada8be13a5311c6491b05c4cbb218b8b49e37b3f203a57c6954576003e3b0b485676ff1e097b892901f3f0c16602213aa
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -47,7 +47,10 @@ class MySiteHook < Octopress::Hooks::Site
|
|
47
47
|
def pre_render(site)
|
48
48
|
end
|
49
49
|
|
50
|
+
# Return a hash to merge into payload
|
51
|
+
#
|
50
52
|
def merge_payload(payload, site)
|
53
|
+
{}
|
51
54
|
end
|
52
55
|
|
53
56
|
def post_write(site)
|
@@ -78,6 +81,12 @@ class MyPageHook < Octopress::Hooks::Page
|
|
78
81
|
def pre_render(page)
|
79
82
|
end
|
80
83
|
|
84
|
+
# Return a hash to merge into payload
|
85
|
+
#
|
86
|
+
def merge_payload(payload, page)
|
87
|
+
{}
|
88
|
+
end
|
89
|
+
|
81
90
|
def post_render(page)
|
82
91
|
end
|
83
92
|
|
@@ -91,6 +100,8 @@ modify the instance before the Site compiles its payload, which includes arrays
|
|
91
100
|
|
92
101
|
With `pre_render` you can parse and modify page contents before it is processed by Liquid, Markdown, Textile and the like, and rendered to HTML.
|
93
102
|
|
103
|
+
Use the `merge_paylod` hook to modify the page and site payload or merge custom data into it. Changes to the payload will only affect this page when it is rendered. This method must return a hash to be merged.
|
104
|
+
|
94
105
|
With `post_render` you can access pages and posts after it has been converted into HTML. You might use this option if you want to modify generated HTML. At this stage, be sure to modify the `page.output` if you want change what the page displays.
|
95
106
|
|
96
107
|
With `post_write` you can execute a code block after a page or post has been successfully written to disk.
|
@@ -99,9 +110,9 @@ To work with all page types, you'd do something like this.
|
|
99
110
|
|
100
111
|
```ruby
|
101
112
|
module Toaster
|
102
|
-
ProcessAll < Octopress::Hooks::All
|
113
|
+
class ProcessAll < Octopress::Hooks::All
|
103
114
|
def pre_render(item)
|
104
|
-
item.content.gsub!(/bread/, '
|
115
|
+
item.content.gsub!(/bread/, 'toast')
|
105
116
|
end
|
106
117
|
end
|
107
118
|
end
|
@@ -111,19 +122,19 @@ To process pages, posts, or documents individually, you'd do this.
|
|
111
122
|
|
112
123
|
```ruby
|
113
124
|
module Samurai
|
114
|
-
ProcessPosts < Octopress::Hooks::Post
|
125
|
+
class ProcessPosts < Octopress::Hooks::Post
|
115
126
|
def pre_render(post)
|
116
127
|
post.gsub!(/bread/, 'sliced bread')
|
117
128
|
end
|
118
129
|
end
|
119
130
|
|
120
|
-
ProcessPages < Octopress::Hooks::Page
|
131
|
+
class ProcessPages < Octopress::Hooks::Page
|
121
132
|
def pre_render(page)
|
122
133
|
post.gsub!(/bread/, 'sliced bread')
|
123
134
|
end
|
124
135
|
end
|
125
136
|
|
126
|
-
ProcessPages < Octopress::Hooks::Document
|
137
|
+
class ProcessPages < Octopress::Hooks::Document
|
127
138
|
def pre_render(page)
|
128
139
|
post.gsub!(/bread/, 'sliced bread')
|
129
140
|
end
|
@@ -141,6 +152,7 @@ Just to be clear, this is the order in which these hooks are triggered.
|
|
141
152
|
4. Site `pre_render`
|
142
153
|
5. Site `merge_payload`
|
143
154
|
6. Post/Page/Document `pre_render`
|
155
|
+
5. Post/Page/Document `merge_payload`
|
144
156
|
7. Post/Page/Document `post_render`
|
145
157
|
8. Post/Page/Document `post_write`
|
146
158
|
9. Site `post_write`
|
data/lib/octopress-hooks.rb
CHANGED
@@ -54,6 +54,15 @@ module Octopress
|
|
54
54
|
def pre_render(page)
|
55
55
|
end
|
56
56
|
|
57
|
+
# Called right after pre_render hook. Allows you to
|
58
|
+
# act on the page's payload data.
|
59
|
+
#
|
60
|
+
# Return: hash to be deep_merged into payload
|
61
|
+
#
|
62
|
+
def merge_payload(payload, page)
|
63
|
+
payload
|
64
|
+
end
|
65
|
+
|
57
66
|
# Called after the post is rendered with the converter.
|
58
67
|
# Use the post object to modify it's contents before the
|
59
68
|
# post is inserted into the template.
|
@@ -71,6 +80,7 @@ module Octopress
|
|
71
80
|
|
72
81
|
class Post < Jekyll::Plugin
|
73
82
|
def post_init(post); end
|
83
|
+
def merge_payload(payload, post); payload; end
|
74
84
|
def pre_render(post); end
|
75
85
|
def post_render(post); end
|
76
86
|
def post_write(post); end
|
@@ -78,6 +88,7 @@ module Octopress
|
|
78
88
|
|
79
89
|
class Document < Jekyll::Plugin
|
80
90
|
def post_init(doc); end
|
91
|
+
def merge_payload(payload, doc); payload; end
|
81
92
|
def pre_render(doc); end
|
82
93
|
def post_render(doc); end
|
83
94
|
def post_write(doc); end
|
@@ -85,6 +96,7 @@ module Octopress
|
|
85
96
|
|
86
97
|
class All < Jekyll::Plugin
|
87
98
|
def post_init(item); end
|
99
|
+
def merge_payload(payload, item); payload; end
|
88
100
|
def pre_render(item); end
|
89
101
|
def post_render(item); end
|
90
102
|
def post_write(item); end
|
@@ -159,7 +171,7 @@ module Jekyll
|
|
159
171
|
#
|
160
172
|
# Returns the patched site payload
|
161
173
|
def site_payload
|
162
|
-
|
174
|
+
@cached_payload = begin
|
163
175
|
payload = old_site_payload
|
164
176
|
|
165
177
|
site_hooks.each do |hook|
|
@@ -168,11 +180,8 @@ module Jekyll
|
|
168
180
|
payload = Jekyll::Utils.deep_merge_hashes(payload, p)
|
169
181
|
end
|
170
182
|
end
|
171
|
-
|
172
|
-
@cached_payload = payload
|
183
|
+
payload
|
173
184
|
end
|
174
|
-
|
175
|
-
@cached_payload
|
176
185
|
end
|
177
186
|
|
178
187
|
# Trigger site hooks after site has been written
|
@@ -236,6 +245,16 @@ module Jekyll
|
|
236
245
|
end
|
237
246
|
end
|
238
247
|
|
248
|
+
def merge_payload(payload)
|
249
|
+
hooks.each do |hook|
|
250
|
+
p = hook.merge_payload(payload, self)
|
251
|
+
if p && p.is_a?(Hash)
|
252
|
+
payload = Jekyll::Utils.deep_merge_hashes(payload, p)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
payload
|
256
|
+
end
|
257
|
+
|
239
258
|
def post_render
|
240
259
|
hooks.each do |hook|
|
241
260
|
hook.post_render(self)
|
@@ -250,12 +269,17 @@ module Jekyll
|
|
250
269
|
end
|
251
270
|
|
252
271
|
class Renderer
|
253
|
-
alias_method :
|
272
|
+
alias_method :old_render_liquid, :render_liquid
|
254
273
|
attr_accessor :output
|
255
274
|
|
256
|
-
def
|
257
|
-
document.pre_render if document.
|
258
|
-
|
275
|
+
def render_liquid(content, payload, info, path = nil)
|
276
|
+
document.pre_render if document.respond_to?(:pre_render) && document.hooks
|
277
|
+
|
278
|
+
if document.respond_to?(:merge_payload) && document.hooks
|
279
|
+
old_render_liquid(document.content, document.merge_payload(payload.dup), info)
|
280
|
+
else
|
281
|
+
old_render_liquid(document.content, payload, info)
|
282
|
+
end
|
259
283
|
end
|
260
284
|
end
|
261
285
|
|
@@ -289,7 +313,13 @@ module Jekyll
|
|
289
313
|
# Returns nothing.
|
290
314
|
def do_layout(payload, layouts)
|
291
315
|
pre_render if respond_to?(:pre_render) && hooks
|
292
|
-
|
316
|
+
|
317
|
+
if respond_to?(:merge_payload) && hooks
|
318
|
+
old_do_layout(merge_payload(payload.dup), layouts)
|
319
|
+
else
|
320
|
+
old_do_layout(payload, layouts)
|
321
|
+
end
|
322
|
+
|
293
323
|
post_render if respond_to?(:post_render) && hooks
|
294
324
|
end
|
295
325
|
|
@@ -313,6 +343,16 @@ module Jekyll
|
|
313
343
|
end
|
314
344
|
end
|
315
345
|
|
346
|
+
def merge_payload(payload)
|
347
|
+
hooks.each do |hook|
|
348
|
+
p = hook.merge_payload(payload, self)
|
349
|
+
if p && p.is_a?(Hash)
|
350
|
+
payload = Jekyll::Utils.deep_merge_hashes(payload, p)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
payload
|
354
|
+
end
|
355
|
+
|
316
356
|
def pre_render
|
317
357
|
hooks.each do |hook|
|
318
358
|
hook.pre_render(self)
|
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
|
+
version: 2.4.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-
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|