Class: Jekyll::Site
- Inherits:
-
Object
- Object
- Jekyll::Site
- Defined in:
- lib/octopress-hooks.rb
Overview
Monkey patch for the Jekyll Site class.
Instance Attribute Summary collapse
-
#all_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
-
#doc_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
-
#page_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
-
#post_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
-
#site_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
Instance Method Summary collapse
-
#load_hooks ⇒ Object
Instantiates all of the hook plugins.
- #old_read ⇒ Object
- #old_render ⇒ Object
- #old_reset ⇒ Object
- #old_site_payload ⇒ Object
- #old_write ⇒ Object
- #read ⇒ Object
-
#render ⇒ Object
Allows site hooks to get access to the site before the render method is called.
-
#reset ⇒ Object
Load hooks before read to ensure that Post and Page hooks can be triggered during initialization.
-
#site_payload ⇒ Object
Allows site hooks to merge data into the site payload.
-
#write ⇒ Object
Trigger site hooks after site has been written.
Instance Attribute Details
#all_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
147 148 149 |
# File 'lib/octopress-hooks.rb', line 147 def all_hooks @all_hooks end |
#doc_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
147 148 149 |
# File 'lib/octopress-hooks.rb', line 147 def doc_hooks @doc_hooks end |
#page_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
147 148 149 |
# File 'lib/octopress-hooks.rb', line 147 def page_hooks @page_hooks end |
#post_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
147 148 149 |
# File 'lib/octopress-hooks.rb', line 147 def post_hooks @post_hooks end |
#site_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
147 148 149 |
# File 'lib/octopress-hooks.rb', line 147 def site_hooks @site_hooks end |
Instance Method Details
#load_hooks ⇒ Object
Instantiates all of the hook plugins. This is basically a duplication of the other loaders in Site#setup.
151 152 153 154 155 156 157 |
# File 'lib/octopress-hooks.rb', line 151 def load_hooks self.site_hooks = instantiate_subclasses(Octopress::Hooks::Site) || [] self.page_hooks = instantiate_subclasses(Octopress::Hooks::Page) || [] self.post_hooks = instantiate_subclasses(Octopress::Hooks::Post) || [] self.doc_hooks = instantiate_subclasses(Octopress::Hooks::Document) || [] self.all_hooks = instantiate_subclasses(Octopress::Hooks::All) || [] end |
#old_read ⇒ Object
163 |
# File 'lib/octopress-hooks.rb', line 163 alias_method :old_read, :read |
#old_render ⇒ Object
161 |
# File 'lib/octopress-hooks.rb', line 161 alias_method :old_render, :render |
#old_reset ⇒ Object
159 |
# File 'lib/octopress-hooks.rb', line 159 alias_method :old_reset, :reset |
#old_site_payload ⇒ Object
160 |
# File 'lib/octopress-hooks.rb', line 160 alias_method :old_site_payload, :site_payload |
#old_write ⇒ Object
162 |
# File 'lib/octopress-hooks.rb', line 162 alias_method :old_write, :write |
#read ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/octopress-hooks.rb', line 176 def read site_hooks.each do |hook| hook.pre_read(self) end old_read site_hooks.each do |hook| hook.post_read(self) end end |
#render ⇒ Object
Allows site hooks to get access to the site before the render method is called
Returns nothing
192 193 194 195 196 197 198 |
# File 'lib/octopress-hooks.rb', line 192 def render site_hooks.each do |hook| hook.pre_render(self) end old_render end |
#reset ⇒ Object
Load hooks before read to ensure that Post and Page hooks can be triggered during initialization
168 169 170 171 172 173 174 |
# File 'lib/octopress-hooks.rb', line 168 def reset old_reset load_hooks site_hooks.each do |hook| hook.reset(self) end end |
#site_payload ⇒ Object
Allows site hooks to merge data into the site payload
Returns the patched site payload
203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/octopress-hooks.rb', line 203 def site_payload @cached_payload = begin payload = old_site_payload site_hooks.each do |hook| p = hook.merge_payload(payload, self) next unless p && p.is_a?(Hash) payload = Jekyll::Utils.deep_merge_hashes(payload, p) end payload end end |
#write ⇒ Object
Trigger site hooks after site has been written
Returns nothing
219 220 221 222 223 224 225 |
# File 'lib/octopress-hooks.rb', line 219 def write old_write site_hooks.each do |hook| hook.post_write(self) end end |