Overview:
The HTML Truncator gem is designed to properly truncate HTML strings using the Nokogiri library in Ruby. With a simple installation process and straightforward implementation, this gem offers a solution for effectively shortening HTML content while maintaining its integrity.
Features:
- Simple Installation: Easily install the gem using RubyGems or add it to your Gemfile with bundler.
- Powerful Truncation Method: The
truncate method allows you to specify the HTML string, the number of words to keep, and optional settings like the ellipsis.
- Customizable Options: Adjust settings such as ellipsable tags, self-closing tags, and punctuation characters for tailored truncation.
- Ellipsis Placement: Ensures that the ellipsis is correctly positioned in the truncated HTML content.
- Handling of HTML Tags: Maintains tag structure integrity and avoids cutting words or leaving empty DOM nodes.
- Integration with Nokogiri: Compatible with Nokogiri-parsed HTML documents for seamless truncation of pre-parsed content.
- Debugging and Testing: Provides methods to check if a string has been truncated and allows for custom configurations to ignore specific elements like images.