Sha256: e84014d5555e30d25599eb960de45a9dc319ee96ecccbd59832fd18ad8527037

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

# 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 <http://www.gnu.org/licenses/>.

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
publishr-0.6.7 lib/publishr/latex_renderer.rb
publishr-0.6.6 lib/publishr/latex_renderer.rb
publishr-0.6.5 lib/publishr/latex_renderer.rb