Method: SDoc::Helpers#truncate
- Defined in:
- lib/sdoc/helpers.rb
#truncate(text, options = {}) ⇒ Object
Truncates a given string. It tries to take whole sentences to have a meaningful description for SEO tags.
The only available option is :length which defaults to 200.
31 32 33 34 35 36 37 38 |
# File 'lib/sdoc/helpers.rb', line 31 def truncate(text, = {}) if text length = .fetch(:length, 200) stop = text.rindex(".", length - 1) || length "#{text[0, stop]}." end end |