Class: Alchemy::ElementsBlockHelper::ElementViewHelper
- Inherits:
-
BlockHelper
- Object
- BlockHelper
- Alchemy::ElementsBlockHelper::ElementViewHelper
- Defined in:
- app/helpers/alchemy/elements_block_helper.rb
Overview
Block-level helper class for element views.
Instance Attribute Summary
Attributes inherited from BlockHelper
Instance Method Summary collapse
-
#has?(name) ⇒ Boolean
Returns true if the given ingredient has a value.
-
#ingredient_by_role(role) ⇒ Object
(also: #ingredient)
Return's the ingredient record by given role.
-
#nested_elements ⇒ Object
The element's visible nested children.
-
#render(name, options = {}, html_options = {}) ⇒ Object
Renders one of the element's ingredients.
-
#value(name) ⇒ Object
Returns the value of one of the element's ingredients.
Methods inherited from BlockHelper
Constructor Details
This class inherits a constructor from Alchemy::ElementsBlockHelper::BlockHelper
Instance Method Details
#has?(name) ⇒ Boolean
Returns true if the given ingredient has a value.
51 52 53 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 51 def has?(name) element.has_value_for?(name) end |
#ingredient_by_role(role) ⇒ Object Also known as: ingredient
Return's the ingredient record by given role.
57 58 59 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 57 def ingredient_by_role(role) element.ingredient_by_role(role) end |
#nested_elements ⇒ Object
The element's visible nested children.
Reads them from the page version's shared in-memory element repository
instead of the nested_elements association, so rendering a deeply
nested element tree does not issue one query per parent.
Returns an Alchemy::ElementsRepository so callers can keep chaining
scopes (e.g. nested_elements.named(:slide)) while still rendering it
directly as a collection (+render el.nested_elements+).
72 73 74 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 72 def nested_elements element.page_version.element_repository.children_of(element).visible end |
#render(name, options = {}, html_options = {}) ⇒ Object
Renders one of the element's ingredients.
If the element uses ingredients it renders the ingredient record.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 31 def render(name, = {}, = {}) renderable = element.ingredient_by_role(name) return if renderable.nil? helpers.render( renderable.as_view_component( options: , html_options: ) ) end |
#value(name) ⇒ Object
Returns the value of one of the element's ingredients.
45 46 47 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 45 def value(name) element.value_for(name) end |