Module: Trestle::FormatHelper
- Defined in:
- app/helpers/trestle/format_helper.rb
Instance Method Summary collapse
- #autoformat_value(value, options = {}) ⇒ Object
- #format_value(value, options = {}) ⇒ Object
- #format_value_from_options(value, options = {}) ⇒ Object
Instance Method Details
#autoformat_value(value, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/trestle/format_helper.rb', line 22 def autoformat_value(value, ={}) case value when Array content_tag(:ol, safe_join(value.map { |v| content_tag(:li, v.is_a?(Array) ? v : autoformat_value(v, )) }, "\n")) when Time, DateTime (value) when Date datestamp(value) when TrueClass, FalseClass status_tag(icon("fa fa-check"), :success) if value when NilClass blank = .key?(:blank) ? [:blank] : I18n.t("admin.format.blank") if blank.respond_to?(:call) instance_exec(&blank) else content_tag(:span, blank, class: "blank") end when String if value.html_safe? || [:truncate] == false value else truncate(value, [:truncate] || {}) end when ->(value) { value.respond_to?(:id) } display(value) else value end end |
#format_value(value, options = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'app/helpers/trestle/format_helper.rb', line 3 def format_value(value, ={}) if .key?(:format) (value, ) else autoformat_value(value, ) end end |
#format_value_from_options(value, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/trestle/format_helper.rb', line 11 def (value, ={}) case [:format] when :currency number_to_currency(value) when :tags safe_join(Array(value).map { |tag| content_tag(:span, tag, class: "tag") }) else value end end |