Method: Decidim::ApplicationHelper#html_truncate

Defined in:
decidim-core/app/helpers/decidim/application_helper.rb

#html_truncate(text, options = {}) ⇒ Object

Truncates a given text respecting its HTML tags.

text - The String text to be truncated. options - A Hash with the options to truncate the text (default: {}):

:length - An Integer number with the max length of the text.
:separator - A String to append to the text when it is being
truncated.

Returns a String.



25
26
27
28
29
30
31
32
33
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 25

def html_truncate(text, options = {})
  options[:max_length] = options.delete(:length) || options[:max_length]
  options[:tail] = options.delete(:separator) || options[:tail] || ""
  options[:count_tags] ||= false
  options[:count_tail] ||= false
  options[:tail_before_final_tag] = true unless options.has_key?(:tail_before_final_tag)

  Decidim::HtmlTruncation.new(text, options).perform
end