Module: Nanoc::Helpers::Text
- Defined in:
- lib/nanoc/helpers/text.rb
Overview
Contains several useful text-related helper functions.
Instance Method Summary (collapse)
-
- (String) excerptize(string, params = {})
Returns an excerpt for the given string.
-
- (String) strip_html(string)
Strips all HTML tags out of the given string.
Instance Method Details
- (String) excerptize(string, params = {})
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.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nanoc/helpers/text.rb', line 19 def excerptize(string, params = {}) # Initialize params params[:length] ||= 25 params[:omission] ||= '...' # Get excerpt length = params[:length] - params[:omission].length length = 0 if length < 0 (string.length > params[:length] ? string[0...length] + params[:omission] : string) end |
- (String) strip_html(string)
Strips all HTML tags out of the given string.
35 36 37 38 |
# File 'lib/nanoc/helpers/text.rb', line 35 def strip_html(string) # FIXME: will need something more sophisticated than this, because it sucks string.gsub(/<[^>]*(>+|\s*\z)/m, '').strip end |