typst-rails 0.1.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +191 -1
- data/README.md +347 -33
- data/lib/typst-rails.rb +7 -0
- data/lib/typst_rails/backends/base.rb +24 -1
- data/lib/typst_rails/backends/cli.rb +47 -12
- data/lib/typst_rails/backends/gem.rb +19 -2
- data/lib/typst_rails/data_serializer.rb +294 -0
- data/lib/typst_rails/diagnostics.rb +284 -0
- data/lib/typst_rails/erb_source.rb +36 -0
- data/lib/typst_rails/errors.rb +139 -0
- data/lib/typst_rails/framework_detection.rb +13 -4
- data/lib/typst_rails/handler.rb +51 -9
- data/lib/typst_rails/helpers.rb +26 -112
- data/lib/typst_rails/markdown_converter.rb +248 -0
- data/lib/typst_rails/rage_integration.rb +55 -8
- data/lib/typst_rails/rails_rendering.rb +58 -0
- data/lib/typst_rails/railtie.rb +7 -0
- data/lib/typst_rails/renderer.rb +223 -107
- data/lib/typst_rails/sinatra_integration.rb +11 -12
- data/lib/typst_rails/template_rendering.rb +252 -0
- data/lib/typst_rails/version.rb +1 -1
- data/lib/typst_rails/view_helpers.rb +28 -0
- data/lib/typst_rails.rb +140 -5
- metadata +12 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 799ef6d2c13a142d9aff9884073aabc53230ea685ec6a27c9295b80b2f259ff9
|
|
4
|
+
data.tar.gz: ce7de50ed456972f529e5b2b7920c86a791a1eab5130d2e69a0f388f42b78044
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3fd3d9e3584ad621410d63685f519104a4cd418b88a187af2a0a3d1b1a0ca779d9cff6cfaa4be10fcfe84f4acb84366d360b26b8436c3ede081111d31e84394
|
|
7
|
+
data.tar.gz: a89f2235008b19da770761bc9abf19e5adb9368dc2961b52c99822c8af9f6a5958d60d289dee65596fd7429221b437d62c97b2e3696cd7e0482391473efaff1a
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,96 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.2] - 2026-11-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `config.pdf_standard` to have Typst enforce PDF standards such as PDF/UA-1
|
|
14
|
+
(`:ua_1`) and PDF/A (`:a_2b` and others). Accepts a symbol or an array of
|
|
15
|
+
symbols, and works with both the CLI and gem backends. PDF/UA-1 requires the
|
|
16
|
+
template to set a document title.
|
|
17
|
+
- `config.font_paths` to add directories that Typst searches for fonts, and
|
|
18
|
+
`config.ignore_system_fonts` to skip the system's fonts. Both backends pass
|
|
19
|
+
them to Typst: the CLI as `--font-path` and `--ignore-system-fonts`, the
|
|
20
|
+
`typst` gem as its `font_paths:` and `ignore_system_fonts:` options.
|
|
21
|
+
- `TypstRails::Configuration#compile_options`, the compiler options that
|
|
22
|
+
backends pass through to Typst.
|
|
23
|
+
- `TypstRails::CompileError`, a subclass of `TypstRails::Error`, raised when
|
|
24
|
+
Typst rejects a template. It carries the parsed diagnostics (severity,
|
|
25
|
+
message, path, line, column, hints), the line and column of the first
|
|
26
|
+
error, the template's name, the offending source line, Typst's output, and,
|
|
27
|
+
for the CLI backend, the command that was run.
|
|
28
|
+
- `TypstRails::Renderer.new` accepts an optional `template:` name. The Rails
|
|
29
|
+
handler passes the view's path, and the Sinatra and Rage helpers pass the
|
|
30
|
+
template path, so errors name the template instead of a temporary file.
|
|
31
|
+
- `config.on_warning`, called with the warnings from a successful CLI
|
|
32
|
+
compile and the template's name. By default it logs them. The `typst` gem
|
|
33
|
+
does not expose warnings on success, so it is not called for the `:gem`
|
|
34
|
+
backend.
|
|
35
|
+
- `TypstRails.render(template, locals:, assigns:, root:)` renders a `.typ`
|
|
36
|
+
template file to PDF outside a request, for background jobs, mailers, and
|
|
37
|
+
scripts. The template runs through ERB, then compiles, with locals and
|
|
38
|
+
assigns also written to `typst_data.json`. Relative paths resolve against
|
|
39
|
+
`app/views` in Rails and the current directory elsewhere, the `.typ`
|
|
40
|
+
extension is optional, and paths that lead outside the root raise
|
|
41
|
+
`ArgumentError`.
|
|
42
|
+
- `TypstRails.render_with_rails(template, locals:, assigns:, controller:)`
|
|
43
|
+
renders a `.typ` view through a Rails controller, so app helpers, route
|
|
44
|
+
helpers, and partials work outside a request. It raises
|
|
45
|
+
`TypstRails::Error` when ActionController is not loaded.
|
|
46
|
+
- `TypstRails.render_and_attach(attachable, template, filename:, ...)`
|
|
47
|
+
renders a template and passes the PDF to `attachable.attach`, such as an
|
|
48
|
+
ActiveStorage attachment. Pass `via: :rails` to render through
|
|
49
|
+
`render_with_rails`.
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
- Compile error messages name the template and the location of the first
|
|
53
|
+
error, and replace paths into the render's temporary directory with the
|
|
54
|
+
template's name or root-relative paths. The full command line is no longer
|
|
55
|
+
part of the message; it is available as `CompileError#command`.
|
|
56
|
+
- Warnings printed by a successful CLI compile are no longer discarded.
|
|
57
|
+
- **Behavior change:** a local whose value has no faithful JSON form now
|
|
58
|
+
raises `TypstRails::SerializationError` (a subclass of `TypstRails::Error`)
|
|
59
|
+
when the template reads `typst_data.json`. The message names the key path,
|
|
60
|
+
such as `locals.line_items[0].amount is a Money, which is not
|
|
61
|
+
JSON-serializable`, and says how to fix it. Such values used to reach the
|
|
62
|
+
template as `{}`, a dump of the object's instance variables, or its `#to_s`,
|
|
63
|
+
depending on whether ActiveSupport was loaded. Rejected values include plain
|
|
64
|
+
objects without their own `as_json` or `to_h`, Procs, IO objects,
|
|
65
|
+
Rationals, NaN and Infinity, strings with no valid UTF-8 form, and Hashes
|
|
66
|
+
with keys other than Strings, Symbols or numbers.
|
|
67
|
+
- An instance variable with no faithful JSON form is left out of
|
|
68
|
+
`typst_data.json`, with one warning per render (to `Rails.logger` when
|
|
69
|
+
present) naming each variable and the path of the offending value. Instance
|
|
70
|
+
variables whose names begin with an underscore are no longer written at all.
|
|
71
|
+
- Values in `typst_data.json` are converted by the new
|
|
72
|
+
`TypstRails::DataSerializer`: Symbols and Hash keys become strings, Sets
|
|
73
|
+
become arrays, BigDecimals become decimal strings, Structs and `Data`
|
|
74
|
+
objects become objects via `to_h`, and other objects are used only when
|
|
75
|
+
their class defines `as_json` or `to_h` itself. The private
|
|
76
|
+
`Renderer#transform_value_for_json_serialization` now delegates to it, and
|
|
77
|
+
the private `active_record_value?` check is gone: models and relations are
|
|
78
|
+
handled through their own `as_json`.
|
|
79
|
+
- Data for templates that do not mention `typst_data.json` is no longer
|
|
80
|
+
converted at all, so it cannot raise.
|
|
81
|
+
- The Sinatra `typst` and Rage `render_typst` helpers now share the template
|
|
82
|
+
rendering code behind `TypstRails.render`. Their behavior is unchanged.
|
|
83
|
+
|
|
84
|
+
### Fixed
|
|
85
|
+
- `gem "typst-rails"` in a Gemfile now loads the library. Bundler.require
|
|
86
|
+
requires "typst-rails", but the entry point was only `typst_rails.rb`, so
|
|
87
|
+
Rails apps loaded `version.rb` and nothing else: the Railtie never ran and
|
|
88
|
+
`.typ` views failed with `ActionView::MissingTemplate`. The workaround,
|
|
89
|
+
`require: "typst_rails"`, is no longer needed.
|
|
90
|
+
- `.typ` partials rendered from a `.typ` view no longer compile to a PDF of
|
|
91
|
+
their own. Only the outermost `.typ` template compiles; nested ones return
|
|
92
|
+
their ERB-processed Typst source to be spliced into the parent.
|
|
93
|
+
- Times passed as locals to a render without a view context (as with
|
|
94
|
+
`Renderer.new(source).render(nil, locals)`) are now ISO 8601 strings, as they
|
|
95
|
+
already were with a view context. They were written with `Time#to_s` when
|
|
96
|
+
ActiveSupport was not loaded.
|
|
97
|
+
|
|
98
|
+
## [0.2.1] - 2026-11-14
|
|
99
|
+
|
|
10
100
|
### Added
|
|
11
101
|
- Swappable Typst compilation backends: a `:cli` backend (shells out to the
|
|
12
102
|
Typst executable, the original behavior) and a `:gem` backend (uses the
|
|
@@ -14,7 +104,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
14
104
|
automatically via `TypstRails::Backends::Registry` or set explicitly with
|
|
15
105
|
`TypstRails.configure { |c| c.backend = :gem }`. Custom backends can be
|
|
16
106
|
registered for other compilation strategies.
|
|
17
|
-
- Docker-based end-to-end tests (`e2e-docker/`, `rake e2e:docker`) covering
|
|
107
|
+
- Docker-based end-to-end tests (`e2e-tests/docker/`, `rake e2e:docker`) covering
|
|
18
108
|
the backend auto-detection matrix (CLI-only, gem-only, both, neither) and a
|
|
19
109
|
fresh `gem build` + `gem install` smoke test, independent of the local dev
|
|
20
110
|
environment.
|
|
@@ -29,7 +119,97 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
29
119
|
- Enhanced gemspec description with clearer value proposition
|
|
30
120
|
- Updated author email to commercial@durableprogramming.com
|
|
31
121
|
|
|
122
|
+
### Removed
|
|
123
|
+
- **Breaking:** the `sanitize_html` helper, along with the
|
|
124
|
+
`DEFAULT_ALLOWED_TAGS` and `DEFAULT_ALLOWED_ATTRIBUTES` constants. Nothing in
|
|
125
|
+
the gem called it: `html_to_typst` never sanitized its input, so this was an
|
|
126
|
+
opt-in helper that duplicated, less thoroughly, what dedicated sanitizers
|
|
127
|
+
already do. Callers who need it should use ActionView's `sanitize` helper,
|
|
128
|
+
the Rails::HTML sanitizers, Loofah, or the `sanitize` gem. Note that HTML
|
|
129
|
+
sanitization was never sufficient here in any case: it strips dangerous HTML,
|
|
130
|
+
but the surviving text still reaches a Typst document where `#`, `$`, `[`,
|
|
131
|
+
and `@` are syntactically meaningful. See SECURITY.md.
|
|
132
|
+
|
|
32
133
|
### Fixed
|
|
134
|
+
- Rage integration now works. It previously called an empty `Rage.configure`
|
|
135
|
+
block and registered nothing. Rage has no template handlers, so
|
|
136
|
+
`RageController::API` now gains `render_typst(template, locals, status:)`,
|
|
137
|
+
which runs the template through ERB and responds with the PDF.
|
|
138
|
+
- The Sinatra `typst` helper now runs templates through ERB, with the route's
|
|
139
|
+
instance variables, the `TypstRails::Helpers` methods, and the locals hash
|
|
140
|
+
in scope. It previously passed the file to Typst unprocessed, so data could
|
|
141
|
+
reach the template only through `typst_data.json`.
|
|
142
|
+
- `TypstRails::Helpers` is now available in Rails views. It was mixed only
|
|
143
|
+
into `Renderer`, but `.typ` templates evaluate their ERB in the view
|
|
144
|
+
context, so `escape_typst` raised `NoMethodError` there. Views keep
|
|
145
|
+
ActionView's `url_encode`.
|
|
146
|
+
- `typst_data.json` is written only when the template source mentions it.
|
|
147
|
+
Every controller instance variable, including whole ActiveRecord models,
|
|
148
|
+
was previously serialized to disk on each render, whether or not the
|
|
149
|
+
template read it.
|
|
150
|
+
- `default_root_path` now sets the Typst root. It was validated but never
|
|
151
|
+
read, so templates could not load files from the application. It also
|
|
152
|
+
accepts a `Pathname`; the README's `Rails.root.join(...)` example raised
|
|
153
|
+
`ArgumentError`.
|
|
154
|
+
- `markdown_to_typst` (and so `html_to_typst` and `include_markdown`) let
|
|
155
|
+
link and image URLs close the Typst string they were written into. A `"`
|
|
156
|
+
in a URL broke compilation, and a crafted URL could add Typst code to the
|
|
157
|
+
document. URLs are now written as escaped string literals, and link titles
|
|
158
|
+
(`[x](url "title")`) are dropped instead of being pasted into the URL.
|
|
159
|
+
- `markdown_to_typst` passed ordinary text through as Typst syntax, so
|
|
160
|
+
`#hashtag` ran as code, `$5 or $10` became math, `me@example.com` became a
|
|
161
|
+
reference, and an unmatched `**` or `_` opened emphasis. Text is now escaped
|
|
162
|
+
with `escape_typst`, and only the Markdown the converter recognizes becomes
|
|
163
|
+
Typst markup. This changes output for text that was previously passed
|
|
164
|
+
through raw: Typst markup given to `markdown_to_typst` is now escaped
|
|
165
|
+
rather than kept.
|
|
166
|
+
- `markdown_to_typst` now honors Markdown backslash escapes (`\*`, `\#`,
|
|
167
|
+
`\[`, and a trailing `# Changelog
|
|
168
|
+
|
|
169
|
+
All notable changes to this project will be documented in this file.
|
|
170
|
+
|
|
171
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
172
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
173
|
+
|
|
174
|
+
as a hard line break) and converts autolinks
|
|
175
|
+
(`<https://...>`).
|
|
176
|
+
- `markdown_to_typst` converts `*` and `+` bullets to `-`. Typst has no `*`
|
|
177
|
+
bullet (the line became bold text), and its `+` makes a numbered item.
|
|
178
|
+
Ordered items written `1)` become `1.`.
|
|
179
|
+
- Text right after a converted link or image, such as `(note)` or `.field`,
|
|
180
|
+
is no longer read by Typst as part of the `#link`/`#image` call.
|
|
181
|
+
- `Backends::Cli#available?` searches PATH in Ruby instead of running
|
|
182
|
+
`which` through a shell, so the configured executable path is never
|
|
183
|
+
interpreted by a shell. It also now requires the file to be executable.
|
|
184
|
+
- `escape_typst` now also escapes backticks, `~`, comment openers (`//`,
|
|
185
|
+
`/*`), dash shorthands (`--`, `---`, `-?`) and line-start markers (`=`, `-`,
|
|
186
|
+
`+`, `/`, `1.`). Text such as `a // b` previously lost everything after the
|
|
187
|
+
`//`, and a line beginning `- ` became a list item.
|
|
188
|
+
- `markdown_to_typst` no longer rewrites the contents of inline code or fenced
|
|
189
|
+
code blocks, and no longer treats `*` or `_` with whitespace on the inner
|
|
190
|
+
side as emphasis (`2 * 3 * 4` was converted to `2 _ 3 _ 4`).
|
|
191
|
+
- Concurrent renders no longer share `typst_data.json`. Each render now
|
|
192
|
+
compiles in its own temporary directory, so threads cannot read or delete
|
|
193
|
+
one another's data.
|
|
194
|
+
- `Renderer` now forwards keyword arguments when delegating helper calls to the
|
|
195
|
+
view context. On Ruby 3, helpers taking keyword arguments raised
|
|
196
|
+
`ArgumentError` when called through the renderer.
|
|
197
|
+
- `markdown_to_typst` mangled combined bold+italic: `***text***` came out as
|
|
198
|
+
`*_text*_` with mismatched markers, because the bold pass matched only two
|
|
199
|
+
of the three asterisks and stranded the third inside the text. `***text***`
|
|
200
|
+
and `___text___` are now recognized as a single token and convert to
|
|
201
|
+
`*_text_*`.
|
|
202
|
+
- `markdown_to_typst` rewrote `\x01` and `\x02` in the caller's own text to
|
|
203
|
+
`*`. Those bytes were used as internal placeholders while converting
|
|
204
|
+
emphasis, so any already present in the input were indistinguishable from
|
|
205
|
+
markers the conversion had written. Placeholders moved to the Unicode
|
|
206
|
+
private use area, and any that do appear in the source are now held aside
|
|
207
|
+
and restored verbatim.
|
|
208
|
+
- `FrameworkDetection.rails?`, `.rage?`, and `.sinatra?` returned `nil` rather
|
|
209
|
+
than `false` when the framework was absent, because `defined?` yields a
|
|
210
|
+
String or nil and the expressions were not coerced. They now return real
|
|
211
|
+
booleans, so callers comparing against `false` or serializing the result
|
|
212
|
+
behave as expected.
|
|
33
213
|
- `Backends::Cli#available?` raised `NoMethodError` when the gem was loaded
|
|
34
214
|
via a bare `require "typst_rails/renderer"`, because `executable_path` read
|
|
35
215
|
`TypstRails.configuration` without checking that the top-level module was
|
|
@@ -39,6 +219,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
39
219
|
- `TypstRails.configuration.typst_executable_path` is now actually used by
|
|
40
220
|
the CLI backend when compiling (previously ignored, so the setting had no
|
|
41
221
|
effect).
|
|
222
|
+
- Three E2E templates failed to compile because they fed Typst syntax it
|
|
223
|
+
could not parse. `02_html_conversion` piped `html_to_markdown` output --
|
|
224
|
+
raw Markdown, where `#` starts a heading -- directly into the document,
|
|
225
|
+
which Typst reads as code; it is now shown verbatim in a `#raw()` block.
|
|
226
|
+
`03_markdown_conversion` referenced a remote image, which Typst refuses to
|
|
227
|
+
fetch; the image case is now asserted as generated markup instead, since the
|
|
228
|
+
renderer compiles from a temp dir whose `--root` cannot reach repo files.
|
|
229
|
+
`05_complex_template` passed plain text containing `#` and `*` through
|
|
230
|
+
`html_to_typst`, which does not escape Typst metacharacters; the fixtures
|
|
231
|
+
are now the HTML that helper expects.
|
|
42
232
|
|
|
43
233
|
## [0.1.0] - 2024-01-XX (Initial Release)
|
|
44
234
|
|