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