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

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

Instance Method Summary collapse

Instance Method Details

#add_data(data_key) ⇒ Object



20
21
22
23
24
# File 'bridgetown-builder/lib/bridgetown-builder/dsl/hooks.rb', line 20

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

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



7
8
9
10
11
12
13
14
15
16
17
18
# File 'bridgetown-builder/lib/bridgetown-builder/dsl/hooks.rb', line 7

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