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
-
#content(name) ⇒ Object
Returns one of the element’s contents (ie. essence instances).
-
#essence(name) ⇒ Object
Return’s the given content’s essence.
-
#has?(name) ⇒ Boolean
Returns true if the given content or ingredient has a value.
-
#ingredient(name) ⇒ Object
Returns the ingredient of one of the element’s contents.
-
#ingredient_by_role(role) ⇒ Object
Return’s the ingredient record by given role.
-
#render(name, options = {}, html_options = {}) ⇒ Object
Renders one of the element’s contents.
-
#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
#content(name) ⇒ Object
Returns one of the element’s contents (ie. essence instances).
43 44 45 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 43 def content(name) element.content_by_name(name) end |
#essence(name) ⇒ Object
Return’s the given content’s essence.
75 76 77 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 75 def essence(name) content(name).try(:essence) end |
#has?(name) ⇒ Boolean
Returns true if the given content or ingredient has a value.
65 66 67 68 69 70 71 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 65 def has?(name) if element.ingredient_definitions.any? element.has_value_for?(name) else element.has_ingredient?(name) end end |
#ingredient(name) ⇒ Object
Returns the ingredient of one of the element’s contents.
If the element uses ingredients
it returns the value
of the ingredient record.
53 54 55 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 53 def ingredient(name) element.ingredient(name) end |
#ingredient_by_role(role) ⇒ Object
Return’s the ingredient record by given role.
83 84 85 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 83 def ingredient_by_role(role) element.ingredient_by_role(role) end |
#render(name, options = {}, html_options = {}) ⇒ Object
Renders one of the element’s contents.
If the element uses ingredients
it renders the ingredient record.
31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 31 def render(name, = {}, = {}) renderable = element.ingredient_by_role(name) || content(name) return if renderable.nil? helpers.render(renderable, { options: , html_options: , }) end |
#value(name) ⇒ Object
Returns the value of one of the element’s ingredients.
59 60 61 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 59 def value(name) element.value_for(name) end |