Class: Alchemy::ElementsBlockHelper::ElementViewHelper

Inherits:
BlockHelper
  • Object
show all
Defined in:
app/helpers/alchemy/elements_block_helper.rb

Overview

Block-level helper class for element views.

Instance Attribute Summary

Attributes inherited from BlockHelper

#helpers, #opts

Instance Method Summary collapse

Methods inherited from BlockHelper

#element, #initialize

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.

Returns:

  • (Boolean)


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

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

#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, options = {}, html_options = {})
  renderable = element.ingredient_by_role(name)
  return if renderable.nil?

  helpers.render(
    renderable.as_view_component(
      options: options,
      html_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