Class: Typstify::Resolver
- Inherits:
-
Object
- Object
- Typstify::Resolver
- Defined in:
- lib/typstify/resolver.rb
Overview
Turns a template name ("invoices/show") into a file on disk, and refuses to
look outside template_root while doing it.
This is the first of two containment layers. The second — and the one that actually matters — is the workspace: Typst compiles with the tmpdir as its root, so even a template that somehow got resolved elsewhere could not read past it. This layer exists to turn a traversal attempt into a clear error rather than a confusing "file not found".
Defined Under Namespace
Classes: Resolution
Constant Summary collapse
- EXTENSIONS =
Data mode wins: a directory holding both show.typ and show.typ.erb renders the safe one.
{ ".typ" => :data, ".typ.erb" => :erb }.freeze
Instance Method Summary collapse
- #call(name) ⇒ Resolution
-
#initialize(config = Typstify.config) ⇒ Resolver
constructor
A new instance of Resolver.
Constructor Details
Instance Method Details
#call(name) ⇒ Resolution
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/typstify/resolver.rb', line 31 def call(name) stem = name.to_s.sub(/\.typ(\.erb)?\z/, "") root = @config.template_root. tried = EXTENSIONS.keys.map { |ext| candidate(root, stem, ext) } EXTENSIONS.each_with_index do |(_ext, mode), index| path = tried[index] return Resolution.new(name: stem, path: path, mode: mode) if path.file? end raise MissingTemplate.new(name, tried) end |