Class: Verku::Exporter::PDF

Inherits:
Base
  • Object
show all
Defined in:
lib/verku/exporter/pdf.rb

Constant Summary

Constants inherited from Base

Base::EXTENSIONS

Instance Attribute Summary

Attributes inherited from Base

#root_dir, #source

Instance Method Summary collapse

Methods inherited from Base

#base_name, #build_data, #config, #epub_file, export!, #git_branch, #handle_error, #html_file, #initialize, #name, #output_name, #read_content, #render_template, #source_list, #spawn_command, #tex_file, #ui

Constructor Details

This class inherits a constructor from Verku::Exporter::Base

Instance Method Details

#export!Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/verku/exporter/pdf.rb', line 7

def export!
  locals = config.merge({ :contents => content })
  locals['copyright'].gsub!("(C)", "\\copyright{}")
  output = render_template(root_dir.join("_templates/pdf/layout.erb"), locals)
  File.open(root_dir.join(tex_file), 'w').write(output)

  puts "-- Exporting PDF"
  puts "   - Pass 1"; spawn_command ["xelatex", tex_file.to_s,]
  puts "   - Pass 2"; spawn_command ["xelatex", tex_file.to_s,]

  if config['status'] == 'final'
    puts "   - Pass 3 - Indexing"
    spawn_command ["makeindex #{name}.idx"]
    spawn_command ["makeglossaries #{name}.glo"] if File.exist?("#{name}.glo")
    spawn_command ["xelatex", tex_file.to_s,]
    spawn_command ["rm *ilg *ind "]
  end

  spawn_command ["rm *.glo *.idx *.log *.out *.toc *aux *ist"]
  spawn_command ["mv #{base_name("pdf")}.pdf #{output_name("pdf")}"]
  true

rescue Exception => error
  handle_error(error)
  false
end