Class: Typstify::Document
- Inherits:
-
Object
- Object
- Typstify::Document
- Defined in:
- lib/typstify/document.rb
Overview
The pipeline: resolve a template, build an isolated workspace, check fonts, compile, hand back bytes. Everything public in this gem funnels through here.
Instance Method Summary collapse
-
#initialize(template:, data: nil, assigns: {}, config: Typstify.config) ⇒ Document
constructor
A new instance of Document.
-
#to_pdf ⇒ String
PDF bytes, ASCII-8BIT.
Constructor Details
#initialize(template:, data: nil, assigns: {}, config: Typstify.config) ⇒ Document
Returns a new instance of Document.
7 8 9 10 11 12 |
# File 'lib/typstify/document.rb', line 7 def initialize(template:, data: nil, assigns: {}, config: Typstify.config) @template = template @data = data @assigns = assigns @config = config end |
Instance Method Details
#to_pdf ⇒ String
Returns PDF bytes, ASCII-8BIT.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/typstify/document.rb', line 15 def to_pdf # Validate first: a bad value should fail before we create a workspace, # let alone start the compiler. payload = @data.nil? ? nil : Data.dump(@data) resolution = Resolver.new(@config).call(@template) source = read_source(resolution) Workspace.build(source: source, data: payload, config: @config) do |workspace| check_fonts(workspace) Adapter.compile_pdf( main_path: workspace.main_path, root: workspace.dir, template: resolution.name, config: @config ) end end |