Sha256: f02cd9e3ea467d0917c90de1eecd9a15738cd1e386a5eb0958c3bef496b1ffd3

Contents?: true

Size: 710 Bytes

Versions: 43

Compression:

Stored size: 710 Bytes

Contents

# frozen_string_literal: true

module Nanoc::Helpers
  # @see http://nanoc.ws/doc/reference/helpers/#text
  module Text
    # @param [String] string
    # @param [Number] length
    # @param [String] omission
    #
    # @return [String]
    def excerptize(string, length: 25, omission: '...')
      if string.length > length
        excerpt_length = [0, length - omission.length].max
        string[0...excerpt_length] + omission
      else
        string
      end
    end

    # @param [String] string
    #
    # @return [String]
    def strip_html(string)
      # FIXME: will need something more sophisticated than this, because it sucks
      string.gsub(/<[^>]*(>+|\s*\z)/m, '').strip
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
nanoc-4.11.2 lib/nanoc/helpers/text.rb
nanoc-4.11.1 lib/nanoc/helpers/text.rb
nanoc-4.11.0 lib/nanoc/helpers/text.rb
nanoc-4.10.4 lib/nanoc/helpers/text.rb
nanoc-4.10.3 lib/nanoc/helpers/text.rb
nanoc-4.10.2 lib/nanoc/helpers/text.rb
nanoc-4.10.1 lib/nanoc/helpers/text.rb
nanoc-4.10.0 lib/nanoc/helpers/text.rb
nanoc-4.9.9 lib/nanoc/helpers/text.rb
nanoc-4.9.8 lib/nanoc/helpers/text.rb
nanoc-4.9.7 lib/nanoc/helpers/text.rb
nanoc-4.9.6 lib/nanoc/helpers/text.rb
nanoc-4.9.5 lib/nanoc/helpers/text.rb
nanoc-4.9.4 lib/nanoc/helpers/text.rb
nanoc-4.9.3 lib/nanoc/helpers/text.rb
nanoc-4.9.2 lib/nanoc/helpers/text.rb
nanoc-4.9.1 lib/nanoc/helpers/text.rb
nanoc-4.9.0 lib/nanoc/helpers/text.rb
nanoc-4.8.19 lib/nanoc/helpers/text.rb
nanoc-4.8.18 lib/nanoc/helpers/text.rb