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

Returns a new instance of Document.



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

.compile(**kwargs) ⇒ Object

Shorthand for ‘new.compile`.



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

def self.compile(**kwargs)
  new.compile(**kwargs)
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).

Parameters:

  • template (String)

    name of template file in ActionView’s lookup context.

  • locals (Hash, nil) (defaults to: {})

    will be made available as getter methods in the template.

  • layout (String, Boolean) (defaults to: true)

    to be used. String value name template files in ‘app/views/layouts`, `true` (default) uses the application layout, and `false` renders without a layout.

Returns:



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