Class: RTeX::Document

Inherits:
Object
  • Object
show all
Extended by:
Escaping
Defined in:
lib/rtex/document.rb

Defined Under Namespace

Classes: ExecutableNotFoundError, FilterError, GenerationError

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Escaping

escape, replacements, simple_format

Constructor Details

#initialize(content, options = {}) ⇒ Document

Returns a new instance of Document.



32
33
34
35
36
37
38
39
# File 'lib/rtex/document.rb', line 32

def initialize(content, options={})
  @options = self.class.options.merge(options)
  if @options[:processed]
    @source = content
  else
    @erb = ERB.new(content)
  end
end

Class Method Details

.optionsObject

Default options

:preprocess

Are we preprocessing? Default is false

:preprocessor

Executable to use during preprocessing (generating TOCs, etc). Default is latex

:shell_redirect

Option redirection for shell output (eg, “> /dev/null 2>&1” ). Default is nil.

:tmpdir

Location of temporary directory (default: Dir.tmpdir)



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rtex/document.rb', line 20

def self.options
  @options ||= {
    :preprocessor => 'latex',
    :preprocess => false,
    :processor => 'pdflatex',
    # 
    :shell_redirect => nil,
    # Temporary Directory
    :tempdir => Dir.tmpdir
  }
end

Instance Method Details

#filter(text) ⇒ Object

Process through defined filter



49
50
51
52
53
54
55
56
# File 'lib/rtex/document.rb', line 49

def filter(text) #:nodoc:
  return text unless @options[:filter]
  if (process = RTeX.filters[@options[:filter]])
    process[text]
  else
    raise FilterError, "No `#{@options[:filter]}' filter"
  end
end

#preprocessorObject

:nodoc:



79
80
81
# File 'lib/rtex/document.rb', line 79

def preprocessor #:nodoc:
  @preprocessor ||= check_path_for @options[:preprocessor]
end

#processorObject

:nodoc:



75
76
77
# File 'lib/rtex/document.rb', line 75

def processor #:nodoc:
  @processor ||= check_path_for @options[:processor]
end

#source(binding = nil) ⇒ Object

Get the source for the entire



42
43
44
45
46
# File 'lib/rtex/document.rb', line 42

def source(binding=nil) #:nodoc:
  @source ||= wrap_in_layout do
    filter @erb.result(binding)
  end
end

#system_pathObject

:nodoc:



83
84
85
# File 'lib/rtex/document.rb', line 83

def system_path #:nodoc:
  ENV['PATH']
end

#to_pdf(binding = nil, &file_handler) ⇒ Object

Generate PDF from call-seq:

to_pdf # => PDF in a String
to_pdf { |filename| ... }


71
72
73
# File 'lib/rtex/document.rb', line 71

def to_pdf(binding=nil, &file_handler)
  process_pdf_from(source(binding), &file_handler)
end

#wrap_in_layoutObject

Wrap content in optional layout



59
60
61
62
63
64
65
# File 'lib/rtex/document.rb', line 59

def wrap_in_layout #:nodoc:
  if @options[:layout]
    ERB.new(@options[:layout]).result(binding)
  else
    yield
  end
end