Class: RTeX::Document
- Inherits:
-
Object
- Object
- RTeX::Document
- Extended by:
- Escaping
- Defined in:
- lib/rtex/document.rb
Defined Under Namespace
Classes: ExecutableNotFoundError, FilterError, GenerationError
Class Method Summary collapse
-
.options ⇒ Object
Default options [
:preprocess
] Are we preprocessing? Default isfalse
[:preprocessor
] Executable to use during preprocessing (generating TOCs, etc).
Instance Method Summary collapse
-
#filter(text) ⇒ Object
Process through defined filter.
-
#initialize(content, options = {}) ⇒ Document
constructor
A new instance of Document.
-
#preprocessor ⇒ Object
:nodoc:.
-
#processor ⇒ Object
:nodoc:.
-
#source(binding = nil) ⇒ Object
Get the source for the entire.
-
#system_path ⇒ Object
:nodoc:.
-
#to_pdf(binding = nil, &file_handler) ⇒ Object
Generate PDF from call-seq: to_pdf # => PDF in a String to_pdf { |filename| … }.
-
#wrap_in_layout ⇒ Object
Wrap content in optional layout.
Methods included from Escaping
Constructor Details
#initialize(content, options = {}) ⇒ Document
Returns a new instance of Document.
35 36 37 38 39 40 41 42 |
# File 'lib/rtex/document.rb', line 35 def initialize(content, ={}) @options = self.class..merge() if @options[:processed] @source = content else @erb = ERB.new(content) end end |
Class Method Details
.options ⇒ Object
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
)
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rtex/document.rb', line 23 def self. @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
52 53 54 55 56 57 58 59 |
# File 'lib/rtex/document.rb', line 52 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 |
#preprocessor ⇒ Object
:nodoc:
82 83 84 |
# File 'lib/rtex/document.rb', line 82 def preprocessor #:nodoc: @preprocessor ||= check_path_for @options[:preprocessor] end |
#processor ⇒ Object
:nodoc:
78 79 80 |
# File 'lib/rtex/document.rb', line 78 def processor #:nodoc: @processor ||= check_path_for @options[:processor] end |
#source(binding = nil) ⇒ Object
Get the source for the entire
45 46 47 48 49 |
# File 'lib/rtex/document.rb', line 45 def source(binding=nil) #:nodoc: @source ||= wrap_in_layout do filter @erb.result(binding) end end |
#system_path ⇒ Object
:nodoc:
86 87 88 |
# File 'lib/rtex/document.rb', line 86 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| ... }
74 75 76 |
# File 'lib/rtex/document.rb', line 74 def to_pdf(binding=nil, &file_handler) process_pdf_from(source(binding), &file_handler) end |
#wrap_in_layout ⇒ Object
Wrap content in optional layout
62 63 64 65 66 67 68 |
# File 'lib/rtex/document.rb', line 62 def wrap_in_layout #:nodoc: if @options[:layout] ERB.new(@options[:layout]).result(binding) else yield end end |