octopress-hooks 2.2.3 → 2.3.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 +4 -1
- data/README.md +29 -15
- data/lib/octopress-hooks/version.rb +1 -1
- data/lib/octopress-hooks.rb +104 -34
- metadata +17 -28
- data/.clash.yml +0 -10
- data/.gitignore +0 -19
- data/.travis.yml +0 -8
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/octopress-hooks.gemspec +0 -23
- data/test/.gitignore +0 -1
- data/test/Gemfile +0 -6
- data/test/_config.yml +0 -5
- data/test/_expected/post_read +0 -1
- data/test/_expected/site/2014/05/21/hi-guys.html +0 -1
- data/test/_expected/site/boom +0 -1
- data/test/_expected/site/magic +0 -1
- data/test/_expected/site/merge_payload.html +0 -1
- data/test/_expected/site/post_render_page.html +0 -1
- data/test/_expected/site/post_write_page.html +0 -1
- data/test/_expected/site/pre_read +0 -1
- data/test/_expected/site/pre_render_page.html +0 -1
- data/test/_plugins/test.rb +0 -85
- data/test/_posts/2014-05-21-hi-guys.md +0 -3
- data/test/merge_payload.md +0 -3
- data/test/post_render_page.md +0 -3
- data/test/post_write_page.md +0 -3
- data/test/pre_render_page.md +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b16cdad0d0ab96fd3be82495163c0016bc2ba0a
|
4
|
+
data.tar.gz: c68895b002b5994f26850aac35683a9851cc32c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b973e48ff39db131289d97f828be2c3002bd78af0c086ce1cb749c07d0f2c21ad80bc70b5c7904a6662a7da2e65e518270db9c11e4b28c9efcebc8af7cf5703
|
7
|
+
data.tar.gz: 5b91e5e25c04fa8d5adc97483dad2a3166eacd432cf8a874e034f84601d8384268e7da27f416e493635bc7da51665f13b96d081edfcae5839bee39ab79474827
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -27,6 +27,7 @@ First extend the appropriate Hook class.
|
|
27
27
|
- `Octopress::Hooks::Site` - access Jekyll's Site instance.
|
28
28
|
- `Octopress::Hooks::Page` - access to each of Jekyll's Page instances.
|
29
29
|
- `Octopress::Hooks::Post` - access to each of Jekyll's Post instances.
|
30
|
+
- `Octopress::Hooks::Document` - access to each of Jekyll's Collection Documents instances.
|
30
31
|
|
31
32
|
Then add a method based on when you want to trigger your hooks.
|
32
33
|
|
@@ -64,10 +65,9 @@ Use the `merge_paylod` hook to modify the site payload or merge custom data into
|
|
64
65
|
|
65
66
|
Use the `post_write` to trigger and action after all documents have been written to disk.
|
66
67
|
|
67
|
-
#### Post/Page hooks
|
68
|
+
#### Post/Page/Documents hooks
|
68
69
|
|
69
|
-
The Page and
|
70
|
-
pages. Here's an example of a Page hook.
|
70
|
+
The Page, Post and Document hooks have four methods and are identical except that Post hooks only operate on posts, and Page hooks only operate on pages and Document hooks only Operate on Collection Documents. Here's an example of a Page hook.
|
71
71
|
|
72
72
|
```ruby
|
73
73
|
class MyPageHook < Octopress::Hooks::Page
|
@@ -95,23 +95,37 @@ With `post_render` you can access pages and posts after it has been converted in
|
|
95
95
|
|
96
96
|
With `post_write` you can execute a code block after a page or post has been successfully written to disk.
|
97
97
|
|
98
|
-
To
|
98
|
+
To work with all page types, you'd do something like this.
|
99
99
|
|
100
100
|
```ruby
|
101
|
-
module
|
102
|
-
|
103
|
-
|
101
|
+
module Toaster
|
102
|
+
ProcessAll < Octopress::Hooks::All
|
103
|
+
def pre_render(item)
|
104
|
+
item.content.gsub!(/bread/, 'tost')
|
105
|
+
end
|
104
106
|
end
|
107
|
+
end
|
108
|
+
```
|
105
109
|
|
106
|
-
|
110
|
+
To process pages, posts, or documents individually, you'd do this.
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
module Samurai
|
114
|
+
ProcessPosts < Octopress::Hooks::Post
|
107
115
|
def pre_render(post)
|
108
|
-
|
116
|
+
post.gsub!(/bread/, 'sliced bread')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
ProcessPages < Octopress::Hooks::Page
|
121
|
+
def pre_render(page)
|
122
|
+
post.gsub!(/bread/, 'sliced bread')
|
109
123
|
end
|
110
124
|
end
|
111
125
|
|
112
|
-
|
126
|
+
ProcessPages < Octopress::Hooks::Document
|
113
127
|
def pre_render(page)
|
114
|
-
|
128
|
+
post.gsub!(/bread/, 'sliced bread')
|
115
129
|
end
|
116
130
|
end
|
117
131
|
end
|
@@ -123,12 +137,12 @@ Just to be clear, this is the order in which these hooks are triggered.
|
|
123
137
|
|
124
138
|
1. Site `pre_read`
|
125
139
|
2. Site `post_read`
|
126
|
-
3. Post/Page `post_init`
|
140
|
+
3. Post/Page/Document `post_init`
|
127
141
|
4. Site `pre_render`
|
128
142
|
5. Site `merge_payload`
|
129
|
-
6. Post/Page `pre_render`
|
130
|
-
7. Post/Page `post_render`
|
131
|
-
8. Post/Page `post_write`
|
143
|
+
6. Post/Page/Document `pre_render`
|
144
|
+
7. Post/Page/Document `post_render`
|
145
|
+
8. Post/Page/Document `post_write`
|
132
146
|
9. Site `post_write`
|
133
147
|
|
134
148
|
## Contributing
|
data/lib/octopress-hooks.rb
CHANGED
@@ -44,28 +44,28 @@ module Octopress
|
|
44
44
|
# allows you to modify a # page object before it is
|
45
45
|
# added to the Jekyll pages array
|
46
46
|
#
|
47
|
-
def post_init(
|
47
|
+
def post_init(page)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Called before post is sent to the converter. Allows
|
51
51
|
# you to modify the post object before the converter
|
52
52
|
# does it's thing
|
53
53
|
#
|
54
|
-
def pre_render(
|
54
|
+
def pre_render(page)
|
55
55
|
end
|
56
56
|
|
57
57
|
# Called after the post is rendered with the converter.
|
58
58
|
# Use the post object to modify it's contents before the
|
59
59
|
# post is inserted into the template.
|
60
60
|
#
|
61
|
-
def post_render(
|
61
|
+
def post_render(page)
|
62
62
|
end
|
63
63
|
|
64
64
|
# Called after the post is written to the disk.
|
65
65
|
# Use the post object to read it's contents to do something
|
66
66
|
# after the post is safely written.
|
67
67
|
#
|
68
|
-
def post_write(
|
68
|
+
def post_write(page)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -76,6 +76,19 @@ module Octopress
|
|
76
76
|
def post_write(post); end
|
77
77
|
end
|
78
78
|
|
79
|
+
class Document < Jekyll::Plugin
|
80
|
+
def post_init(doc); end
|
81
|
+
def pre_render(doc); end
|
82
|
+
def post_render(doc); end
|
83
|
+
def post_write(doc); end
|
84
|
+
end
|
85
|
+
|
86
|
+
class All < Jekyll::Plugin
|
87
|
+
def post_init(item); end
|
88
|
+
def pre_render(item); end
|
89
|
+
def post_render(item); end
|
90
|
+
def post_write(item); end
|
91
|
+
end
|
79
92
|
end
|
80
93
|
end
|
81
94
|
|
@@ -92,7 +105,7 @@ module Jekyll
|
|
92
105
|
|
93
106
|
# Instance variable to store the various page_hook
|
94
107
|
# plugins that are loaded.
|
95
|
-
attr_accessor :page_hooks, :post_hooks, :site_hooks
|
108
|
+
attr_accessor :page_hooks, :post_hooks, :site_hooks, :doc_hooks, :all_hooks
|
96
109
|
|
97
110
|
# Instantiates all of the hook plugins. This is basically
|
98
111
|
# a duplication of the other loaders in Site#setup.
|
@@ -100,6 +113,8 @@ module Jekyll
|
|
100
113
|
self.site_hooks = instantiate_subclasses(Octopress::Hooks::Site) || []
|
101
114
|
self.page_hooks = instantiate_subclasses(Octopress::Hooks::Page) || []
|
102
115
|
self.post_hooks = instantiate_subclasses(Octopress::Hooks::Post) || []
|
116
|
+
self.doc_hooks = instantiate_subclasses(Octopress::Hooks::Document) || []
|
117
|
+
self.all_hooks = instantiate_subclasses(Octopress::Hooks::All) || []
|
103
118
|
end
|
104
119
|
|
105
120
|
|
@@ -112,14 +127,15 @@ module Jekyll
|
|
112
127
|
# can be triggered during initialization
|
113
128
|
#
|
114
129
|
def read
|
115
|
-
|
116
|
-
|
130
|
+
load_hooks
|
131
|
+
|
132
|
+
site_hooks.each do |hook|
|
117
133
|
hook.pre_read(self)
|
118
134
|
end
|
119
135
|
|
120
136
|
old_read
|
121
137
|
|
122
|
-
|
138
|
+
site_hooks.each do |hook|
|
123
139
|
hook.post_read(self)
|
124
140
|
end
|
125
141
|
end
|
@@ -129,10 +145,8 @@ module Jekyll
|
|
129
145
|
#
|
130
146
|
# Returns nothing
|
131
147
|
def render
|
132
|
-
|
133
|
-
self
|
134
|
-
hook.pre_render(self)
|
135
|
-
end
|
148
|
+
site_hooks.each do |hook|
|
149
|
+
hook.pre_render(self)
|
136
150
|
end
|
137
151
|
|
138
152
|
old_render
|
@@ -145,12 +159,10 @@ module Jekyll
|
|
145
159
|
unless @cached_payload
|
146
160
|
payload = old_site_payload
|
147
161
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
payload = Jekyll::Utils.deep_merge_hashes(payload, p)
|
153
|
-
end
|
162
|
+
site_hooks.each do |hook|
|
163
|
+
p = hook.merge_payload(payload, self) || {}
|
164
|
+
if p != {}
|
165
|
+
payload = Jekyll::Utils.deep_merge_hashes(payload, p)
|
154
166
|
end
|
155
167
|
end
|
156
168
|
|
@@ -166,10 +178,8 @@ module Jekyll
|
|
166
178
|
def write
|
167
179
|
old_write
|
168
180
|
|
169
|
-
|
170
|
-
self
|
171
|
-
hook.post_write(self)
|
172
|
-
end
|
181
|
+
site_hooks.each do |hook|
|
182
|
+
hook.post_write(self)
|
173
183
|
end
|
174
184
|
end
|
175
185
|
end
|
@@ -182,11 +192,71 @@ module Jekyll
|
|
182
192
|
|
183
193
|
def initialize(*args)
|
184
194
|
old_initialize(*args)
|
185
|
-
post_init if respond_to?(:post_init) &&
|
195
|
+
post_init if respond_to?(:post_init) && hooks
|
196
|
+
end
|
197
|
+
|
198
|
+
def hooks
|
199
|
+
@hooks ||= site.all_hooks + site.page_hooks
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
# Monkey patch Jekyll's Document class
|
204
|
+
#
|
205
|
+
class Document
|
206
|
+
alias_method :old_initialize, :initialize
|
207
|
+
alias_method :old_write, :write
|
208
|
+
|
209
|
+
def initialize(*args)
|
210
|
+
old_initialize(*args)
|
211
|
+
post_init if place_in_layout?
|
212
|
+
end
|
213
|
+
|
214
|
+
def write(dest)
|
215
|
+
post_render if place_in_layout?
|
216
|
+
old_write(dest)
|
217
|
+
post_write if place_in_layout?
|
186
218
|
end
|
187
219
|
|
188
220
|
def hooks
|
189
|
-
|
221
|
+
@hooks ||= site.all_hooks + site.doc_hooks
|
222
|
+
end
|
223
|
+
|
224
|
+
def post_init
|
225
|
+
puts 'post_init doc'
|
226
|
+
hooks.each do |hook|
|
227
|
+
hook.post_init(self)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def pre_render
|
232
|
+
puts 'pre_render doc'
|
233
|
+
hooks.each do |hook|
|
234
|
+
hook.pre_render(self)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def post_render
|
239
|
+
puts 'post_render doc'
|
240
|
+
hooks.each do |hook|
|
241
|
+
hook.post_render(self)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def post_write
|
246
|
+
puts 'post_write doc'
|
247
|
+
hooks.each do |hook|
|
248
|
+
hook.post_write(self)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
class Renderer
|
254
|
+
alias_method :old_run, :run
|
255
|
+
attr_accessor :output
|
256
|
+
|
257
|
+
def run
|
258
|
+
document.pre_render if document.place_in_layout?
|
259
|
+
old_run
|
190
260
|
end
|
191
261
|
end
|
192
262
|
|
@@ -197,11 +267,11 @@ module Jekyll
|
|
197
267
|
|
198
268
|
def initialize(*args)
|
199
269
|
old_initialize(*args)
|
200
|
-
post_init if respond_to?(:post_init) &&
|
270
|
+
post_init if respond_to?(:post_init) && hooks
|
201
271
|
end
|
202
272
|
|
203
273
|
def hooks
|
204
|
-
|
274
|
+
@hooks ||= site.all_hooks + site.post_hooks
|
205
275
|
end
|
206
276
|
end
|
207
277
|
|
@@ -219,9 +289,9 @@ module Jekyll
|
|
219
289
|
#
|
220
290
|
# Returns nothing.
|
221
291
|
def do_layout(payload, layouts)
|
222
|
-
pre_render if respond_to?(:pre_render) &&
|
292
|
+
pre_render if respond_to?(:pre_render) && hooks
|
223
293
|
old_do_layout(payload, layouts)
|
224
|
-
post_render if respond_to?(:post_render) &&
|
294
|
+
post_render if respond_to?(:post_render) && hooks
|
225
295
|
end
|
226
296
|
|
227
297
|
# Write the generated post file to the destination directory. It
|
@@ -231,7 +301,7 @@ module Jekyll
|
|
231
301
|
# Returns nothing
|
232
302
|
def write(dest)
|
233
303
|
old_write(dest)
|
234
|
-
post_write if respond_to?(:post_write) &&
|
304
|
+
post_write if respond_to?(:post_write) && hooks
|
235
305
|
end
|
236
306
|
|
237
307
|
def hooks
|
@@ -239,25 +309,25 @@ module Jekyll
|
|
239
309
|
end
|
240
310
|
|
241
311
|
def post_init
|
242
|
-
|
312
|
+
hooks.each do |hook|
|
243
313
|
hook.post_init(self)
|
244
314
|
end
|
245
315
|
end
|
246
316
|
|
247
317
|
def pre_render
|
248
|
-
|
318
|
+
hooks.each do |hook|
|
249
319
|
hook.pre_render(self)
|
250
320
|
end
|
251
321
|
end
|
252
322
|
|
253
323
|
def post_render
|
254
|
-
|
324
|
+
hooks.each do |hook|
|
255
325
|
hook.post_render(self)
|
256
326
|
end
|
257
327
|
end
|
258
328
|
|
259
329
|
def post_write
|
260
|
-
|
330
|
+
hooks.each do |hook|
|
261
331
|
hook.post_write(self)
|
262
332
|
end
|
263
333
|
end
|
@@ -265,7 +335,7 @@ module Jekyll
|
|
265
335
|
# Returns the full url of the post, including the configured url
|
266
336
|
#
|
267
337
|
def full_url
|
268
|
-
File.join(
|
338
|
+
File.join(site.config['url'], url)
|
269
339
|
end
|
270
340
|
end
|
271
341
|
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
|
+
version: 2.3.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:
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -52,43 +52,32 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
|
56
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
57
70
|
email:
|
58
71
|
- brandon@imathis.com
|
59
72
|
executables: []
|
60
73
|
extensions: []
|
61
74
|
extra_rdoc_files: []
|
62
75
|
files:
|
63
|
-
- ".clash.yml"
|
64
|
-
- ".gitignore"
|
65
|
-
- ".travis.yml"
|
66
76
|
- CHANGELOG.md
|
67
|
-
- Gemfile
|
68
77
|
- LICENSE.txt
|
69
78
|
- README.md
|
70
|
-
- Rakefile
|
71
79
|
- lib/octopress-hooks.rb
|
72
80
|
- lib/octopress-hooks/version.rb
|
73
|
-
- octopress-hooks.gemspec
|
74
|
-
- test/.gitignore
|
75
|
-
- test/Gemfile
|
76
|
-
- test/_config.yml
|
77
|
-
- test/_expected/post_read
|
78
|
-
- test/_expected/site/2014/05/21/hi-guys.html
|
79
|
-
- test/_expected/site/boom
|
80
|
-
- test/_expected/site/magic
|
81
|
-
- test/_expected/site/merge_payload.html
|
82
|
-
- test/_expected/site/post_render_page.html
|
83
|
-
- test/_expected/site/post_write_page.html
|
84
|
-
- test/_expected/site/pre_read
|
85
|
-
- test/_expected/site/pre_render_page.html
|
86
|
-
- test/_plugins/test.rb
|
87
|
-
- test/_posts/2014-05-21-hi-guys.md
|
88
|
-
- test/merge_payload.md
|
89
|
-
- test/post_render_page.md
|
90
|
-
- test/post_write_page.md
|
91
|
-
- test/pre_render_page.md
|
92
81
|
homepage: http://github.com/octopress/hooks
|
93
82
|
licenses:
|
94
83
|
- MIT
|
data/.clash.yml
DELETED
data/.gitignore
DELETED
data/.travis.yml
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.0.0
|
4
|
-
- 1.9.3
|
5
|
-
script: bundle exec clash test
|
6
|
-
notifications:
|
7
|
-
slack:
|
8
|
-
secure: FZR2kuuJF2PwpzsoSsPgU5r2Uaj9LL611gOt2de9/x1bx2N464DTBVa3nhV8SfNRNOrqR10nvt8CvKqL4iWNdt3OpU8iK7/PTqCIsggJbdfAkqU5WAhsmV7+shYIJxi+kOH+8bockG7c4kY9GMBaJUSe1VgM+BHsykUyrna8ywQ=
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/octopress-hooks.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'octopress-hooks/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |gem|
|
7
|
-
gem.name = "octopress-hooks"
|
8
|
-
gem.version = Octopress::Hooks::VERSION
|
9
|
-
gem.authors = ["Brandon Mathis"]
|
10
|
-
gem.email = ["brandon@imathis.com"]
|
11
|
-
gem.description = %q{Allows access to Jekyll's site, posts and pages at different points in the life cycle of a build. Formerly known as 'jekyll-page-hooks'.}
|
12
|
-
gem.summary = %q{Allows access to Jekyll's site, posts and pages at different points in the life cycle of a build. Formerly known as 'jekyll-page-hooks'.}
|
13
|
-
gem.homepage = "http://github.com/octopress/hooks"
|
14
|
-
gem.license = "MIT"
|
15
|
-
|
16
|
-
gem.add_runtime_dependency 'jekyll', '~> 2.0'
|
17
|
-
|
18
|
-
gem.add_development_dependency 'clash', '~> 1.0'
|
19
|
-
gem.add_development_dependency 'rake'
|
20
|
-
|
21
|
-
gem.files = `git ls-files`.split($/)
|
22
|
-
gem.require_paths = ["lib"]
|
23
|
-
end
|
data/test/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
_site
|
data/test/Gemfile
DELETED
data/test/_config.yml
DELETED
data/test/_expected/post_read
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
pages: 4
|
@@ -1 +0,0 @@
|
|
1
|
-
<p>Hi guys awesome</p>
|
data/test/_expected/site/boom
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
BOOM
|
data/test/_expected/site/magic
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
MAGIC
|
@@ -1 +0,0 @@
|
|
1
|
-
<p>Your New Jekyll Site == Your New Jekyll Site</p>
|
@@ -1 +0,0 @@
|
|
1
|
-
<p><code><strong></code> is for the weak. The age of <code><blink><strong></code> is <blink><strong>upon us</strong></blink>.</p>
|
@@ -1 +0,0 @@
|
|
1
|
-
<p>This page has been written</p>
|
@@ -1 +0,0 @@
|
|
1
|
-
pages: 0
|
@@ -1 +0,0 @@
|
|
1
|
-
<p>Snatch this _______ from my hand.</p>
|
data/test/_plugins/test.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'octopress-hooks'
|
2
|
-
|
3
|
-
module TestingHooks
|
4
|
-
class SiteHookTest < Octopress::Hooks::Site
|
5
|
-
def pre_read(site)
|
6
|
-
file = File.join(site.source, 'pre_read')
|
7
|
-
File.open(file, 'w') { |f| f.write("pages: #{site.pages.size}") }
|
8
|
-
end
|
9
|
-
|
10
|
-
def post_read(site)
|
11
|
-
file = File.join(site.source, 'post_read')
|
12
|
-
File.open(file, 'w') { |f| f.write("pages: #{site.pages.size}") }
|
13
|
-
end
|
14
|
-
|
15
|
-
def pre_render(site)
|
16
|
-
file = File.join(site.source, 'magic')
|
17
|
-
File.open(file, 'w') { |f| f.write('MAGIC') }
|
18
|
-
site.static_files << Jekyll::StaticFile.new(site, site.source, '', 'magic')
|
19
|
-
end
|
20
|
-
|
21
|
-
def merge_payload(payload, site)
|
22
|
-
if payload['site']['title']
|
23
|
-
payload['site']['name'] ||= payload['site']['title']
|
24
|
-
end
|
25
|
-
|
26
|
-
payload
|
27
|
-
end
|
28
|
-
|
29
|
-
def post_write(site)
|
30
|
-
file = File.join(site.config['destination'], 'boom')
|
31
|
-
File.open(file, 'w') { |f| f.write('BOOM') }
|
32
|
-
FileUtils.rm('magic')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class PostHooksTest < Octopress::Hooks::Post
|
37
|
-
def post_init(post)
|
38
|
-
post.data['injected_data'] = 'awesome'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class PageHooksTest < Octopress::Hooks::Page
|
43
|
-
|
44
|
-
# Inherited methods from PageHooks
|
45
|
-
|
46
|
-
# Called before processors
|
47
|
-
#
|
48
|
-
def pre_render(page)
|
49
|
-
page.content = snatch_cupcake page.content
|
50
|
-
end
|
51
|
-
|
52
|
-
# Called after processors
|
53
|
-
#
|
54
|
-
def post_render(page)
|
55
|
-
page.content = blink_strong page.content
|
56
|
-
end
|
57
|
-
|
58
|
-
# Called after write
|
59
|
-
#
|
60
|
-
def post_write(page)
|
61
|
-
file = page.destination(page.site.config['destination'])
|
62
|
-
File.open(file, 'w') { |f| f.write(log_write(page.content)) }
|
63
|
-
end
|
64
|
-
|
65
|
-
# Plugin methods
|
66
|
-
|
67
|
-
# Replaces *cupcake* with _______ before markdown renders <em>cupcake</em>.
|
68
|
-
#
|
69
|
-
def snatch_cupcake(content)
|
70
|
-
content.sub /\*cupcake\*/, '_______'
|
71
|
-
end
|
72
|
-
|
73
|
-
def log_write(content)
|
74
|
-
content.sub /hasn't/, 'has'
|
75
|
-
end
|
76
|
-
|
77
|
-
# Replaces <strong> tag with <strong><blink> after html has been rendered.
|
78
|
-
#
|
79
|
-
def blink_strong(content)
|
80
|
-
content.gsub /(<strong>.+?<\/strong>)/ do
|
81
|
-
"<blink>#{$1}</blink>"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/test/merge_payload.md
DELETED
data/test/post_render_page.md
DELETED
data/test/post_write_page.md
DELETED
data/test/pre_render_page.md
DELETED