Module: Nanoc::Helpers::Text
- Defined in:
- lib/nanoc/helpers/text.rb
Overview
Contains several useful text-related helper functions.
Instance Method Summary collapse
-
#excerptize(string, length: 25, omission: '...') ⇒ String
Returns an excerpt for the given string.
-
#strip_html(string) ⇒ String
Strips all HTML tags out of the given string.
Instance Method Details
#excerptize(string, length: 25, omission: '...') ⇒ String
Returns an excerpt for the given string. HTML tags are ignored, so if you don’t want them to turn up, they should be stripped from the string before passing it to the excerpt function.
17 18 19 20 21 22 23 24 |
# File 'lib/nanoc/helpers/text.rb', line 17 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
Strips all HTML tags out of the given string.
31 32 33 34 |
# File 'lib/nanoc/helpers/text.rb', line 31 def strip_html(string) # FIXME: will need something more sophisticated than this, because it sucks string.gsub(/<[^>]*(>+|\s*\z)/m, '').strip end |