Skip to content

Latest commit

 

History

History
36 lines (19 loc) · 921 Bytes

README.rdoc

File metadata and controls

36 lines (19 loc) · 921 Bytes

NokogiriTruncateHtml

NokogiriTruncateHtml is just like the vanilla truncate rails helper, except it respects tags and html entities, and returns valid html.

Nokogiri and HtmlEntities are used for the parsing.

Inspired and heavily influenced by this article by Mike Burns and the links contained therein.

Usage

when post.title is

<p>This is <em>my <strong>first</strong> post</em></p>

Then

<%= truncate_html post.title, :length => 15 %>

results in

<p>This is <em>my <strong>fir&hellip;</strong></em></p>

Dependencies

Requires the htmlentities and nokogiri gems:

in Gemfile:

gem "nokogiri_truncate_html"

Specs and Coverage

  • Coverage is 100% (C0)

  • CI: tested against all 2.x branches of rails

RSpec is used for testing, so the tests are in spec/ rather than test/ Do rake –tasks for more details.