Module: Refinery::ActionHelper

Included in:
TagHelper
Defined in:
app/helpers/refinery/action_helper.rb

Instance Method Summary collapse

Instance Method Details

#action_icon(action, url, title, options = {}) ⇒ Object

returns a link to the requested url, with the requested icon as content



8
9
10
# File 'app/helpers/refinery/action_helper.rb', line 8

def action_icon(action, url, title, options={})
  action_icon_label(action, url, title, options, false)
end

#action_icon_label(action, url, title, options = {}, label = true) ⇒ Object

See icons.scss for defined icons/classes



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/refinery/action_helper.rb', line 18

def action_icon_label(action, url, title, options={}, label = true)
  options[:title] = title
  action_classes = ["#{action}_icon", action]

  case action
  when :preview
    options[:target] = '_blank'
  when :delete
    options[:method] = 'delete'
  when :reorder_done
    action_classes.push 'hidden'
  end

  options[:class] = [options[:class], *action_classes].compact.join(' ')
  link_to(label && title || '', url, **options)
end

#action_label(action, url, title, options = {}) ⇒ Object

returns a link to the requested url, with icon and label as content



13
14
15
# File 'app/helpers/refinery/action_helper.rb', line 13

def action_label(action, url, title, options={})
  action_icon_label(action, url, title, options, true)
end

#edit_in_current_locale(url:, title:, **options) ⇒ Object



36
37
38
# File 'app/helpers/refinery/action_helper.rb', line 36

def edit_in_current_locale(url:, title:, **options)
  action_icon(:edit, url, title, class: :edit,  **options)
end

#edit_in_locale(locale, url:, title: nil, **options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/refinery/action_helper.rb', line 44

def edit_in_locale(locale, url:, title: nil, **options)
  if options.delete(:label)
    action_label(
      :locale, "#{url}?switch_locale=#{locale}",
      title || locale.to_s.upcase,
      **options,
      id: locale,
      class: :edit, **options
    )
  else
    action_icon(
      :locale, "#{url}?switch_locale=#{locale}",
      title || ::I18n.t('.edit_in_language', language: locale_language(locale), scope: 'refinery.admin.locale_picker'),
      **options,
      id: locale,
      class: :edit
    )
  end
end

#edit_in_locales(edit_url, locales = [], i18n_scope: %i[refinery admin locale_picker])) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'app/helpers/refinery/action_helper.rb', line 64

def edit_in_locales(edit_url, locales = [], i18n_scope: %i[refinery admin locale_picker])
  return if locales.empty?

  edit_links = locales.map do |locale|
    language = ::Refinery::I18n.config.locales.fetch(locale, locale)
    edit_in_locale(locale, url: edit_url, title: t('edit_in_language', language: language, scope: i18n_scope))
  end

  tag.span edit_links.compact.join(' ').html_safe, class: :locales
end

#i18n_scopeObject



3
4
5
# File 'app/helpers/refinery/action_helper.rb', line 3

def i18n_scope
  'refinery.index.locale_picker'
end

#locale_language(locale) ⇒ Object



40
41
42
# File 'app/helpers/refinery/action_helper.rb', line 40

def locale_language(locale)
  Refinery::I18n.locales[locale]
end