Sha256: 2c22844243a0a49396ff070bfbba3765c8748ebf90e014d3b47b6abfc988a896

Contents?: true

Size: 1.81 KB

Versions: 9

Compression:

Stored size: 1.81 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 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

9 entries across 9 versions & 1 rubygems

Version Path
publishr-0.7.8 lib/publishr/latex_renderer.rb
publishr-0.7.7 lib/publishr/latex_renderer.rb
publishr-0.7.6 lib/publishr/latex_renderer.rb
publishr-0.7.5 lib/publishr/latex_renderer.rb
publishr-0.7.4 lib/publishr/latex_renderer.rb
publishr-0.7.3 lib/publishr/latex_renderer.rb
publishr-0.7.2 lib/publishr/latex_renderer.rb
publishr-0.7.1 lib/publishr/latex_renderer.rb
publishr-0.7.0 lib/publishr/latex_renderer.rb