Module: RailsCom::FormatHelper
- Defined in:
- app/helpers/rails_com/format_helper.rb
Instance Method Summary collapse
- #ex_simple_format(text, html_options = {}, options = {}) ⇒ Object
- #simple_format(text, html_options = {}, options = {}) ⇒ Object
- #simple_format_hash(hash_text, html_options = {}, options = {}) ⇒ Object
Instance Method Details
#ex_simple_format(text, html_options = {}, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/rails_com/format_helper.rb', line 18 def ex_simple_format(text, ={}, ={}) text = '' if text.nil? text = text.dup start_tag = tag('p', , true) text = sanitize(text) unless [:sanitize] == false text = text.to_str text.gsub!(/\n?/, "</p>\n#{start_tag}") text.insert 0, start_tag text.html_safe.safe_concat("</p>") end |
#simple_format(text, html_options = {}, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/rails_com/format_helper.rb', line 29 def simple_format(text, = {}, = {}) if text.is_a?(Hash) return simple_format_hash(text, , ) #elsif text.is_a?(String) #return ex_simple_format(text, html_options, options) end if text.is_a?(Array) begin hash_text = text.to_h return simple_format_hash(hash_text, , ) rescue TypeError return text.map { |t| content_tag(:p, t, ) }.join("\n").html_safe end end text = text.to_s super end |
#simple_format_hash(hash_text, html_options = {}, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/rails_com/format_helper.rb', line 4 def simple_format_hash(hash_text, = {}, = {}) wrapper_tag = .fetch(:wrapper_tag, :p) hash_text.map do |k, v| if k.to_s.rstrip.end_with?(':') text = k.to_s + ' ' + v.to_s else text = k.to_s + ': ' + v.to_s end content_tag(wrapper_tag, text, ) end.join("\n\n").html_safe end |