octopress-hooks 2.1.0 → 2.2.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: 3169a133f7c3a17900e54db52932fb84a202ec66
4
- data.tar.gz: 104ff2a28bcce7a7bea13e51acd7b3585025bbfe
3
+ metadata.gz: 5e3bd95b88b25cb56b6a5bbd8f7c34fca11d523f
4
+ data.tar.gz: 106875c913792ed39b59775a987179d90486de30
5
5
  SHA512:
6
- metadata.gz: 9985494e92eb14430704b568b60beb58fd14e5043779f76eb0ed87bac8a23abc1da593128b30514b50c7091b7aea3e0565aacb186d38371d78e58d2da1ae8884
7
- data.tar.gz: e4cb99f4706e85ac8d39b0fb8da9bfb006b21c7afaf286a7e38de1bb8ff9d5c267ede3b3e1c6eeeb984fdfcc26a19a06926cd159ec6834d93111966bd76731be
6
+ metadata.gz: 4f268204aef608a201f1f1ee5de87bd904f35ba2874fbdc9ca84c6e392e1c5d67d3ddce2a739be6d436fee17b3032f60038b3adda6e7b4c092cf91e2a4098373
7
+ data.tar.gz: f055592a699b4573b0898393d4227037cb5d8c1e47f47e75d8be50c91c67c722df4146fb2c685bb5a410a4dfaaf039fd82a1dfb111984b2fec895175ff09bda0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ### 2.1.0
3
+ ### 2.2.0 - 2014-07-28
4
+ - New: Site hook - pre_read, runs before site reads items
5
+ - New: Site hook - post_read, runs after site reads items
6
+
7
+ ### 2.1.0 - 2014-07-28
4
8
  - New: Added Post hooks.
5
9
  - Change: Page hooks now only target pages.
6
10
  - New: Added post_init hooks for pages and posts which is triggered after initialization.
data/README.md CHANGED
@@ -34,9 +34,15 @@ Then add a method based on when you want to trigger your hooks.
34
34
 
35
35
  The Site class has three methods. Here's an example.
36
36
 
37
- ```
37
+ ```ruby
38
38
  class MySiteHook < Octopress::Hooks::Site
39
39
 
40
+ def pre_read(site)
41
+ end
42
+
43
+ def post_read(site)
44
+ end
45
+
40
46
  def pre_render(site)
41
47
  end
42
48
 
@@ -48,6 +54,10 @@ class MySiteHook < Octopress::Hooks::Site
48
54
  end
49
55
  ```
50
56
 
57
+ Use the `pre_read` hook to modify the site instance before posts, pages and static files are read.
58
+
59
+ Use the `pre_read` hook to modify the site instance after posts, pages and static files are read but before generators are triggered.
60
+
51
61
  Use the `pre_render` hook to modify the site instance before posts and pages are rendered.
52
62
 
53
63
  Use the `merge_paylod` hook to modify the site payload or merge custom data into it. This data will be available to all documents when they are rendered. This method must return a hash.
@@ -59,8 +69,8 @@ Use the `post_write` to trigger and action after all documents have been written
59
69
  The Page and Post hooks have four methods and are identical except that Post hooks only operate on posts, and Page hooks only operate on
60
70
  pages. Here's an example of a Page hook.
61
71
 
62
- ```
63
- class MySiteHook < Octopress::Hooks::Page
72
+ ```ruby
73
+ class MyPageHook < Octopress::Hooks::Page
64
74
 
65
75
  def post_init(page)
66
76
  end
@@ -99,9 +109,9 @@ module MyModule
99
109
  end
100
110
  end
101
111
 
102
- MyPostHook < Octopress::Hooks::Page
103
- def pre_render(post)
104
- MyModule.do_awesome(post)
112
+ MyPageHook < Octopress::Hooks::Page
113
+ def pre_render(page)
114
+ MyModule.do_awesome(page)
105
115
  end
106
116
  end
107
117
  end
@@ -111,13 +121,16 @@ end
111
121
 
112
122
  Just to be clear, this is the order in which these hooks are triggered.
113
123
 
114
- 1. Post/Page `post_init`
115
- 2. Site `pre_render`
116
- 3. Site `merge_payload`
117
- 4. Post/Page `pre_render`
118
- 5. Post/Page `post_render`
119
- 6. Post/Page `post_write`
120
- 7. Site `post_write`
124
+ 1. Site `pre_read`
125
+ 2. Site `post_read`
126
+ 3. Post/Page `post_init`
127
+ 4. Post/Page `post_init`
128
+ 5. Site `pre_render`
129
+ 6. Site `merge_payload`
130
+ 7. Post/Page `pre_render`
131
+ 8. Post/Page `post_render`
132
+ 9. Post/Page `post_write`
133
+ 10. Site `post_write`
121
134
 
122
135
  ## Contributing
123
136
 
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Hooks
3
- VERSION = "2.1.0"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
  end
@@ -6,6 +6,18 @@ module Octopress
6
6
 
7
7
  class Site < Jekyll::Plugin
8
8
 
9
+ # Called before after Jekyll reads in items
10
+ # Returns nothing
11
+ #
12
+ def pre_read(site)
13
+ end
14
+
15
+ # Called right after Jekyll reads in all items, but before generators
16
+ # Returns nothing
17
+ #
18
+ def post_read(site)
19
+ end
20
+
9
21
  # Called before Jekyll renders posts and pages
10
22
  # Returns nothing
11
23
  #
@@ -101,7 +113,15 @@ module Jekyll
101
113
  #
102
114
  def read
103
115
  self.load_hooks
116
+ self.site_hooks.each do |hook|
117
+ hook.pre_read(self)
118
+ end
119
+
104
120
  old_read
121
+
122
+ self.site_hooks.each do |hook|
123
+ hook.post_read(self)
124
+ end
105
125
  end
106
126
 
107
127
  # Allows site hooks to get access to the site before
data/test/.clash.yml CHANGED
@@ -1,2 +1,10 @@
1
- build: true
2
- compare: _expected _site
1
+ -
2
+ build: true
3
+ before: rm pre_read post_read
4
+ compare: _expected/site _site
5
+ -
6
+ name: Test post_read
7
+ enforce_missing: _site/post_read
8
+ compare: _expected/post_read post_read
9
+ after: rm pre_read post_read
10
+
@@ -0,0 +1 @@
1
+ pages: 4
File without changes
File without changes
@@ -0,0 +1 @@
1
+ pages: 0
@@ -2,6 +2,16 @@ require 'octopress-hooks'
2
2
 
3
3
  module TestingHooks
4
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
+
5
15
  def pre_render(site)
6
16
  file = File.join(site.source, 'magic')
7
17
  File.open(file, 'w') { |f| f.write('MAGIC') }
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.1.0
4
+ version: 2.2.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: 2014-07-28 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -60,13 +60,15 @@ files:
60
60
  - test/.gitignore
61
61
  - test/Gemfile
62
62
  - test/_config.yml
63
- - test/_expected/2014/05/21/hi-guys.html
64
- - test/_expected/boom
65
- - test/_expected/magic
66
- - test/_expected/merge_payload.html
67
- - test/_expected/post_render_page.html
68
- - test/_expected/post_write_page.html
69
- - test/_expected/pre_render_page.html
63
+ - test/_expected/post_read
64
+ - test/_expected/site/2014/05/21/hi-guys.html
65
+ - test/_expected/site/boom
66
+ - test/_expected/site/magic
67
+ - test/_expected/site/merge_payload.html
68
+ - test/_expected/site/post_render_page.html
69
+ - test/_expected/site/post_write_page.html
70
+ - test/_expected/site/pre_read
71
+ - test/_expected/site/pre_render_page.html
70
72
  - test/_plugins/test.rb
71
73
  - test/_posts/2014-05-21-hi-guys.md
72
74
  - test/merge_payload.md