Module: Releaf::ApplicationHelper

Defined in:
app/helpers/releaf/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#i18n_options_for_select(container, selected, prefix, i18n_options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/releaf/application_helper.rb', line 26

def i18n_options_for_select container, selected, prefix, i18n_options={}
  i18n_options = { scope: controller_scope_name }.merge(i18n_options)

  translated_container = []

  container.each do|element|
    text, value = i18n_option_text_and_value(element).map { |item| item.to_s }
    text = I18n.t("#{prefix}-#{text}", **i18n_options.merge(default: text))
    translated_container << [text, value]
  end

  return options_for_select(translated_container, selected)
end

#merge_attributes(a, b) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'app/helpers/releaf/application_helper.rb', line 3

def merge_attributes(a, b)
  if a.key?(:class) || b.key?(:class)
    classes = {class: [a[:class], b[:class]].flatten.reject(&:blank?)}
  else
    classes = {}
  end

  a.deep_merge(b).merge(classes)
end

#releaf_table(collection, resource_class, options = {}) ⇒ Object



13
14
15
16
17
# File 'app/helpers/releaf/application_helper.rb', line 13

def releaf_table(collection, resource_class, options = {})
  builder_class = options[:builder]
  options.delete(:builder)
  builder_class.new(collection, resource_class, self, options).output
end

#translate(key, options = {}) ⇒ Object Also known as: t



19
20
21
22
23
# File 'app/helpers/releaf/application_helper.rb', line 19

def translate(key, options = {})
  # prevent I18n from raising errors when translation is missing
  options.merge!(raise: false) unless options.key?(:raise)
  super(key, **options)
end