Module: Alchemy::Admin::EssencesHelper

Includes:
ContentsHelper, EssencesHelper
Included in:
ElementsHelper
Defined in:
app/helpers/alchemy/admin/essences_helper.rb

Instance Method Summary collapse

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

#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

Instance Method Details

#edit_picture_dialog_size(content, options = {}) ⇒ Object

Size value for edit picture dialog



77
78
79
80
81
82
83
# File 'app/helpers/alchemy/admin/essences_helper.rb', line 77

def edit_picture_dialog_size(content, options = {})
  if content.settings_value(:caption_as_textarea, options)
    content.settings_value(:sizes, options) ? '380x320' : '380x300'
  else
    content.settings_value(:sizes, options) ? '380x290' : '380x255'
  end
end

#essence_picture_thumbnail(content, options = {}) ⇒ Object

Renders a thumbnail for given EssencePicture content with correct cropping and size



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/alchemy/admin/essences_helper.rb', line 62

def essence_picture_thumbnail(content, options = {})
  picture = content.ingredient
  essence = content.essence

  return if picture.nil?

  image_tag(
    essence.thumbnail_url(options),
    alt: picture.name,
    class: 'img_paddingtop',
    title: Alchemy.t(:image_name) + ": #{picture.name}"
  )
end

#pages_for_select(pages = nil, selected = nil, prompt = "Choose page", page_attribute = :id) ⇒ Object

Returns all public pages from current language as an option tags string suitable or the Rails select_tag helper.

Parameters:

  • A (Array)

    collection of pages so it only returns these pages and does not query the database.

  • Pass (String)

    a Page#name or Page#id as selected item to the options_for_select helper.

  • Used (String)

    as prompt message in the select tag

  • Method (Symbol)

    that is called on the page object to get the value that is passed with the params of the form.



45
46
47
48
49
50
51
52
53
# File 'app/helpers/alchemy/admin/essences_helper.rb', line 45

def pages_for_select(pages = nil, selected = nil, prompt = "Choose page", page_attribute = :id)
  values = [[Alchemy.t(prompt), ""]]
  pages ||= begin
    nested = true
    Language.current.pages.published.order(:lft)
  end
  values += pages_attributes_for_select(pages, page_attribute, nested)
  options_for_select(values, selected.to_s)
end

#render_essence_editor(content, options = {}, html_options = {}) ⇒ Object

Renders the Content editor partial from the given Content. For options see -> render_essence



11
12
13
# File 'app/helpers/alchemy/admin/essences_helper.rb', line 11

def render_essence_editor(content, options = {}, html_options = {})
  render_essence(content, :editor, {for_editor: options}, html_options)
end

#render_essence_editor_by_name(element, name, options = {}, html_options = {}) ⇒ Object

Renders the Content editor partial found in views/contents/ for the content with name inside the passed Element. For options see -> render_essence

Content creation on the fly:

If you update the elements.yml file after creating an element this helper displays a error message with an option to create the content.



22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/alchemy/admin/essences_helper.rb', line 22

def render_essence_editor_by_name(element, name, options = {}, html_options = {})
  if element.blank?
    return warning('Element is nil', Alchemy.t(:no_element_given))
  end
  content = element.content_by_name(name)
  if content.nil?
    render_missing_content(element, name, options)
  else
    render_essence_editor(content, options, html_options)
  end
end

#render_missing_content(element, name, options) ⇒ Object

Renders the missing content partial



57
58
59
# File 'app/helpers/alchemy/admin/essences_helper.rb', line 57

def render_missing_content(element, name, options)
  render 'alchemy/admin/contents/missing', {element: element, name: name, options: options}
end