Sha256: a86e3f030de37e0fdac2f023f7e7659545e39312ea4bd912ba7140e914de41bb

Contents?: true

Size: 883 Bytes

Versions: 4

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # Main module to add application-wide helpers.
  module ApplicationHelper
    # 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's being
    #           truncated. See `truncato` gem for more options.
    #
    # Returns a String.
    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

      Truncato.truncate(text, options)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-core-0.3.2 app/helpers/decidim/application_helper.rb
decidim-core-0.3.1 app/helpers/decidim/application_helper.rb
decidim-core-0.3.0 app/helpers/decidim/application_helper.rb
decidim-core-0.2.0 app/helpers/decidim/application_helper.rb