Sha256: bccd6e7e3e009ec1c5c56173b9c2d0c1d14f18ac296b5c0fee4769e9846fc5ca

Contents?: true

Size: 1.14 KB

Versions: 16

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Decidim
  # Main module to add application-wide helpers.
  module ApplicationHelper
    include Decidim::OmniauthHelper
    include Decidim::ScopesHelper

    # 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
      options[:tail_before_final_tag] ||= true

      Truncato.truncate(text, options)
    end

    def present(object)
      presenter = "#{object.class.name}Presenter".constantize.new(object)

      yield(presenter) if block_given?

      presenter
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
decidim-core-0.13.1 app/helpers/decidim/application_helper.rb
decidim-core-0.12.2 app/helpers/decidim/application_helper.rb
decidim-core-0.13.0 app/helpers/decidim/application_helper.rb
decidim-core-0.12.1 app/helpers/decidim/application_helper.rb
decidim-core-0.13.0.pre1 app/helpers/decidim/application_helper.rb
decidim-core-0.12.0 app/helpers/decidim/application_helper.rb
decidim-core-0.11.2 app/helpers/decidim/application_helper.rb
decidim-core-0.12.0.pre app/helpers/decidim/application_helper.rb
decidim-core-0.11.1 app/helpers/decidim/application_helper.rb
decidim-core-0.11.0.pre1 app/helpers/decidim/application_helper.rb
decidim-core-0.10.1 app/helpers/decidim/application_helper.rb
decidim-core-0.10.0 app/helpers/decidim/application_helper.rb
decidim-core-0.9.3 app/helpers/decidim/application_helper.rb
decidim-core-0.9.2 app/helpers/decidim/application_helper.rb
decidim-core-0.9.1 app/helpers/decidim/application_helper.rb
decidim-core-0.9.0 app/helpers/decidim/application_helper.rb