Module: Bridgetown::Builders::DSL::Hooks

Included in:
PluginBuilder
Defined in:
lib/bridgetown-builder/dsl/hooks.rb

Instance Method Summary collapse

Instance Method Details

#add_data(data_key) ⇒ Object

Define a site post_read hook and add data returned by the block to the site data/signals



28
29
30
31
32
33
34
35
# File 'lib/bridgetown-builder/dsl/hooks.rb', line 28

def add_data(data_key)
  hook(:site, :post_read) do
    yield.tap do |value|
      site.data[data_key] = value
      site.signals[data_key] = value
    end
  end
end

#hook(owner, event, method_name = nil, priority: Bridgetown::Hooks::DEFAULT_PRIORITY, &block) ⇒ Object

Define a hook to run at some point during the build process

Parameters:

  • owner (Symbol)

    name of the owner (‘:site`, `:resource`, etc.)

  • event (Symbol)

    name of the event (‘:pre_read`, `:post_render`, etc.)

  • method_name (Symbol) (defaults to: nil)

    name of a Builder method to use, if block isn’t provided

  • priority (Integer, Symbol) (defaults to: Bridgetown::Hooks::DEFAULT_PRIORITY)

    either ‘:low`, `:normal`, or `:high`, or an integer. Default is normal (20)



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bridgetown-builder/dsl/hooks.rb', line 14

def hook(
  owner,
  event,
  method_name = nil,
  priority: Bridgetown::Hooks::DEFAULT_PRIORITY,
  &block
)
  block = method(method_name) if method_name.is_a?(Symbol)

  hook_block = Bridgetown::Hooks.register_one(owner, event, priority:, &block)
  functions << { name:, hook: [owner, event, priority, hook_block] }
end