Module: Refinery::ActionHelper
- Included in:
- TagHelper
- Defined in:
- app/helpers/refinery/action_helper.rb
Instance Method Summary collapse
-
#action_icon(action, url, title, options = {}) ⇒ Object
returns a link to the requested url, with the requested icon as content.
-
#action_icon_label(action, url, title, options = {}, label = true) ⇒ Object
See icons.scss for defined icons/classes.
-
#action_label(action, url, title, options = {}) ⇒ Object
returns a link to the requested url, with icon and label as content.
- #edit_in_current_locale(url:, title:, **options) ⇒ Object
- #edit_in_locale(locale, url:, title: nil, **options) ⇒ Object
- #edit_in_locales(edit_url, locales = [], i18n_scope: %i[refinery admin locale_picker])) ⇒ Object
- #i18n_scope ⇒ Object
- #locale_language(locale) ⇒ Object
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, ={}) action_icon_label(action, url, title, , 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, ={}, label = true) [:title] = title action_classes = ["#{action}_icon", action] case action when :preview [:target] = '_blank' when :delete [:method] = 'delete' when :reorder_done action_classes.push 'hidden' end [:class] = [[:class], *action_classes].compact.join(' ') link_to(label && title || '', url, **) 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, ={}) action_icon_label(action, url, title, , 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:, **) action_icon(:edit, url, title, class: :edit, **) 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, **) if .delete(:label) action_label( :locale, "#{url}?switch_locale=#{locale}", title || locale.to_s.upcase, **, id: locale, class: :edit, ** ) else action_icon( :locale, "#{url}?switch_locale=#{locale}", title || ::I18n.t('.edit_in_language', language: locale_language(locale), scope: 'refinery.admin.locale_picker'), **, 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_scope ⇒ Object
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 |