Class: TypstRails::Backends::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/typst_rails/backends/base.rb

Overview

This class is abstract.

Abstract interface for a Typst compilation backend.

A backend is responsible for turning a Typst source file (plus a root directory for relative imports) into PDF bytes. Subclasses implement #available? and #compile.

Direct Known Subclasses

Cli, Gem

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Returns whether this backend can be used in the current environment (e.g. the typst executable is on PATH, or the typst gem is loaded).

Returns:

  • (Boolean)

    whether this backend can be used in the current environment (e.g. the typst executable is on PATH, or the typst gem is loaded)

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/typst_rails/backends/base.rb', line 15

def available?
  raise NotImplementedError, "#{self.class} must implement #available?"
end

#compile(typ_path, root_dir) ⇒ String

Compiles a Typst source file to PDF.

Parameters:

  • typ_path (String)

    path to the .typ source file to compile

  • root_dir (String)

    root directory for resolving relative imports

Returns:

  • (String)

    binary PDF data

Raises:



25
26
27
# File 'lib/typst_rails/backends/base.rb', line 25

def compile(typ_path, root_dir)
  raise NotImplementedError, "#{self.class} must implement #compile"
end