Class: Jekyll::Document

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

Overview

Monkey patch Jekyll’s Document class

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Document

Returns a new instance of Document.



221
222
223
224
# File 'lib/octopress-hooks.rb', line 221

def initialize(*args)
  old_initialize(*args)
  post_init if place_in_layout?
end

Instance Method Details

#hooksObject



232
233
234
# File 'lib/octopress-hooks.rb', line 232

def hooks
  @hooks ||= site.all_hooks + site.doc_hooks
end

#merge_payload(payload) ⇒ Object



248
249
250
251
252
253
254
255
256
# File 'lib/octopress-hooks.rb', line 248

def merge_payload(payload)
  hooks.each do |hook|
    p = hook.merge_payload(payload, self)
    if p && p.is_a?(Hash)
      payload = Jekyll::Utils.deep_merge_hashes(payload, p)
    end
  end
  payload
end

#old_initializeObject



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

alias_method :old_initialize, :initialize

#old_writeObject



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

alias_method :old_write, :write

#post_initObject



236
237
238
239
240
# File 'lib/octopress-hooks.rb', line 236

def post_init
  hooks.each do |hook|
    hook.post_init(self)
  end
end

#post_renderObject



258
259
260
261
262
# File 'lib/octopress-hooks.rb', line 258

def post_render
  hooks.each do |hook|
    hook.post_render(self)
  end
end

#post_writeObject



264
265
266
267
268
# File 'lib/octopress-hooks.rb', line 264

def post_write
  hooks.each do |hook|
    hook.post_write(self)
  end
end

#pre_renderObject



242
243
244
245
246
# File 'lib/octopress-hooks.rb', line 242

def pre_render
  hooks.each do |hook|
    hook.pre_render(self)
  end
end

#write(dest) ⇒ Object



226
227
228
229
230
# File 'lib/octopress-hooks.rb', line 226

def write(dest)
  post_render if place_in_layout?
  old_write(dest)
  post_write if place_in_layout?
end