module Jekyll::Hooks
Constants
- DEFAULT_PRIORITY
- NotAvailable
- PRIORITY_MAP
-
compatibility layer for octopress-hooks users
- Uncallable
Public Class Methods
Source
# File lib/jekyll/hooks.rb, line 90 def self.insert_hook(owner, event, priority, &block) @hook_priority[block] = [-priority, @hook_priority.size] @registry[owner][event] << block end
Source
# File lib/jekyll/hooks.rb, line 64 def self.priority_value(priority) return priority if priority.is_a?(Integer) PRIORITY_MAP[priority] || DEFAULT_PRIORITY end
Ensure the priority is a Fixnum
Source
# File lib/jekyll/hooks.rb, line 57 def self.register(owners, event, priority: DEFAULT_PRIORITY, &block) Array(owners).each do |owner| register_one(owner, event, priority_value(priority), &block) end end
register hook(s) to be called later, public API
Source
# File lib/jekyll/hooks.rb, line 71 def self.register_one(owner, event, priority, &block) @registry[owner] ||= { :post_init => [], :pre_render => [], :post_convert => [], :post_render => [], :post_write => [], } unless @registry[owner][event] raise NotAvailable, "Invalid hook. #{owner} supports only the following hooks " \ "#{@registry[owner].keys.inspect}" end raise Uncallable, "Hooks must respond to :call" unless block.respond_to? :call insert_hook owner, event, priority, &block end
register a single hook to be called later, internal API
Source
# File lib/jekyll/hooks.rb, line 96 def self.trigger(owner, event, *args) # proceed only if there are hooks to call hooks = @registry.dig(owner, event) return if hooks.nil? || hooks.empty? # sort and call hooks according to priority and load order hooks.sort_by { |h| @hook_priority[h] }.each do |hook| hook.call(*args) end end
interface for Jekyll
core components to trigger hooks