Class: Latexpdf::PdfGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/latexpdf/pdf_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tex) ⇒ PdfGenerator

Returns a new instance of PdfGenerator.



11
12
13
# File 'lib/latexpdf/pdf_generator.rb', line 11

def initialize(tex)
  @template = tex
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/latexpdf/pdf_generator.rb', line 9

def errors
  @errors
end

#pdf_fileObject (readonly)

Returns the value of attribute pdf_file.



9
10
11
# File 'lib/latexpdf/pdf_generator.rb', line 9

def pdf_file
  @pdf_file
end

#templateObject (readonly)

Returns the value of attribute template.



9
10
11
# File 'lib/latexpdf/pdf_generator.rb', line 9

def template
  @template
end

Instance Method Details

#cleanupObject



29
30
31
32
33
34
# File 'lib/latexpdf/pdf_generator.rb', line 29

def cleanup
  if File.directory?(build_path)
    FileUtils.remove_entry_secure(build_path)
  end
  @build_path = nil
end

#contentObject



40
41
42
# File 'lib/latexpdf/pdf_generator.rb', line 40

def content
  File.read(pdf_file) if pdf_exist?
end

#generate(target_file = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/latexpdf/pdf_generator.rb', line 15

def generate(target_file=nil)
  write_tex
  Latexpdf.configuration.passes.times do
    run_tex
  end

  if pdf_exist?
    @pdf_file = target_pdf_file
    FileUtils.cp target_pdf_file, target_file if target_file
  else
    raise LatexpdfError.new "Tex failed: No PDF generated"
  end
end

#pdf_exist?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/latexpdf/pdf_generator.rb', line 36

def pdf_exist?
  File.exist?(target_pdf_file)
end