Module: Nanoc::Helpers::Text

Defined in:
lib/nanoc/helpers/text.rb

Overview

Instance Method Summary collapse

Instance Method Details

#excerptize(string, length: 25, omission: '...') ⇒ String

Parameters:

  • string (String)
  • length (Number)
  • omission (String)

Returns:

  • (String)


9
10
11
12
13
14
15
16
# File 'lib/nanoc/helpers/text.rb', line 9

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

#strip_html(string) ⇒ String

Parameters:

  • string (String)

Returns:

  • (String)


21
22
23
24
# File 'lib/nanoc/helpers/text.rb', line 21

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