Sha256: 2b72f58df4cecae718b99d35a7266115c8680eb18e02e81550a573ed19f1f013

Contents?: true

Size: 1.88 KB

Versions: 11

Compression:

Stored size: 1.88 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 Dir[File.join(@inpath,'images','*.eps')], @outpath
      FileUtils.cp_r File.join(@gempath,'lib','tex_templates','book.tex'), @outpath
      FileUtils.cp_r Dir[File.join(@inpath,'*.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,File.basename(infilepath)).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

11 entries across 11 versions & 1 rubygems

Version Path
publishr-0.8.9 lib/publishr/latex_renderer.rb
publishr-0.8.8 lib/publishr/latex_renderer.rb
publishr-0.8.7 lib/publishr/latex_renderer.rb
publishr-0.8.6 lib/publishr/latex_renderer.rb
publishr-0.8.5 lib/publishr/latex_renderer.rb
publishr-0.8.4 lib/publishr/latex_renderer.rb
publishr-0.8.3 lib/publishr/latex_renderer.rb
publishr-0.8.2 lib/publishr/latex_renderer.rb
publishr-0.8.1 lib/publishr/latex_renderer.rb
publishr-0.8.0 lib/publishr/latex_renderer.rb
publishr-0.7.9 lib/publishr/latex_renderer.rb