def self.invalid?(file)
# Obnoxiously, we can't just check for a non-zero output...
- cmd = "#{CHECKER} #{file}"
+ cmd = %Q(#{CHECKER} "#{file}")
output = `#{cmd} 2>&1`
if $?.to_i == 0
html_stylesheet,
].join(" ")
# Double-quote stylesheet & file to help Windows cmd.exe
- db2epub_cmd = "cd #{@output_dir} && #{XSLT_PROCESSOR} #{options} \"#{@stylesheet}\" \"#{@collapsed_docbook_file}\""
+ db2epub_cmd = %Q(cd "#{@output_dir}" && #{XSLT_PROCESSOR} #{options} "#{@stylesheet}" "#{@collapsed_docbook_file}")
STDERR.puts db2epub_cmd if $DEBUG
success = system(db2epub_cmd)
raise "Could not render as .epub to #{output_file} (#{db2epub_cmd})" unless success
callouts = copy_callouts()
# zip -X -r ../book.epub mimetype META-INF OEBPS
# Double-quote stylesheet & file to help Windows cmd.exe
- zip_cmd = "cd \"#{@output_dir}\" && #{ZIPPER} #{quiet} -X -r \"#{File.expand_path(output_file)}\" \"#{mimetype_filename}\" \"#{meta}\" \"#{oebps}\""
+ zip_cmd = %Q(cd "#{@output_dir}" && #{ZIPPER} #{quiet} -X -r "#{File.expand_path(output_file)}" "#{mimetype_filename}" "#{meta}" "#{oebps}")
puts zip_cmd if $DEBUG
success = system(zip_cmd)
raise "Could not bundle into .epub file to #{output_file}" unless success
# were XIncluded or added by ENTITY
# http://sourceforge.net/tracker/?func=detail&aid=2750442&group_id=21935&atid=373747
def collapse_docbook
+ # Double-quote stylesheet & file to help Windows cmd.exe
collapsed_file = File.join(File.expand_path(File.dirname(@docbook_file)),
'.collapsed.' + File.basename(@docbook_file))
- entity_collapse_command = "xmllint --loaddtd --noent -o '#{collapsed_file}' '#{@docbook_file}'"
+ entity_collapse_command = %Q(xmllint --loaddtd --noent -o "#{collapsed_file}" "#{@docbook_file}")
entity_success = system(entity_collapse_command)
raise "Could not collapse named entites in #{@docbook_file}" unless entity_success
- xinclude_collapse_command = "xmllint --xinclude -o '#{collapsed_file}' '#{collapsed_file}'"
+ xinclude_collapse_command = %Q(xmllint --xinclude -o "#{collapsed_file}" "#{collapsed_file}")
xinclude_success = system(xinclude_collapse_command)
raise "Could not collapse XIncludes in #{@docbook_file}" unless xinclude_success
* XML Catalogs for DocBook 4.4 & 4.5 (this can be a pain)
* ruby 1.8+
* rspec version=1.1 http://rspec.info (gem install rspec --version 1.1)
-* zip
+* zip & unzip
* java
* epubcheck (1.0.5+) http://code.google.com/p/epubcheck/
Note: a standalone epubcheck command is just a shell script or .bat as:
FileUtils.copy(@epub_file, "." + File.basename(@xml_file, ".xml") + ".epub") if $DEBUG
@tmpdir2 = File.join(Dir::tmpdir(), "epubreal"); Dir.mkdir(@tmpdir2) rescue Errno::EEXIST
- success = system("unzip -q -o -d #{@tmpdir2} #{@epub_file}")
+ success = system(%Q(unzip -q -o -d "#{@tmpdir2}" "#{@epub_file}"))
raise "Could not unzip #{epub_file}" unless success
@html_files = Dir.glob(File.join(@tmpdir2, "**", "*.html"))
FileUtils.copy(epub_file, "./.t.epub") if $DEBUG
itemref_tmpdir = File.join(Dir::tmpdir(), "epubitemref"); Dir.mkdir(itemref_tmpdir) rescue Errno::EEXIST
- system("unzip -q -o -d #{itemref_tmpdir} #{epub_file}")
+ system(%Q(unzip -q -o -d "#{itemref_tmpdir}" "#{epub_file}"))
opf_file = File.join(itemref_tmpdir, "OEBPS", "content.opf")
opf = REXML::Document.new(File.new(opf_file))
epub.render_to_file(epubfile, $DEBUG)
FileUtils.copy(epubfile, ".re.ded.epub") if $DEBUG
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{epubfile}"))
raise "Could not unzip #{epubfile}" unless success
glob = Dir.glob(File.join(tmpdir, "**", "*.opf"))
index_html_links = glob.find_all {|opf_file| File.open(opf_file).readlines.to_s =~ /href=["']index.html["']/}
tmpdir = File.join(Dir::tmpdir(), "epubcssreg"); Dir.mkdir(tmpdir) rescue Errno::EEXIST
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{css_epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{css_epubfile}")
raise "Could not unzip #{css_epubfile}" unless success
opf_files = Dir.glob(File.join(tmpdir, "**", "*.opf"))
opf_files.find_all {|opf_file|
xhtml_dtd = "DTD XHTML 1.1"
itemref_tmpdir = File.join(Dir::tmpdir(), "epubitemref"); Dir.mkdir(itemref_tmpdir) rescue Errno::EEXIST
- system("unzip -q -o -d #{itemref_tmpdir} #{epub_file}")
+ system(%Q(unzip -q -o -d "#{itemref_tmpdir}" "#{epub_file}"))
opf_file = File.join(itemref_tmpdir, "OEBPS", "content.opf")
- xhtml_dtd_in_opf_file = system("grep '#{xhtml_dtd}' #{opf_file}")
+ xhtml_dtd_in_opf_file = system(%Q(grep "#{xhtml_dtd}" "#{opf_file}"))
xhtml_dtd_in_opf_file.should_not be_true
end
epubfile = File.join(tmpdir, shortname + ".epub")
epub.render_to_file(epubfile, $DEBUG)
FileUtils.copy(epubfile, "." + shortname + ".epub") if $DEBUG
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{File.expand_path(epubfile)}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{File.expand_path(epubfile)}"))
raise "Could not unzip #{epubfile}" unless success
container_file = File.join(tmpdir, 'META-INF', 'container.xml')
container_lines = File.open(container_file).readlines
epub.render_to_file(epubfile, $DEBUG)
FileUtils.copy(epubfile, ".b.epub") if $DEBUG
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{epubfile}"))
raise "Could not unzip #{epubfile}" unless success
glob = Dir.glob(File.join(tmpdir, "**", "*.html"))
glob.each {|html_file|
ncx_epubfile.should be_valid_epub
ncx_tmpdir = File.join(Dir::tmpdir(), "epubncx"); Dir.mkdir(ncx_tmpdir) rescue Errno::EEXIST
- system("unzip -q -o -d #{ncx_tmpdir} #{ncx_epubfile}")
+ system(%Q(unzip -q -o -d "#{ncx_tmpdir}" "#{ncx_epubfile}"))
ncx_file = File.join(ncx_tmpdir, "OEBPS", "toc.ncx")
ncx_default = '<ncx '
- ncx_in_default_ns = system("grep '#{ncx_default}' #{ncx_file}")
+ ncx_in_default_ns = system(%Q(grep "#{ncx_default}" "#{ncx_file}"))
ncx_in_default_ns.should be_true
end
begin
tmpdir = File.join(Dir::tmpdir(), "epubinclusiontest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{File.expand_path(@manygraphic_epubfile)}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o #{File.expand_path(@manygraphic_epubfile)}"))
raise "Could not unzip #{@manygraphic_epubfile}" unless success
glob = Dir.glob(File.join(tmpdir, "**", "*.*"))
pdfs_in_glob = glob.find_all {|file| file =~ /\.pdf/i}
begin
tmpdir = File.join(Dir::tmpdir(), "epubcsshtmltest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{@css_epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{@css_epubfile}"))
raise "Could not unzip #{@css_epubfile}" unless success
html_files = Dir.glob(File.join(tmpdir, "**", "*.html"))
html_links = html_files.find_all {|html_file| File.open(html_file).readlines.to_s =~ /<link [^>]*#{@css_file_base}/}
begin
tmpdir = File.join(Dir::tmpdir(), "epubcssfiletest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{@css_epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{@css_epubfile}"))
raise "Could not unzip #{@css_epubfile}" unless success
css_files = Dir.glob(File.join(tmpdir, "**", "*.css"))
css_files.should_not be_empty
begin
tmpdir = File.join(Dir::tmpdir(), "epubcsshtmltest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{@css_epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{@css_epubfile}"))
raise "Could not unzip #{@css_epubfile}" unless success
opf_files = Dir.glob(File.join(tmpdir, "**", "*.opf"))
opf_links = opf_files.find_all {|opf_file| File.open(opf_file).readlines.to_s =~ /<(opf:item|item) [^>]*#{@css_file_base}/}
begin
tmpdir = File.join(Dir::tmpdir(), "epubfontman"); Dir.mkdir(tmpdir) rescue Errno::EEXIST
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{@css_epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{@css_epubfile}"))
raise "Could not unzip #{@css_epubfile}" unless success
opf_files = Dir.glob(File.join(tmpdir, "**", "*.opf"))
begin
tmpdir = File.join(Dir::tmpdir(), "epubfontbundle"); Dir.mkdir(tmpdir) rescue Errno::EEXIST
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{@css_epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{@css_epubfile}"))
raise "Could not unzip #{@css_epubfile}" unless success
@embedded_fonts.each {|font|
font_files = Dir.glob(File.join(tmpdir, "**", File.basename(font)))
epub.render_to_file(epubfile, $DEBUG)
FileUtils.copy(epubfile, ".h1c.epub") if $DEBUG
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{epubfile}"))
raise "Could not unzip #{epubfile}" unless success
glob = Dir.glob(File.join(tmpdir, "**", "*.html"))
glob.each {|html_file|
epub.render_to_file(epubfile, $DEBUG)
FileUtils.copy(epubfile, ".h1c2.epub") if $DEBUG
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{epubfile}"))
raise "Could not unzip #{epubfile}" unless success
glob = Dir.glob(File.join(tmpdir, "**", "*.html"))
glob.each {|html_file|
epub.render_to_file(epubfile, $DEBUG)
FileUtils.copy(epubfile, ".tcl.epub") if $DEBUG
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{epubfile}"))
raise "Could not unzip #{epubfile}" unless success
glob = Dir.glob(File.join(tmpdir, "**", "*.opf"))
toc_links = glob.find_all {|opf_file| File.open(opf_file).readlines.to_s =~ /type=["']toc["']/}
epub.render_to_file(epubfile, $DEBUG)
FileUtils.copy(epubfile, ".cust.epub") if $DEBUG
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{epubfile}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{epubfile}"))
raise "Could not unzip #{epubfile}" unless success
glob = Dir.glob(File.join(tmpdir, "**", "*.html"))
# The customization layer changes the style of cross references to _not_
epubfile = File.join(tmpdir, shortname + ".epub")
epub.render_to_file(epubfile, $DEBUG)
FileUtils.copy(epubfile, "." + shortname + ".epub") if $DEBUG
- success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{File.expand_path(epubfile)}")
+ success = system(%Q(unzip -q -d "#{File.expand_path(tmpdir)}" -o "#{File.expand_path(epubfile)}"))
raise "Could not unzip #{epubfile}" unless success
opf_file = Dir.glob(File.join(tmpdir, "**", "*.opf")).first
opf_lines = File.open(opf_file).readlines