Module: EtabliocmsCore::OutputHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/etabliocms_core/output_helper.rb

Instance Method Summary collapse

Instance Method Details

#html_out(string = "", options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'app/helpers/etabliocms_core/output_helper.rb', line 3

def html_out(string = "", options = {})
  string = RedCloth.new(string.to_s)
  string = string.to_html(:textile, :tags)
  string = truncate_and_strip_tags(string, options[:words].to_i) if options[:words]
  string = string.gsub(/\\|"/) { |c| "\\#{c}" } if options[:escape_double_quote]
  string.html_safe
end

#sanitized(string) ⇒ Object



11
12
13
# File 'app/helpers/etabliocms_core/output_helper.rb', line 11

def sanitized(string)
  simple_format(auto_link(h(string)))
end

#truncate_and_strip_tags(text, wordcount = 30, separator = "…") ⇒ Object



19
20
21
# File 'app/helpers/etabliocms_core/output_helper.rb', line 19

def truncate_and_strip_tags(text, wordcount = 30, separator = "…")
  truncate_words(strip_tags(text.to_s), wordcount, separator)
end

#truncate_and_strip_tags_from_textile(textile, wordcount = 30, separator = "…") ⇒ Object



23
24
25
# File 'app/helpers/etabliocms_core/output_helper.rb', line 23

def truncate_and_strip_tags_from_textile(textile, wordcount = 30, separator = "…")
  truncate_words(strip_tags(RedCloth.new(textile.to_s).to_html), wordcount, separator)
end

#truncate_words(text, wordcount = 30, separator = "…") ⇒ Object



15
16
17
# File 'app/helpers/etabliocms_core/output_helper.rb', line 15

def truncate_words(text, wordcount = 30, separator = "…")
  text.to_s.split[0..(wordcount-1)].join(" ") +(text.to_s.split.size > wordcount ? separator : "")
end

#w3c_date(date) ⇒ Object



27
28
29
# File 'app/helpers/etabliocms_core/output_helper.rb', line 27

def w3c_date(date)
  date.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00")
end