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

#delete_content_link, #label_and_remove_link, #render_content_name, #render_create_content_link, #render_new_content_link

Methods included from BaseHelper

#alchemy_datepicker, #body_class, #button_with_confirm, #clipboard_select_tag_options, #current_alchemy_user_name, #delete_button, #js_filter_field, #link_to_confirm_dialog, #link_to_dialog, #link_url_regexp, #max_image_count, #merge_params, #merge_params_only, #merge_params_without, #new_asset_path_with_session_information, #render_alchemy_title, #render_hint_for, #render_resources, #sites_for_select, #toolbar, #toolbar_button, #translations_for_select

Methods included from NavigationHelper

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

#_t, #page_or_find, #parse_sitemap_name, #render_flash_notice, #render_icon, #render_message, #shorten, #warning

Methods included from EssencesHelper

#content_settings_value, #render_essence, #render_essence_picture_view, #render_essence_view, #render_essence_view_by_name

Instance Method Details

#essence_picture_thumbnail(content, options) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/alchemy/admin/essences_helper.rb', line 60

def essence_picture_thumbnail(content, options)
  return if content.ingredient.blank?
  crop = !(content.essence.crop_size.blank? && content.essence.crop_from.blank?) ||
    (content_settings_value(content, :crop, options) == true || content_settings_value(content, :crop, options) == "true")
  image_options = {
    size: content.essence.thumbnail_size(content.essence.render_size.blank? ? content_settings_value(content, :size, options) : content.essence.render_size, crop),
    crop_from: content.essence.crop_from.blank? ? nil : content.essence.crop_from,
    crop_size: content.essence.crop_size.blank? ? nil : content.essence.crop_size,
    crop: crop ? 'crop' : nil,
    upsample: content_settings_value(content, :upsample, options)
  }
  image_tag(
    alchemy.thumbnail_path({
      id: content.ingredient.id,
      name: content.ingredient.urlname,
      sh: content.ingredient.security_token(image_options)
    }.merge(image_options)),
    alt: content.ingredient.name,
    class: 'img_paddingtop',
    title: _t(:image_name) + ": #{content.ingredient.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.



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

def pages_for_select(pages = nil, selected = nil, prompt = "Choose page", page_attribute = :id)
  values = [[_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



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

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.



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

def render_essence_editor_by_name(element, name, options = {}, html_options = {})
  if element.blank?
    return warning('Element is nil', _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



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

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