2 # vim: fileencoding=UTF-8 ft=ruby syn=ruby ts=2 sw=2 ai eol et si
4 # Copyright (c) 2009 Jörg W Mittag <mailto:JoergWMittag+Akkordarbeit@GoogleMail.Com>
5 # Copyright (c) 2009 Marc Rummel <mailto:Marc.Rummel+Akkordarbeit@GoogleMail.Com>
6 # This code is licensed under the terms of the MIT License (see LICENSE.rdoc)
8 libdir
= File
.expand_path(File
.join File
.dirname(File
.expand_path(__FILE__
).gsub(/(.*)bin.*?/, '\1')), 'lib')
9 $LOAD_PATH.unshift libdir
unless $LOAD_PATH.include? libdir
12 require 'akkordarbeit'
18 @options = { :format => 'HTML', :input => $stdin, :output => $stdout }
19 @option_parser = OptionParser
.new
do |opts
|
20 opts
.banner
= 'Usage: akkordarbeit -f <FORMAT> -t <TITLE> -i <INPUT> -o <OUTPUT>'
21 opts
.on('-f', '--format [FORMAT]', 'Use output format <FORMAT> instead of HTML') do |format
|
22 @options[:format] = format
24 opts
.on
'-t', '--title [TITLE]', 'Use title instead of "Song-Sheet"' do |title
|
25 @options[:title] = title
27 opts
.on('-i', '--input [INPUTFILE]', 'Use Filename instead of STDIN') do |file
|
28 @options[:input] = open file
30 opts
.on('-o', '--output [OUTPUTFILE]', 'Use Filename instead of STDOUT') do |file
|
31 @options[:output] = open file
, 'w'
37 @option_parser.parse
! @args
38 parsetree
= Parser
.new
.parse
@options[:input].gets(nil)
39 output
= case @options[:format]
41 HtmlFormatter
.new
.format parsetree
, @options[:title]
43 TextFormatter
.new
.format parsetree
, @options[:title]
45 @options[:output].puts output
47 @options[:input].close
48 @options[:output].close