Class: Jekyll::Assets::Hook
- Inherits:
-
Object
- Object
- Jekyll::Assets::Hook
- Defined in:
- lib/jekyll/assets/hook.rb
Defined Under Namespace
Classes: Point, UnknownHookError
Class Attribute Summary collapse
-
.points ⇒ Object
readonly
Returns the value of attribute points.
Class Method Summary collapse
-
.add_point(*point) ⇒ Hash<Hash<Array>>
– Create a hook point to attach hooks to.
-
.check_point(*point) ⇒ nil
– Checks that a point exists or raises an error.
-
.get_point(*point) ⇒ Array<Proc>
– Get a hook point.
-
.register(*point, priority: 48, &block) ⇒ nil
– Register a hook on a hook point.
-
.trigger(*point, &block) ⇒ nil
– Trigger a hook point.
Class Attribute Details
.points ⇒ Object (readonly)
Returns the value of attribute points.
31 32 33 |
# File 'lib/jekyll/assets/hook.rb', line 31 def points @points end |
Class Method Details
.add_point(*point) ⇒ Hash<Hash<Array>>
Note:
plugins can create their own points if wished.
– Create a hook point to attach hooks to. –
66 67 68 69 70 71 72 |
# 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) ⇒ nil
– Checks that a point exists or raises an error. –
124 125 126 127 128 129 |
# 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) ⇒ Array<Proc>
Note:
this is really internal.
– Get a hook point. –
80 81 82 83 84 |
# 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) ⇒ nil
Note:
this is what plugins should use.
– Register a hook on a hook point. –
111 112 113 114 115 116 117 |
# 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) ⇒ nil
Note:
plugins can trigger their own hooks.
– Trigger a hook point. –
94 95 96 97 98 99 100 101 102 |
# 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 |