lib/softcover/builders/pdf.rb in softcover-0.7.11 vs lib/softcover/builders/pdf.rb in softcover-0.8.0

- old
+ new

@@ -26,31 +26,30 @@ return # only gets called in test env end polytex_filenames = manifest.pdf_chapter_filenames << book_filename polytex_filenames.each do |filename| - polytex = File.open(filename) { |f| f.read } + polytex = File.read(filename) latex = Polytexnic::Pipeline.new(polytex).to_latex if filename == book_filename latex.gsub!(/\\include{(.*?)}/) do "\\include{#{Softcover::Utils.tmpify(manifest, $1)}.tmp}" end end - File.open(Softcover::Utils.tmpify(manifest, filename), 'w') do |f| - f.write(latex) - end + File.write(Softcover::Utils.tmpify(manifest, filename), latex) end - write_pygments_file(:latex) + write_pygments_file(:latex, Softcover::Directories::STYLES) copy_polytexnic_sty # Renaming the PDF in the command is necessary because `execute` # below uses `exec` (except in tests, where it breaks). Since `exec` # causes the Ruby process to end, any Ruby code after `exec` # is ignored. # (The reason for using `exec` is so that LaTeX errors get emitted to # the screen rather than just hanging the process.) - cmd = "#{pdf_cmd(book_filename, options)} ; #{rename_pdf(basename)}" + cmd = "#{pdf_cmd(book_filename, options)} " + + "; #{rename_pdf(basename, options)}" # Here we use `system` when making a preview because the preview command # needs to run after the main PDF build. if options[:quiet] || options[:silent] silence_stream(STDERR) do silence { options[:preview] ? system(cmd) : execute(cmd) } @@ -104,22 +103,25 @@ # Returns the command to rename the temp PDF. # The purpose is to match the original filename. # For example, foo_bar.tex should produce foo_bar.pdf. # While we're at it, we move it to the standard ebooks/ directory. - def rename_pdf(basename) + def rename_pdf(basename, options={}) tmp_pdf = basename + '.tmp.pdf' pdf = basename + '.pdf' mkdir('ebooks') - "mv -f #{tmp_pdf} #{File.join('ebooks', pdf)}" + # Remove the intermediate tmp files unless only running once. + rm_tmp = options[:once] || Softcover.test? ? "" : "&& rm -f *.tmp.*" + "mv -f #{tmp_pdf} #{File.join('ebooks', pdf)} #{rm_tmp}" end - # Copies the PolyTeXnic style file to ensure it's always fresh. + # Copies the style file to ensure it's always fresh. def copy_polytexnic_sty - polytexnic_sty = 'softcover.sty' + softcover_sty = File.join(Softcover::Directories::STYLES, + 'softcover.sty') source_sty = File.join(File.dirname(__FILE__), - "../template/#{polytexnic_sty}") - FileUtils.cp source_sty, polytexnic_sty + '..', 'template', softcover_sty) + FileUtils.cp source_sty, softcover_sty end end end end \ No newline at end of file