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).
50 51 52 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 50 def content(name) element.content_by_name(name) end |
#essence(name) ⇒ Object
Return’s the given content’s essence.
84 85 86 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 84 def essence(name) content(name).try(:essence) end |
#has?(name) ⇒ Boolean
Returns true if the given content or ingredient has a value.
72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 72 def has?(name) if element.ingredient_definitions.any? element.has_value_for?(name) else Alchemy::Deprecation.silence do element.has_ingredient?(name) end 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.
60 61 62 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 60 def ingredient(name) element.ingredient(name) end |
#ingredient_by_role(role) ⇒ Object
Return’s the ingredient record by given role.
92 93 94 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 92 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 40 41 42 43 44 45 46 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 31 def render(name, = {}, = {}) renderable = element.ingredient_by_role(name) || Alchemy::Deprecation.silence { content(name) } return if renderable.nil? if Alchemy::DEPRECATED_ESSENCE_CLASSES.include?(renderable.try(:essence)&.class&.name) Alchemy::Deprecation.warn( "Using a '#{renderable.essence.class.name.demodulize}' content is deprecated. " \ "Please use a '#{Alchemy::DEPRECATED_ESSENCE_CLASS_MAPPING[renderable.essence.class.name].demodulize}' ingredient instead." ) end helpers.render(renderable, { options: , html_options: , }) end |
#value(name) ⇒ Object
Returns the value of one of the element’s ingredients.
66 67 68 |
# File 'app/helpers/alchemy/elements_block_helper.rb', line 66 def value(name) element.value_for(name) end |