Created
May 15, 2009 15:17
-
-
Save panterch/112246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
require 'tempfile' | |
class Pdflatex | |
TEMPLATE_DIR = File.join(RAILS_ROOT, 'app', 'views', 'tex') | |
def self.run(template_path, locals = nil) | |
template = File.new(template_path).read | |
erb = ERB.new(template) | |
tex = Tempfile.new('pdflatex', WORK_DIR) | |
tex.puts erb.result(binding) | |
tex.flush | |
cmd = "pdflatex -interaction batchmode " + | |
" -output-directory #{File.dirname(tex.path)} #{tex.path}" | |
res = `#{cmd}` | |
unless (0 == $?.to_i) | |
raise "could not transform using #{cmd}: #{res}" | |
end | |
tex.path + '.pdf' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment