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.



250
251
252
253
# File 'lib/octopress-hooks.rb', line 250

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

Instance Method Details

#hooksObject



261
262
263
# File 'lib/octopress-hooks.rb', line 261

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

#merge_payload(payload) ⇒ Object



277
278
279
280
281
282
283
284
# File 'lib/octopress-hooks.rb', line 277

def merge_payload(payload)
  hooks.each do |hook|
    p = hook.merge_payload(payload, self)
    next unless p && p.is_a?(Hash)
    payload = hook.deep_merge_payload(payload, p)
  end
  payload
end

#old_initializeObject



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

alias_method :old_initialize, :initialize

#old_writeObject



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

alias_method :old_write, :write

#post_initObject



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

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

#post_renderObject



286
287
288
289
290
# File 'lib/octopress-hooks.rb', line 286

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

#post_writeObject



292
293
294
295
296
# File 'lib/octopress-hooks.rb', line 292

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

#pre_renderObject



271
272
273
274
275
# File 'lib/octopress-hooks.rb', line 271

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

#write(dest) ⇒ Object



255
256
257
258
259
# File 'lib/octopress-hooks.rb', line 255

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