Add support for song titles.
[Akkordarbeit.git] / bin / akkordarbeit
blobc2ae6f77cbb72afc9e77acefe6231daab7b94bb4
1 #!/usr/bin/env ruby
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
11 require 'optparse'
12 require 'akkordarbeit'
14 module Akkordarbeit
15 class Main
16 def initialize args
17 @args = args
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
23 end
24 opts.on '-t', '--title [TITLE]', 'Use title instead of "Song-Sheet"' do |title|
25 @options[:title] = title
26 end
27 opts.on('-i', '--input [INPUTFILE]', 'Use Filename instead of STDIN') do |file|
28 @options[:input] = open file
29 end
30 opts.on('-o', '--output [OUTPUTFILE]', 'Use Filename instead of STDOUT') do |file|
31 @options[:output] = open file, 'w'
32 end
33 end
34 end
36 def run!
37 @option_parser.parse! @args
38 parsetree = Parser.new.parse @options[:input].gets(nil)
39 output = case @options[:format]
40 when /html/i
41 HtmlFormatter.new.format parsetree, @options[:title]
42 when /text/i
43 TextFormatter.new.format parsetree, @options[:title]
44 end
45 @options[:output].puts output
46 ensure
47 @options[:input].close
48 @options[:output].close
49 end
51 def self.run!
52 new(ARGV).run!
53 end
54 end
56 Main.run!
57 end