jorgemanrubia/truncato — pull request #3 by rewinfrey (2013-04-23 05:13:20+00:00)
Title: Adds tail_before_final_tag and comments features with specs / Updates README

Great library. Thanks for writing this. I pulled it into a project today I'm currently working on, but found I needed a few things that weren't supported by your parser.

1. Adds tail_before_final_tag feature (option set to false by default).
default behavior: `Truncato.truncate("

some textsome more text

", max_length: 4) => "

some...

"`
new behavior: `Truncato.truncate("

some textsome more text

", max_length: 4, tail_before_final_tag: true) => "

some...

"`
(admittedly, this is a very superficial feature, but is something I needed)

2. Adds comments feature (option set to false by default)
Currently Truncato doesn't support html comments. I looked over the Nokogiri::XML::SAX::Parser library and saw there is a comments hook. I added it for completeness.
default behavior: `Truncato.truncate("

some text

") => "

some text

"`
new behavior: `Truncato.truncate("

some text

", comments: true) => "

some text

"`

3. Correctly handles `
` and `` html tags.
Previously, `
` and `` tags were not handled correctly (an open and closing tag were applied to the names "br" and "img"
before: `Truncato.truncate("

some text

") => "

some text

"`
now: `Truncato.truncate("

some text

") => "

some text

"`

4. All features covered with specs

5. Corrects a filter spec to show that filtering works as intended

6. Updates README to include both features in the style of the current README

7. Fixes a typo in lib/truncato/truncato.rb, and handles parens around parameters uniformly throughout lib/truncato/truncato_sax_document.rb