bin/stories2cards in pdf-storycards-0.0.1 vs bin/stories2cards in pdf-storycards-0.1.0
- old
+ new
@@ -7,35 +7,38 @@
#
# == Examples
# This command outputs a PDF consisting of one card for each story and
# narrative defined in stories.txt and saves it as stories.pdf
#
-# stories2cards stories.txt
+# stories2cards < stories.txt
#
# Other examples
#
-# stories2cards stories.txt -o /tmp/cards.pdf
-# stories2cards stories.txt --style=4up
+# stories2cards -o /tmp/cards.pdf < stories.txt
+# stories2cards --style=4up < stories.txt
#
# == Usage
-# stories2cards [options] text_file_with_stories
+# stories2cards [options] < text_file_with_stories
#
# For help use stories2cards -h
#
# == Options
# -h, --help Displays help message
# -v, --version Display the version, then exit
-# -o, --output=PATH Specify the path to the PDF file
-# to be created, defaults to storycards.pdf
+# -o, --output=PATH (optional) Specify the path to the PDF file
+# to be created, writes to stdout by default
# -s, --style=1up|4up Defaults to 1up
-# -b, --[no-]borders Print borders (only has effect with 4up style
+# -l, --lowerleft=key (optional) MetaData key for value to be printed in lower left
+# -r, --lowerright=key (optional) MetaData key for value to be printed in lower right
+# -b, --[no-]borders Print borders (only has effect with 4up style)
+# -m, --makesentences, Make english narratives into sentences
#
# == Author
# Luke Melia
#
# == Copyright
-# Copyright (c) 2007 Luke Melia. Licensed under the MIT License
+# Copyright (c) 2007-2008 Luke Melia. Licensed under the MIT License
# http://www.opensource.org/licenses/mit-license.php
require 'optparse'
require 'rdoc/usage'
require 'ostruct'
@@ -54,24 +57,25 @@
class App
attr_reader :options
- def initialize(arguments, stdin)
+ def initialize(arguments, stdin, stdout)
@arguments = arguments
@stdin = stdin
+ @stdout = stdout
# Set defaults
@options = OpenStruct.new
- @options.output = "storycards.pdf"
@options.style = :"1up"
end
# Parse options, check arguments, then process the command
def run
if parsed_options? && arguments_valid?
- process_arguments
+ process_arguments
+ @story_text = @stdin.read
process_command
else
output_usage
end
end
@@ -84,26 +88,27 @@
opts = OptionParser.new
opts.on('-v', '--version') { output_version ; exit 0 }
opts.on('-h', '--help') { output_help }
opts.on('-o', '--output [PATH]') { |path| @options.output = path }
opts.on('-s', '--style [STYLE]', [:"1up", :"4up"]) { |style| @options.style = style }
- opts.on("-b", "--[no-]borders", "Print borders") { |b| options.borders = b }
+ opts.on('-l', '--lowerleft [METADATA_KEY]') { |metadata_key| @options.lower_left = metadata_key }
+ opts.on('-r', '--lowerright [METADATA_KEY]') { |metadata_key| @options.lower_right = metadata_key }
+ opts.on("-b", "--[no-]borders", "Print borders") { |b| @options.borders = b }
+ opts.on('-m', '--makesentences', "Make english narratives into sentences") { |m| @options.make_sentences = m }
opts.parse!(@arguments) rescue return false
true
end
# True if required arguments were provided
def arguments_valid?
- return false unless @arguments.length == 1
- return false unless File.exists?(@arguments[0])
+ return false if @arguments.length > 0
return true
end
# Setup the arguments
def process_arguments
- @source_file = @arguments[0]
end
def output_help
output_version
RDoc::usage() #exits app
@@ -116,14 +121,20 @@
def output_version
puts "#{File.basename(__FILE__)} version #{PDF::Storycards::VERSION}"
end
def process_command
- style = :card_1up if @options.style == :"1up"
- style = :letter_4up if @options.style == :"4up"
- PDF::Storycards::Writer.make_pdf(@source_file, @options.output, :style => style)
+ @options.style = :card_1up if @options.style == :"1up"
+ @options.style = :letter_4up if @options.style == :"4up"
+ options_as_hash = @options.instance_variable_get('@table')
+ pdf_text = PDF::Storycards::Writer.make_pdf(@story_text, options_as_hash)
+ if @options.output
+ File.open(@options.output, 'w') {|f| f.write(pdf_text) }
+ else
+ @stdout.print pdf_text
+ end
end
- end
+end
# Create and run the application
-app = App.new(ARGV, STDIN)
+app = App.new(ARGV, $stdin, $stdout)
app.run