Module: NokogiriTruncator::TextNode
- Defined in:
- lib/middleman-blog/truncate_html.rb
Instance Method Summary collapse
Instance Method Details
#truncate(max_length, ellipsis) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/middleman-blog/truncate_html.rb', line 51 def truncate(max_length, ellipsis) # Don't break in the middle of a word trimmed_content = content.match(/(.{1,#{max_length}}\w*)/m).to_s trimmed_content << ellipsis if trimmed_content.length < content.length Nokogiri::XML::Text.new(trimmed_content, parent) end |