Module: Alchemy::Element::Presenters

Extended by:
ActiveSupport::Concern
Included in:
Alchemy::Element
Defined in:
app/models/alchemy/element/presenters.rb

Overview

Methods used for presenting an Alchemy Element.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#display_nameObject

Returns the translated name

See Also:

  • #display_name_for


35
36
37
# File 'app/models/alchemy/element/presenters.rb', line 35

def display_name
  self.class.display_name_for(definition["name"] || name)
end

#display_name_with_preview_text(maxlength = 30) ⇒ Object

Generates a preview text containing Element#display_name and Element#preview_text.

It is displayed inside the head of the Element in the Elements.list overlay window from the Alchemy Admin::Page#edit view.

Example

A Element described as:

- name: funky_element
  display_name: Funky Element
  ingredients:
    - role: headline
      type: Text
    - role: text
      type: Richtext
      as_element_title: true

With “I want to tell you a funky story” as stripped_body for the Richtext ingredient produces:

Funky Element: I want to tell ...

Parameters:

  • maxlength (Fixnum) (defaults to: 30)

    (30) Length of characters after the text will be cut off.



77
78
79
# File 'app/models/alchemy/element/presenters.rb', line 77

def display_name_with_preview_text(maxlength = 30)
  "#{display_name}: #{preview_text(maxlength)}"
end

#dom_idObject

Deprecated.

Returns a dom id used for elements html id tag.



83
84
85
86
87
88
# File 'app/models/alchemy/element/presenters.rb', line 83

def dom_id
  if caller.none? { |l| l =~ Regexp.new("alchemy/elements_block_helper.rb:117:in `element_view_for'") }
    Alchemy::Deprecation.warn("dom_id is deprecated and will be removed from Alchemy 8.0. Please pass an id to the element_view_for helper instead.")
  end
  self.class.dom_id_class.new(self).call
end

#preview_ingredientAlchemy::Ingredient

The ingredient that’s used for element’s preview text.

It tries to find one of element’s ingredients that is defined as_element_title. Takes element’s first defined ingredient if no ingredient is defined as_element_title.

Returns:



97
98
99
# File 'app/models/alchemy/element/presenters.rb', line 97

def preview_ingredient
  @_preview_ingredient ||= ingredients.detect(&:preview_ingredient?) || first_ingredient_by_definition
end

#preview_text(maxlength = 60) ⇒ Object

Returns a preview text for element.

It’s taken from the first Ingredient found in the elements.yml definition file.

You can flag a Ingredient as as_element_title to take this as preview.

Parameters:

  • maxlength (Fixnum) (defaults to: 60)

    (60) Length of characters after the text will be cut off.



48
49
50
51
# File 'app/models/alchemy/element/presenters.rb', line 48

def preview_text(maxlength = 60)
  preview_text_from_preview_ingredient(maxlength) ||
    preview_text_from_nested_elements(maxlength)
end