Module: Releaf::ApplicationHelper
- Defined in:
- app/helpers/releaf/application_helper.rb
Instance Method Summary collapse
- #i18n_options_for_select(container, selected, prefix, i18n_options = {}) ⇒ Object
- #merge_attributes(a, b) ⇒ Object
- #releaf_table(collection, resource_class, options = {}) ⇒ Object
- #translate(key, options = {}) ⇒ Object (also: #t)
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 container, selected, prefix, ={} = { scope: controller_scope_name }.merge() translated_container = [] container.each do|element| text, value = i18n_option_text_and_value(element).map { |item| item.to_s } text = I18n.t("#{prefix}-#{text}", .merge(default: text)) translated_container << [text, value] end return (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, = {}) builder_class = [:builder] .delete(:builder) builder_class.new(collection, resource_class, self, ).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, = {}) # prevent I18n from raising errors when translation is missing .merge!(raise: false) unless .key?(:raise) super(key, ) end |