Sha256: a2054aeef0471fe0a480b8737404555e176ef0de2b9c1fa9b742d215e6600892

Contents?: true

Size: 712 Bytes

Versions: 6

Compression:

Stored size: 712 Bytes

Contents

# frozen_string_literal: true

module Nanoc::Helpers
  # @see https://nanoc.app/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

6 entries across 6 versions & 1 rubygems

Version Path
nanoc-4.13.3 lib/nanoc/helpers/text.rb
nanoc-4.13.2 lib/nanoc/helpers/text.rb
nanoc-4.13.1 lib/nanoc/helpers/text.rb
nanoc-4.13.0 lib/nanoc/helpers/text.rb
nanoc-4.12.21 lib/nanoc/helpers/text.rb
nanoc-4.12.20 lib/nanoc/helpers/text.rb