class Jekyll::Assets::Hook

Attributes

points[R]

Public Class Methods

add_point(*point) click to toggle source

– Create a hook point to attach hooks to. @param [Array<String,Symbol>] point the parent and child. @note plugins can create their own points if wished. @return [Hash<Hash<Array>>] –

# File lib/jekyll/assets/hook.rb, line 66
def self.add_point(*point)
  raise ArgumentError, "only give 2 points" if point.count > 2

  @points[point[0]] ||= {}
  @points[point[0]][point[1]] ||= {}
  @points
end
check_point(*point) click to toggle source

– @param point the points to check. Checks that a point exists or raises an error. @return [nil] –

# File lib/jekyll/assets/hook.rb, line 124
def self.check_point(*point)
  raise ArgumentError, "only give 2 points" if point.count > 2
  if !@points.key?(point[0]) || !@points[point[0]].key?(point[1])
    raise ArgumentError, "Unknown hook #{point}"
  end
end
get_point(*point) click to toggle source

– @return [Array<Proc>] @param [Array<String,Symbol>] point the parent and child. @note this is really internal. Get a hook point. –

# File lib/jekyll/assets/hook.rb, line 80
def self.get_point(*point)
  check_point(*point)
  @points[point[0]][point[1]]
    .sort_by(&:priority)
end
register(*point, priority: 48, &block) click to toggle source

– Register a hook on a hook point. @param [Array<String,Symbol>] point the parent and child. @param [Integer] priority your priority. @note this is what plugins should use. @return [nil] –

# File lib/jekyll/assets/hook.rb, line 111
def self.register(*point, priority: 48, &block)
  check_point(*point)
  point_ = Point.new(priority, &block)
  out = @points[point[0]]
  out = out[point[1]]
  out << point_
end
trigger(*point, &block) click to toggle source

– Trigger a hook point. @note plugins can trigger their own hooks. @param [Array<String,Symbol>] point the parent and child. @param [Proc{}] block the code to run. @see self.add_point @return [nil] –

# File lib/jekyll/assets/hook.rb, line 94
def self.trigger(*point, &block)
  hooks = get_point(*point)
  Logger.debug "messaging hooks on #{point.last} " \
    "through #{point.first}"

  hooks.map do |v|
    block.call(v.block)
  end
end