Sha256: ce3eba9331ea4e5952490cc012c8e3f2fd50a429d60923b26aec7cb346b514de
Contents?: true
Size: 1.47 KB
Versions: 17
Compression:
Stored size: 1.47 KB
Contents
module Dorsale module TextHelper include ::ActionView::Helpers::TextHelper include ::ActionView::Helpers::SanitizeHelper def euros(n) return if n.nil? number(n) + " €" end def percentage(n) return if n.nil? number(n) + " %" end def number(n) return if n.nil? opts = {} if n.class.to_s.match(/Float|Decimal/i) opts[:precision] = 2 else opts[:precision] = 0 end opts[:delimiter] = I18n.t("number.format.delimiter") opts[:separator] = I18n.t("number.format.separator") number_with_precision(n, opts) end def date(d) return if d.nil? I18n.l(d) end def hours(n) return if n.nil? number = number_with_precision(n, precision: 2) text = I18n.t("datetime.prompts.hour").downcase text = text.pluralize if n > 1 "#{number} #{text}" end def text2html(str) return if str.to_s.blank? str = str.gsub("\r", "").strip strip_tags(str).gsub("\n", "<br />").html_safe end def info(object, attribute, text = nil) label = content_tag(:strong) do object.t(attribute) end span_css_class = "#{object.class.model_name.element}-#{attribute}" value = content_tag(:span, class: span_css_class) do ( text || object.send(attribute) ).to_s end content_tag(:div, class: "info") do "#{label} : #{value}".html_safe end end end end
Version data entries
17 entries across 17 versions & 1 rubygems