Skip to content

rails helper that works just like truncate, but it respects, and produces well formed html

License

Notifications You must be signed in to change notification settings

galetahub/truncate_html

 
 

Repository files navigation

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.

About

rails helper that works just like truncate, but it respects, and produces well formed html

<a href="http://ianwhite.github.com/truncate_html">http://ianwhite.github.com/truncate_html</a>

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%