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
-
#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_site_payload ⇒ Object
- #old_write ⇒ Object
-
#read ⇒ Object
Load hooks before read to ensure that Post and Page hooks can be triggered during initialization.
-
#render ⇒ Object
Allows site hooks to get access to the site before the render method is called.
-
#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
#page_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
83 84 85 |
# File 'lib/octopress-hooks.rb', line 83 def page_hooks @page_hooks end |
#post_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
83 84 85 |
# File 'lib/octopress-hooks.rb', line 83 def post_hooks @post_hooks end |
#site_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
83 84 85 |
# File 'lib/octopress-hooks.rb', line 83 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.
87 88 89 90 91 |
# File 'lib/octopress-hooks.rb', line 87 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) end |
#old_read ⇒ Object
97 |
# File 'lib/octopress-hooks.rb', line 97 alias_method :old_read, :read |
#old_render ⇒ Object
95 |
# File 'lib/octopress-hooks.rb', line 95 alias_method :old_render, :render |
#old_site_payload ⇒ Object
94 |
# File 'lib/octopress-hooks.rb', line 94 alias_method :old_site_payload, :site_payload |
#old_write ⇒ Object
96 |
# File 'lib/octopress-hooks.rb', line 96 alias_method :old_write, :write |
#read ⇒ Object
Load hooks before read to ensure that Post and Page hooks can be triggered during initialization
102 103 104 105 |
# File 'lib/octopress-hooks.rb', line 102 def read self.load_hooks old_read end |
#render ⇒ Object
Allows site hooks to get access to the site before the render method is called
Returns nothing
111 112 113 114 115 116 117 118 119 |
# File 'lib/octopress-hooks.rb', line 111 def render if self.site_hooks self.site_hooks.each do |hook| hook.pre_render(self) end end old_render end |
#site_payload ⇒ Object
Allows site hooks to merge data into the site payload
Returns the patched site payload
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/octopress-hooks.rb', line 124 def site_payload unless @cached_payload payload = old_site_payload if self.site_hooks self.site_hooks.each do |hook| p = hook.merge_payload(payload, self) || {} if p != {} payload = Jekyll::Utils.deep_merge_hashes(payload, p) end end end @cached_payload = payload end @cached_payload end |
#write ⇒ Object
Trigger site hooks after site has been written
Returns nothing
146 147 148 149 150 151 152 153 154 |
# File 'lib/octopress-hooks.rb', line 146 def write old_write if self.site_hooks self.site_hooks.each do |hook| hook.post_write(self) end end end |