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.
-
#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_render ⇒ Object
- #old_site_payload ⇒ Object
- #old_write ⇒ Object
-
#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.
72 73 74 |
# File 'lib/octopress-hooks.rb', line 72 def page_hooks @page_hooks end |
#site_hooks ⇒ Object
Instance variable to store the various page_hook plugins that are loaded.
72 73 74 |
# File 'lib/octopress-hooks.rb', line 72 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.
76 77 78 79 |
# File 'lib/octopress-hooks.rb', line 76 def load_hooks self.site_hooks = instantiate_subclasses(Octopress::Hooks::Site) self.page_hooks = instantiate_subclasses(Octopress::Hooks::Page) end |
#old_render ⇒ Object
83 |
# File 'lib/octopress-hooks.rb', line 83 alias_method :old_render, :render |
#old_site_payload ⇒ Object
82 |
# File 'lib/octopress-hooks.rb', line 82 alias_method :old_site_payload, :site_payload |
#old_write ⇒ Object
84 |
# File 'lib/octopress-hooks.rb', line 84 alias_method :old_write, :write |
#render ⇒ Object
Allows site hooks to get access to the site before the render method is called
Returns nothing
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/octopress-hooks.rb', line 90 def render self.load_hooks 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
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/octopress-hooks.rb', line 105 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
127 128 129 130 131 132 133 134 135 |
# File 'lib/octopress-hooks.rb', line 127 def write old_write if self.site_hooks self.site_hooks.each do |hook| hook.post_write(self) end end end |