# PublishR -- Fast publishing for ebooks and paper # Copyright (C) 2012 Michael Franzl # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . module Publishr class LatexRenderer def initialize(name,path,metadata) @name = name @inpath = path @outpath = File.join(@inpath,'latex') @gempath = Publishr::Project.gempath @metadata = metadata end def render make_tex_directory_structure render_tex end def make_tex_directory_structure FileUtils.mkdir_p @outpath FileUtils.cp Dir[File.join(@inpath,'images','*.jpg')], @outpath FileUtils.cp_r File.join(@gempath,'lib','tex_templates','book.tex'), @outpath FileUtils.cp_r File.join(@inpath,'book.tex'), @outpath if File.exists?(File.join(@inpath,'book.tex')) FileUtils.cp_r File.join(@inpath,'preamble.tex'), @outpath end def render_tex Dir[File.join(@inpath,'*.txt')].each do |infilepath| kramdown = File.open(infilepath, 'r').read latex = Kramdown::Document.new(kramdown, @metadata[:kramdown_options]).to_latex fixed_latex = LatexProcessor.new(latex,@inpath).fix outfilepath = File.join(@outpath, File.basename(infilepath).gsub(/(.*).txt/, '\1.tex')) File.open(outfilepath, 'w'){ |f| f.write fixed_latex } end end end end