Module: Alchemy::Admin::ElementsHelper
- Includes:
- BaseHelper, ContentsHelper, EssencesHelper, ElementsBlockHelper
- Defined in:
- app/helpers/alchemy/admin/elements_helper.rb
Instance Method Summary collapse
-
#element_editor_classes(element) ⇒ Object
CSS classes for the element editor partial.
-
#elements_for_select(elements) ⇒ Array
Returns an elements array for select helper.
-
#render_editor(element) ⇒ Object
Renders a Element editor partial.
-
#show_element_footer?(element, with_nestable_elements = nil) ⇒ Boolean
Tells us, if we should show the element footer.
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_editor_classes(element) ⇒ Object
CSS classes for the element editor partial.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 86 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.
75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 75 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
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) %>
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 51 def render_editor(element) if element.nil? warning('Element is nil') render "alchemy/elements/editor_not_found", {name: 'nil'} return end 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 |
#show_element_footer?(element, with_nestable_elements = nil) ⇒ Boolean
Tells us, if we should show the element footer.
99 100 101 102 103 104 105 106 |
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 99 def (element, with_nestable_elements = nil) return false if element.folded? if with_nestable_elements element.content_definitions.present? || element.taggable? else element.nestable_elements.empty? end end |