Sha256: 6f5427f9dde398592436f5401f02360f8f445beca3ad91c71b895178234d4140

Contents?: true

Size: 857 Bytes

Versions: 28

Compression:

Stored size: 857 Bytes

Contents

require 'truncate_html'

module Refinery
  module HtmlTruncationHelper

    # Like the Rails _truncate_ helper but doesn't break HTML tags, entities, and words.
    # <script> tags pass through and are not counted in the total.
    # the omission specified _does_ count toward the total length count.
    # use :link => link_to('more', post_path), or something to that effect
    def truncate(text, options = {})
      return unless text.present?
      return super unless options.delete(:preserve_html_tags) == true # ensure preserve_html_tags doesn't pass through

      max_length = options[:length] || 30
      omission = options[:omission] || "..."

      return truncate_html(text,
                           :length => max_length,
                           :word_boundary => true,
                           :omission => omission)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
refinerycms-core-4.0.3 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-4.0.2 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-4.0.1 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-3.0.6 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-4.0.0 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-3.0.5 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-3.0.4 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-3.0.3 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-3.0.2 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-3.0.1 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-3.0.0 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-2.1.5 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-2.1.4 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-2.1.3 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-2.1.2 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-2.1.1 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-2.1.0 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-2.0.10 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-2.0.9 app/helpers/refinery/html_truncation_helper.rb
refinerycms-core-2.0.8 app/helpers/refinery/html_truncation_helper.rb