auto_excerpt icon indicating copy to clipboard operation
auto_excerpt copied to clipboard

Ruby gem to generate excerpts from html formatted text. Great for blogs.

NO LONGER MAINTAINED. There are surely better tools for this out there now.

h1. AutoExcerpt

pre. [sudo] gem install auto_excerpt

Creates excerpts of html formatted text.

pre. AutoExcerpt.new("This is some fancy html formatted text homie", {:words => 5}) # => "This is some fancy html..."

h3. Features

  • There are 4 different ways to limit the length of an excerpt: characters, words, sentences, paragraphs
  • If the excerpt would be shorter than the limit that is set, the entire text will be shown.
  • If limiting by characters the gem will ensure that the excerpt does not cutoff in the middle of a word.
  • HTML can be stripped. You can also set specific tags that you don't want stripped.
  • HTML tags are automatically closed.

h3. Options

@:characters@ The number of characters to display from the text. Default: 150 (does not need to be set to 0 if you choose another option)

If you need to be 100% accurate in your character count, then remove the @:ending@

pre. AutoExcerpt.new("

Hello World!

", {:characters => 5, :ending => nil}) # =>

Hello

@:words@, @:sentences@, @:paragraphs@ The number of [which] to display from the text.

@:ending@ The text that will be displayed at the end of the excerpt when generating the excerpt by length or words. Set to @nil@ if you don't want it. Default: "..."

pre. AutoExcerpt.new("This is cool stuff man!", :ending => ". Srsly!", :words => 3) # => "This is cool. Srsly!"

@:strip_html@ Strips HTML tags from the excerpt that is displayed. Default: false

@:allowed_tags@ If using @:strip_html@ then this setting will allow the listed tags to be shown. default: []

pre. AutoExcerpt.new("

This is some formatted html

", {:strip_html => true, :allowed_tags => %w(p em)}) # => "

This is some formatted html

"

@:strip_paragraphs@ Strip all paragraph tags from the html. Default: false

@:skip_words@, @:skip_sentences@, @:skip_paragraphs@ The number of [which] to skip at the beginning of the html when returned. Default: 0

h3. Command Line

new: v0.7.1 Run @auto_excerpt@ from the command line with all of the options shown above! @$ auto_excerpt --words 10 "

Some html string

"@

h2. Help out on Github!

  • Fork the project.
  • Make your feature addition or bug fix.
  • Commit, do not mess with Rakefile, Version, or LICENSE.
  • Send me a pull request :)
  • Thanks for helping out!

h2. Credits

This is based on the rss_auto_excerpt plugin for Textpattern by the great "Rob Sable":http://www.wilshireone.com.

h3. Copyright

Copyright (c) 2010 Kabari Hendrick. See LICENSE for details.