2 # This program converts DocBook documents into .epub files.
 
   4 # Usage: dbtoepub [OPTIONS] [DocBook Files]
 
   6 # .epub is defined by the IDPF at www.idpf.org and is made up of 3 standards:
 
   7 # - Open Publication Structure (OPS)
 
   8 # - Open Packaging Format (OPF) 
 
   9 # - Open Container Format (OCF)
 
  12 #     -c, --css [FILE]                 Use FILE for CSS on generated XHTML.
 
  13 #     -d, --debug                      Show debugging output.
 
  14 #     -f, --font [OTF FILE]            Embed OTF FILE in .epub.
 
  15 #     -h, --help                       Display usage info.
 
  16 #     -s, --stylesheet [XSL FILE]      Use XSL FILE as a customization
 
  17 #                                        layer (imports epub/docbook.xsl).
 
  18 #     -v, --verbose                    Make output verbose.
 
  20 lib = File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
 
  21 $LOAD_PATH.unshift(lib) if File.exist?(lib)
 
  33 customization_layer = nil
 
  38 # Set up the OptionParser
 
  39 opts = OptionParser.new
 
  40 opts.banner = "Usage: #{File.basename($0)} [OPTIONS] [DocBook Files]
 
  42 #{File.basename($0)} converts DocBook <book> and <article>s into to .epub files.
 
  44 .epub is defined by the IDPF at www.idpf.org and is made up of 3 standards:
 
  45 - Open Publication Structure (OPS)
 
  46 - Open Packaging Format (OPF) 
 
  47 - Open Container Format (OCF)
 
  50 opts.on("-c", "--css [FILE]", "Use FILE for CSS on generated XHTML.") {|f| css_file = f}
 
  51 opts.on("-d", "--debug", "Show debugging output.") {debug = true; verbose = true}
 
  52 opts.on("-f", "--font [OTF FILE]", "Embed OTF FILE in .epub.") {|f| otf_files << f}
 
  53 opts.on("-h", "--help", "Display usage info.") {puts opts.to_s; exit 0}
 
  54 opts.on("-o", "--output [OUTPUT FILE]", "Output ePub file as OUTPUT FILE.") {|f| output_file = f}
 
  55 opts.on("-s", "--stylesheet [XSL FILE]", "Use XSL FILE as a customization layer (imports epub/docbook.xsl).") {|f| customization_layer = f}
 
  56 opts.on("-v", "--verbose", "Make output verbose.") {verbose = true}
 
  58 db_files = opts.parse(ARGV)
 
  64 db_files.each {|docbook_file|
 
  65   dir = File.expand_path(File.join(Dir.tmpdir, ".epubtmp#{Time.now.to_f.to_s}"))
 
  66   FileUtils.mkdir_p(dir)
 
  67   e = DocBook::Epub.new(docbook_file, dir, css_file, customization_layer, otf_files)
 
  70     epub_file = output_file
 
  72     epub_file = File.basename(docbook_file, ".xml") + ".epub"
 
  74   puts "Rendering DocBook file #{docbook_file} to #{epub_file}" if verbose
 
  75   e.render_to_file(epub_file)