Sha256: 3d3d41157209d9554ad5f8d1d4be64e2cd9322913528321bf3b582d1a1d5be67

Contents?: true

Size: 900 Bytes

Versions: 7

Compression:

Stored size: 900 Bytes

Contents

# encoding: utf-8
# 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

7 entries across 7 versions & 1 rubygems

Version Path
decidim-core-0.1.0 app/helpers/decidim/application_helper.rb
decidim-core-0.0.8.1 app/helpers/decidim/application_helper.rb
decidim-core-0.0.7 app/helpers/decidim/application_helper.rb
decidim-core-0.0.6 app/helpers/decidim/application_helper.rb
decidim-core-0.0.3 app/helpers/decidim/application_helper.rb
decidim-core-0.0.2 app/helpers/decidim/application_helper.rb
decidim-core-0.0.1 app/helpers/decidim/application_helper.rb