Module: Trestle::Hook::Helpers
- Included in:
- Form::Renderer, Trestle::HookHelper
- Defined in:
- lib/trestle/hook/helpers.rb
Instance Method Summary collapse
-
#hook(name, *args, &block) ⇒ Object
Evaluates any defined hooks with the given name and returns the result.
-
#hook?(name) ⇒ Boolean
Returns true or false depending on whether there are any defined hooks (either on the current admin or globally) with the given name.
Instance Method Details
#hook(name, *args, &block) ⇒ Object
Evaluates any defined hooks with the given name and returns the result.
Each hook is evaluated and passed any provided arguments, and the result is concatenated together. If no hooks are defined, and a block is passed to this helper, then the block will be evaluated instead.
name - Name of hook to evaluate args - Arguments to pass to hook blocks block - Optional block to evaluate as a fallback if no hooks are defined
Examples
<%= hook("index.toolbar.primary", toolbar) %>
<%= hook("view.title") do %>
Default Title
<% end %>
Returns a HTML-safe string.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/trestle/hook/helpers.rb', line 23 def hook(name, *args, &block) hooks = hooks(name) if hooks.any? safe_join(hooks.map { |hook| hook.evaluate(self, *args) }, "\n") elsif block_given? capture(*args, &block) end end |
#hook?(name) ⇒ Boolean
Returns true or false depending on whether there are any defined hooks (either on the current admin or globally) with the given name.
37 38 39 |
# File 'lib/trestle/hook/helpers.rb', line 37 def hook?(name) hooks(name).any? end |