Sha256: b41a017b5b9ab954ffde18818d21e8ac1c36e48f3728214ac0d668eaa8fb8e78

Contents?: true

Size: 912 Bytes

Versions: 31

Compression:

Stored size: 912 Bytes

Contents

require 'truncate_html'

module Refinery
  module Helpers
    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
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
refinerycms-core-1.0.11 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-1.0.10 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-1.0.9 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-1.0.8 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-1.0.7 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-1.0.5 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-1.0.4 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-1.0.3 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-1.0.1 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-1.0.0 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.22 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.21 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.20 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.19 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.18 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.17 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.16 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.15 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.14 lib/refinery/helpers/html_truncation_helper.rb
refinerycms-core-0.9.9.13 lib/refinery/helpers/html_truncation_helper.rb