Skip to content

Commit

Permalink
adding executable
Browse files Browse the repository at this point in the history
  • Loading branch information
probablykabari committed Feb 23, 2010
1 parent b185712 commit d5bf7c6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
59 changes: 59 additions & 0 deletions bin/auto_excerpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env ruby

require "rubygems"
require "auto_excerpt"
require "optparse"

def perr(msg)
$stderr.puts(msg)
end

def dashed(key)
key.to_s.gsub('_','-')
end

@options = {}

options_parser = OptionParser.new do |o|
o.banner = "Usage: auto_excerpt [options] STRING|FILE"
o.separator ""

[
:characters,
:words,
:sentences,
:paragraphs,
:skip_words,
:skip_sentences,
:skip_paragraphs
].each do |key|
o.on("--#{dashed(key)} N", Integer){ |n| @options[key] = n }
end

[
:strip_html ,
:strip_breaks_tabs ,
:strip_paragraphs
].each do |key|
o.on("--#{dashed(key)}"){ |b| @options[key] = b }
end

o.on("--allowed_tags a,b,c", Array){|allowed| @options[:allowed_tags] = allowed }

o.on('--[no-]ending [STRING]'){ |s| @options[:ending] = s || nil }
o.on_tail('-h','--help'){ puts o; exit }
end

begin
options_parser.parse!(ARGV)
string_or_file = ARGV.last
raise(ArgumentError, "Please provide a STRING or FILE to parse.") unless string_or_file
string_or_file = File.read(string_or_file) if File.exist?(string_or_file)
puts AutoExcerpt.new(string_or_file, @options)
rescue => e
perr("Error: #{e.message}\n")
perr(e.backtrace)
exit(1)
end


1 change: 1 addition & 0 deletions lib/auto_excerpt/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Parser
# @option settings [Boolean] :strip_html (false) Strip all HTML from the text before creating the excerpt
# @option settings [Boolean] :strip_paragraphs (false) Strip all <p> tags from the HTML before creating the excerpt
def initialize(text, settings = {})
# undo this and change how settings are stored
@settings = Marshal.load(Marshal.dump(DEFAULTS)).merge(settings)

# make our copy
Expand Down

0 comments on commit d5bf7c6

Please sign in to comment.