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


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

def display_name
  self.class.display_name_for(description['name'] || self.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
  contents:
  - name: headline
    type: EssenceText
  - name: text
    type EssenceRichtext
    as_element_title: true

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

Funky Element: I want to tell ...

Parameters:

  • maxlength (Fixnum) (defaults to: 30)

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



75
76
77
# File 'app/models/alchemy/element/presenters.rb', line 75

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

#dom_idObject

Returns a dom id used for elements html id tag.



81
82
83
# File 'app/models/alchemy/element/presenters.rb', line 81

def dom_id
  "#{name}_#{id}"
end

#preview_text(maxlength = 30) ⇒ Object

Returns a preview text for element.

It’s taken from the first Content found in the elements.yml description file.

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

Parameters:

  • maxlength (Fixnum) (defaults to: 30)

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



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

def preview_text(maxlength = 30)
  (contents.detect(&:preview_content?) || contents.first).try(:preview_text, maxlength)
end