Class: Publishr::LatexRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/publishr/latex_renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, path, metadata) ⇒ LatexRenderer

Returns a new instance of LatexRenderer.



20
21
22
23
24
25
26
# File 'lib/publishr/latex_renderer.rb', line 20

def initialize(name,path,)
  @name = name
  @inpath = path
  @outpath = File.join(@inpath,'latex')
  @gempath = Publishr::Project.gempath
  @metadata = 
end

Instance Method Details

#make_tex_directory_structureObject



33
34
35
36
37
38
39
# File 'lib/publishr/latex_renderer.rb', line 33

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

#renderObject



28
29
30
31
# File 'lib/publishr/latex_renderer.rb', line 28

def render
  make_tex_directory_structure
  render_tex
end

#render_texObject



41
42
43
44
45
46
47
48
49
# File 'lib/publishr/latex_renderer.rb', line 41

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