Class: TypstRails::Configuration

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

Overview

Configuration class for Typst rendering options.

This class holds configuration values that control how Typst documents are compiled and rendered. It provides validation to ensure configuration values are valid before use.

Examples:

Create and configure

config = TypstRails::Configuration.new
config.typst_executable_path = "/usr/local/bin/typst"
config.validate! # Ensures configuration is valid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initializes a new Configuration with default values.

Default values:

  • typst_executable_path: "typst" (assumes typst is in PATH)
  • default_root_path: nil (uses temporary directory)
  • backend: :auto (prefer the typst gem, fall back to the CLI)

Examples:

Create configuration with defaults

config = TypstRails::Configuration.new
config.typst_executable_path #=> "typst"
config.default_root_path #=> nil
config.backend #=> :auto


114
115
116
117
118
# File 'lib/typst_rails.rb', line 114

def initialize
  @typst_executable_path = "typst"
  @default_root_path = nil
  @backend = :auto
end

Instance Attribute Details

#backendSymbol, TypstRails::Backends::Base

Returns Which compilation backend to use. :auto (the default) prefers the typst gem when installed, otherwise falls back to shelling out to the typst CLI. Set to :gem or :cli to force a specific built-in backend, or assign a custom backend instance registered via Backends::Registry.register.

Returns:

  • (Symbol, TypstRails::Backends::Base)

    Which compilation backend to use. :auto (the default) prefers the typst gem when installed, otherwise falls back to shelling out to the typst CLI. Set to :gem or :cli to force a specific built-in backend, or assign a custom backend instance registered via Backends::Registry.register.



98
99
100
# File 'lib/typst_rails.rb', line 98

def backend
  @backend
end

#default_root_pathString?

Returns Default root path for Typst template resolution.

Returns:

  • (String, nil)

    Default root path for Typst template resolution



91
92
93
# File 'lib/typst_rails.rb', line 91

def default_root_path
  @default_root_path
end

#typst_executable_pathString

Returns Path to the Typst executable (defaults to "typst" in PATH).

Returns:

  • (String)

    Path to the Typst executable (defaults to "typst" in PATH)



88
89
90
# File 'lib/typst_rails.rb', line 88

def typst_executable_path
  @typst_executable_path
end

Instance Method Details

#validate!true

Validates the configuration settings.

Ensures that:

  • typst_executable_path is a non-empty string
  • default_root_path (if set) is a valid directory path

Examples:

Validate configuration

config = Configuration.new
config.typst_executable_path = ""
config.validate! # Raises ArgumentError

Returns:

  • (true)

    if configuration is valid

Raises:

  • (ArgumentError)

    if typst_executable_path is invalid

  • (ArgumentError)

    if default_root_path is invalid



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/typst_rails.rb', line 134

def validate! # rubocop:disable Naming/PredicateMethod -- bang method raises, doesn't predicate
  raise ArgumentError, "typst_executable_path must be a String" unless typst_executable_path.is_a?(String)

  raise ArgumentError, "typst_executable_path cannot be nil or empty" if typst_executable_path.empty?

  if default_root_path && !default_root_path.is_a?(String)
    raise ArgumentError, "default_root_path must be a String or nil"
  end

  true
end