Class: Jekyll::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/octopress-hooks.rb

Overview

Monkey patch for the Jekyll Site class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#all_hooksObject

Instance variable to store the various page_hook plugins that are loaded.



120
121
122
# File 'lib/octopress-hooks.rb', line 120

def all_hooks
  @all_hooks
end

#doc_hooksObject

Instance variable to store the various page_hook plugins that are loaded.



120
121
122
# File 'lib/octopress-hooks.rb', line 120

def doc_hooks
  @doc_hooks
end

#page_hooksObject

Instance variable to store the various page_hook plugins that are loaded.



120
121
122
# File 'lib/octopress-hooks.rb', line 120

def page_hooks
  @page_hooks
end

#post_hooksObject

Instance variable to store the various page_hook plugins that are loaded.



120
121
122
# File 'lib/octopress-hooks.rb', line 120

def post_hooks
  @post_hooks
end

#site_hooksObject

Instance variable to store the various page_hook plugins that are loaded.



120
121
122
# File 'lib/octopress-hooks.rb', line 120

def site_hooks
  @site_hooks
end

Instance Method Details

#load_hooksObject

Instantiates all of the hook plugins. This is basically a duplication of the other loaders in Site#setup.



124
125
126
127
128
129
130
# File 'lib/octopress-hooks.rb', line 124

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_readObject



136
# File 'lib/octopress-hooks.rb', line 136

alias_method :old_read, :read

#old_renderObject



134
# File 'lib/octopress-hooks.rb', line 134

alias_method :old_render, :render

#old_resetObject



132
# File 'lib/octopress-hooks.rb', line 132

alias_method :old_reset, :reset

#old_site_payloadObject



133
# File 'lib/octopress-hooks.rb', line 133

alias_method :old_site_payload, :site_payload

#old_writeObject



135
# File 'lib/octopress-hooks.rb', line 135

alias_method :old_write, :write

#readObject



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/octopress-hooks.rb', line 146

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

#renderObject

Allows site hooks to get access to the site before the render method is called

Returns nothing



162
163
164
165
166
167
168
# File 'lib/octopress-hooks.rb', line 162

def render
  site_hooks.each do |hook|
    hook.pre_render(self)
  end

  old_render
end

#resetObject

Load hooks before read to ensure that Post and Page hooks can be triggered during initialization



141
142
143
144
# File 'lib/octopress-hooks.rb', line 141

def reset
  old_reset
  load_hooks
end

#site_payloadObject

Allows site hooks to merge data into the site payload

Returns the patched site payload



173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/octopress-hooks.rb', line 173

def site_payload
  @cached_payload = begin
    payload = old_site_payload

    site_hooks.each do |hook|
      p = hook.merge_payload(payload, self) || {}
      if p != {}
        payload = Jekyll::Utils.deep_merge_hashes(payload, p)
      end
    end
    payload
  end
end

#writeObject

Trigger site hooks after site has been written

Returns nothing



190
191
192
193
194
195
196
# File 'lib/octopress-hooks.rb', line 190

def write
  old_write

  site_hooks.each do |hook|
    hook.post_write(self)
  end
end