Module: Alchemy::Admin::ElementsHelper

Includes:
BaseHelper, ContentsHelper, EssencesHelper, ElementsBlockHelper
Defined in:
app/helpers/alchemy/admin/elements_helper.rb

Instance Method Summary collapse

Methods included from EssencesHelper

#edit_picture_dialog_size, #essence_picture_thumbnail, #pages_for_select, #render_essence_editor, #render_essence_editor_by_name, #render_missing_content

Methods included from ContentsHelper

#content_label, #render_content_name

Methods included from BaseHelper

#alchemy_body_class, #alchemy_datepicker, #button_with_confirm, #clipboard_select_tag_options, #current_alchemy_user_name, #delete_button, #hint_with_tooltip, #js_filter_field, #link_to_confirm_dialog, #link_to_dialog, #link_url_regexp, #new_asset_path_with_session_information, #page_layout_missing_warning, #render_alchemy_title, #render_hint_for, #sites_for_select, #toolbar, #toolbar_button, #translations_for_select

Methods included from NavigationHelper

#alchemy_main_navigation_entry, #entry_active?, #main_navigation_css_classes, #navigate_module, #sorted_alchemy_modules, #url_for_module, #url_for_module_sub_navigation

Methods included from BaseHelper

#message_icon_class, #page_or_find, #render_flash_notice, #render_icon, #render_message, #shorten, #warning

Methods included from EssencesHelper

#render_essence, #render_essence_view, #render_essence_view_by_name

Methods included from ElementsBlockHelper

#element_editor_for, #element_view_for

Instance Method Details

#element_editable?(element) ⇒ Boolean

Tells us, if we should show the element footer and form inputs.

Returns:

  • (Boolean)


105
106
107
108
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 105

def element_editable?(element)
  return false if element.folded?
  element.content_definitions.present? || element.taggable?
end

#element_editor_classes(element) ⇒ Object

CSS classes for the element editor partial.



92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 92

def element_editor_classes(element)
  [
    'element-editor',
    element.content_definitions.present? ? 'with-contents' : 'without-contents',
    element.nestable_elements.any? ? 'nestable' : 'not-nestable',
    element.taggable? ? 'taggable' : 'not-taggable',
    element.folded ? 'folded' : 'expanded',
    element.compact? ? 'compact' : nil,
    element.fixed? ? 'is-fixed' : 'not-fixed'
  ].join(' ')
end

#elements_for_select(elements) ⇒ Array

Returns an elements array for select helper.

Parameters:

  • elements (Array)

    definitions

Returns:

  • (Array)


81
82
83
84
85
86
87
88
89
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 81

def elements_for_select(elements)
  return [] if elements.nil?
  elements.collect do |e|
    [
      Element.display_name_for(e['name']),
      e['name']
    ]
  end
end

#render_editor(element) ⇒ Object

Deprecated.

Using element editor partials is deprecated and will be removed in Alchemy 5.0

Note:

If the partial is not found alchemy/elements/_editor_not_found.html.erb gets rendered.

Renders a Element editor partial.

A element editor partial is the form presented to the content author in page edit mode.

The partial is located in app/views/alchemy/elements.

Partial naming

The partials have to be named after the name of the element as defined in the elements.yml file and has to be suffixed with _editor.

Example

Given a headline element

# elements.yml
- name: headline
  contents:
  - name: text
    type: EssenceText

Then your element editor partial has to be named:

app/views/alchemy/elements/_headline_editor.html.{erb|haml|slim}

Element partials generator

You can use this handy generator to let Alchemy generate the partials for you:

$ rails generate alchemy:elements --skip

Usage

<%= render_editor(Alchemy::Element.published.named(:headline).first) %>

Parameters:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 52

def render_editor(element)
  if element.nil?
    warning('Element is nil')
    render "alchemy/elements/editor_not_found", {name: 'nil'}
    return
  end
  Alchemy::Deprecation.warn <<~WARN
    Using element editor partials is deprecated and will be removed in Alchemy 5.0.
    You can delete the `app/views/alchemy/elements/_#{element.name}_editor` partial
    and Alchemy will render the content editors for you.
  WARN

  render "alchemy/elements/#{element.name}_editor", element: element
rescue ActionView::MissingTemplate => e
  warning(%(
    Element editor partial not found for #{element.name}.\n
    #{e}
  ))
  render "alchemy/elements/editor_not_found", {
    name: element.name,
    error: "Element editor partial not found.<br>Use <code>rails generate alchemy:elements</code> to generate it."
  }
end