class Jekyll::Premonition::Hook

Registers Premonition hooks in Jekyll.

Two hooks are added. One general hook for pages and another special hook for dealing with excerpts within posts.

This ladder is really a hack as we scan all Markdown files and insert the excerpt ourselves in the document data. Unfortunately Jekyll prepares the excerpt way to early in the process, preventing us from hooking into it in a prober way. We only support excerpts if the excerpt_separator is explicitly set: jekyllrb.com/docs/posts/#post-excerpts

Public Class Methods

new(p) click to toggle source
Calls superclass method
# File lib/premonition/hook.rb, line 19
def initialize(p)
  super(p)
end

Public Instance Methods

generate(site) click to toggle source
# File lib/premonition/hook.rb, line 23
def generate(site)
  resources = Resources.new site.config
  processor = Processor.new resources

  Hooks.register [:posts], :pre_render do |doc|
    if process?(resources, doc)
      doc.content = processor.adder(doc.content)
      doc.data['excerpt'] = Jekyll::Excerpt.new(doc) if generate_excerpt? doc
    end
  end

  Hooks.register [:pages], :pre_render do |doc|
    doc.content = processor.adder(doc.content) if process?(resources, doc)
  end
end

Private Instance Methods

generate_excerpt?(doc) click to toggle source
# File lib/premonition/hook.rb, line 41
def generate_excerpt?(doc)
  !doc.data['excerpt_separator'].nil? && !doc.data['excerpt_separator'].empty?
end
process?(resources, doc) click to toggle source
# File lib/premonition/hook.rb, line 45
def process?(resources, doc)
  resources.config['extensions'].include?(File.extname(doc.relative_path)[1..-1])
end