Module: Alveole::Helper::ComponentHelper
- Defined in:
- lib/alveole/helpers/method_helper.rb
Instance Method Summary collapse
- #component(name, *args, &block) ⇒ Object
- #format_value(value, options = {}) ⇒ Object
- #label_for(obj, fieldname) ⇒ Object
Instance Method Details
#component(name, *args, &block) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/alveole/helpers/method_helper.rb', line 4 def component(name, *args, &block) component_args = {} component_args = args.pop if args[-1].is_a? Hash component_args[:modifiers] = args unless args.empty? component_class = "#{name}_component".camelize.constantize render(component_class.new(**component_args), &block) end |
#format_value(value, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/alveole/helpers/method_helper.rb', line 13 def format_value(value, = {}) return if value.nil? v = value v = I18n.l(v.to_date, format: :short) if [:date] v = I18n.l(v.to_datetime, format: :short) if [:time] v end |
#label_for(obj, fieldname) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/alveole/helpers/method_helper.rb', line 23 def label_for(obj, fieldname) return unless obj && fieldname return obj.class.human_attribute_name(fieldname) if obj.class.respond_to?(:human_attribute_name) return obj.klass.human_attribute_name(fieldname) if obj.respond_to?(:klass) && obj.klass.respond_to?(:human_attribute_name) end |