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 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, 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