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



98
99
100
101
102
103
104
# File 'app/helpers/alchemy/admin/essences_helper.rb', line 98

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/alchemy/admin/essences_helper.rb', line 59

def essence_picture_thumbnail(content, options)
  ingredient = content.ingredient
  essence = content.essence
  return if ingredient.blank?

  crop = !(essence.crop_size.blank? && essence.crop_from.blank?) ||
         (
           content.settings_value(:crop, options) == true ||
           content.settings_value(:crop, options) == "true"
         )

  size = if essence.render_size.blank?
           content.settings_value(:size, options)
         else
           essence.render_size
         end

  image_options = {
    size: essence.thumbnail_size(size, crop),
    crop_from: essence.crop_from.blank? ? nil : essence.crop_from,
    crop_size: essence.crop_size.blank? ? nil : essence.crop_size,
    crop: crop ? 'crop' : nil,
    upsample: content.settings_value(:upsample, options)
  }

  image_tag(
    alchemy.thumbnail_path({
      id: ingredient.id,
      name: ingredient.urlname,
      sh: ingredient.security_token(image_options),
      format: ingredient.image_file_format
    }.merge(image_options)),
    alt: ingredient.name,
    class: 'img_paddingtop',
    title: Alchemy.t(:image_name) + ": #{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.



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

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



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

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.



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

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



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

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