Class: Texd::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/texd/document.rb

Overview

Document handles compiling of templates into TeX sources.

Defined Under Namespace

Classes: Compilation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocument



13
14
15
16
# File 'lib/texd/document.rb', line 13

def initialize
  context      = LookupContext.new(Texd.config.lookup_paths)
  @attachments = AttachmentList.new(context)
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



6
7
8
# File 'lib/texd/document.rb', line 6

def attachments
  @attachments
end

Class Method Details

.compileObject

Shorthand for ‘new.compile`.



9
10
11
# File 'lib/texd/document.rb', line 9

def self.compile(**)
  new.compile(**)
end

Instance Method Details

#compile(template:, locals: {}, layout: true) ⇒ Compilation

Compile converts templates into TeX sources and collects file references (created with ‘texd_attach` and `texd_reference` helpers).



29
30
31
32
33
34
35
36
37
# File 'lib/texd/document.rb', line 29

def compile(template:, locals: {}, layout: true)
  helper_mod = ::Texd.helpers(attachments, locals)
  tex_source = Class.new(ApplicationController) {
    helper helper_mod
  }.render(template: template, format: :tex, layout: layout)

  main = attachments.main_input(tex_source)
  Compilation.new(main.name, attachments)
end