sghtmltopdf 0.6.0 → 0.7.0
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/Cargo.lock +6 -6
- data/README.md +14 -3
- data/ext/sghtmltopdf/Cargo.toml +1 -1
- data/ext/sghtmltopdf/extconf.rb +5 -4
- data/lib/sghtmltopdf/options.rb +8 -0
- data/lib/sghtmltopdf/renderer.rb +14 -0
- data/lib/sghtmltopdf/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ccb7358464b7e2b54de35755d1aaf2a278b59dddee9716101cdf3715eebf51cc
|
|
4
|
+
data.tar.gz: 4c653cda8ba36f061a2d2253f59b4877ee39e2f9f7157cc84e05ab4ec978ad1f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f861dc645c65f74dee61b47a000395e10da29746bb27941079bdb0e34a69828fd424b2033f67692679f3500f6386ee0c2c5ada72bb048fdae593a167f35051a
|
|
7
|
+
data.tar.gz: 616b41944d6a37a7110cf807dab0d2feaf3aeda1861d5c254276d6c59ace03e530c29c03a07b10cff4131ed6f04e4dcd2f284abb6cfcf1c6ff48d87a8f3c6170
|
data/Cargo.lock
CHANGED
|
@@ -951,9 +951,9 @@ dependencies = [
|
|
|
951
951
|
|
|
952
952
|
[[package]]
|
|
953
953
|
name = "rustls-webpki"
|
|
954
|
-
version = "0.103.
|
|
954
|
+
version = "0.103.16"
|
|
955
955
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
956
|
-
checksum = "
|
|
956
|
+
checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281"
|
|
957
957
|
dependencies = [
|
|
958
958
|
"ring",
|
|
959
959
|
"rustls-pki-types",
|
|
@@ -1050,7 +1050,7 @@ dependencies = [
|
|
|
1050
1050
|
|
|
1051
1051
|
[[package]]
|
|
1052
1052
|
name = "sghtmltopdf"
|
|
1053
|
-
version = "0.
|
|
1053
|
+
version = "0.7.0"
|
|
1054
1054
|
dependencies = [
|
|
1055
1055
|
"base64",
|
|
1056
1056
|
"clap",
|
|
@@ -1077,7 +1077,7 @@ dependencies = [
|
|
|
1077
1077
|
|
|
1078
1078
|
[[package]]
|
|
1079
1079
|
name = "sghtmltopdf-ruby"
|
|
1080
|
-
version = "0.
|
|
1080
|
+
version = "0.7.0"
|
|
1081
1081
|
dependencies = [
|
|
1082
1082
|
"magnus",
|
|
1083
1083
|
"rb-sys",
|
|
@@ -1395,9 +1395,9 @@ dependencies = [
|
|
|
1395
1395
|
|
|
1396
1396
|
[[package]]
|
|
1397
1397
|
name = "webpki-roots"
|
|
1398
|
-
version = "1.0.
|
|
1398
|
+
version = "1.0.10"
|
|
1399
1399
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1400
|
-
checksum = "
|
|
1400
|
+
checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9"
|
|
1401
1401
|
dependencies = [
|
|
1402
1402
|
"rustls-pki-types",
|
|
1403
1403
|
]
|
data/README.md
CHANGED
|
@@ -13,13 +13,22 @@ The engine runs inside your process through a native extension (magnus + rb-sys)
|
|
|
13
13
|
gem "sghtmltopdf"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
Precompiled native gems are published for `x86_64-linux`, `aarch64-linux`, `x86_64-linux-musl`, `aarch64-linux-musl`, `arm64-darwin`, and `
|
|
16
|
+
Precompiled native gems are published for `x86_64-linux`, `aarch64-linux`, `x86_64-linux-musl`, `aarch64-linux-musl`, `arm64-darwin`, `x86_64-darwin`, and Windows `x64-mingw-ucrt`.
|
|
17
17
|
There is no build step on those platforms.
|
|
18
18
|
|
|
19
|
-
Elsewhere
|
|
19
|
+
Elsewhere the source gem does not carry the Rust core and will refuse to build with an explanatory message.
|
|
20
20
|
Point those environments at a separate `sghtmltopdf server` process instead; see [Delegating to a server](#delegating-to-a-server).
|
|
21
21
|
|
|
22
|
-
Requires Ruby >= 3.2.
|
|
22
|
+
Requires Ruby >= 3.2. The precompiled gems bundle extensions for Ruby 3.2, 3.3,
|
|
23
|
+
3.4, and 4.0. On Windows, use 64-bit RubyInstaller UCRT (`x64-mingw-ucrt`).
|
|
24
|
+
|
|
25
|
+
For contributors building from a repository checkout on Windows, use RubyInstaller
|
|
26
|
+
with its Devkit, the Rust GNU toolchain (`stable-x86_64-pc-windows-gnu`), and LLVM
|
|
27
|
+
with `libclang.dll`. Set `RUSTUP_TOOLCHAIN=stable-x86_64-pc-windows-gnu`, set
|
|
28
|
+
`LIBCLANG_PATH` to the LLVM `bin` directory, add it to `PATH`, and set
|
|
29
|
+
`BINDGEN_EXTRA_CLANG_ARGS=--target=x86_64-w64-windows-gnu`.
|
|
30
|
+
Run the build through `ridk exec bundle exec rake compile`. The precompiled gem
|
|
31
|
+
does not need these tools.
|
|
23
32
|
|
|
24
33
|
## Usage
|
|
25
34
|
|
|
@@ -89,6 +98,8 @@ end
|
|
|
89
98
|
```
|
|
90
99
|
|
|
91
100
|
View-rendering keys (`template`, `layout`, `locals`, …) go to `render_to_string`, response keys (`filename`, `disposition`, `status`) go to `send_data`, `show_as_html: true` returns the HTML instead of a PDF, and everything else is passed to the converter.
|
|
101
|
+
|
|
102
|
+
`render_to_string(pdf: "invoice", template: "invoices/show")` returns PDF bytes without setting the controller response. You can then pass those bytes to `send_data` or save them elsewhere; response options such as `filename`, `disposition`, and `status` only apply to `render pdf:`.
|
|
92
103
|
Converter keys are flat CLI flag names, so wicked_pdf's nested `margin: {top: 10}` becomes `margin_top: "10mm"` (with the unit spelled out); the [migration guide](https://waka.github.io/sghtmltopdf/en/migration/wicked-pdf.html) maps every key one by one.
|
|
93
104
|
|
|
94
105
|
### Assets
|
data/ext/sghtmltopdf/Cargo.toml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# The package name differs from the library name on purpose: the core crate is published as
|
|
3
3
|
# `sghtmltopdf`, and two packages with the same name cannot be written to one lockfile.
|
|
4
4
|
name = "sghtmltopdf-ruby"
|
|
5
|
-
version = "0.
|
|
5
|
+
version = "0.7.0"
|
|
6
6
|
edition = "2021"
|
|
7
7
|
publish = false
|
|
8
8
|
description = "Ruby binding for sghtmltopdf (see bindings/ruby)"
|
data/ext/sghtmltopdf/extconf.rb
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "mkmf"
|
|
4
|
-
require "rb_sys/mkmf"
|
|
5
|
-
|
|
6
3
|
core = File.expand_path("../../../../core", __dir__)
|
|
7
4
|
unless File.exist?(File.join(core, "Cargo.toml"))
|
|
8
5
|
abort <<~MESSAGE
|
|
@@ -13,9 +10,13 @@ unless File.exist?(File.join(core, "Cargo.toml"))
|
|
|
13
10
|
so a build from source was attempted, but the source gem does not include the
|
|
14
11
|
Rust core and cannot be built.
|
|
15
12
|
|
|
16
|
-
Supported platforms: x86_64-linux / aarch64-linux / x86_64-linux-musl / aarch64-linux-musl / arm64-darwin / x86_64-darwin
|
|
13
|
+
Supported platforms: x86_64-linux / aarch64-linux / x86_64-linux-musl / aarch64-linux-musl / arm64-darwin / x86_64-darwin / x64-mingw-ucrt
|
|
14
|
+
Supported Ruby ABIs: 3.2 / 3.3 / 3.4 / 4.0
|
|
17
15
|
MESSAGE
|
|
18
16
|
end
|
|
19
17
|
|
|
18
|
+
require "mkmf"
|
|
19
|
+
require "rb_sys/mkmf"
|
|
20
|
+
|
|
20
21
|
# Built as `lib/sghtmltopdf/sghtmltopdf.so`.
|
|
21
22
|
create_rust_makefile("sghtmltopdf/sghtmltopdf")
|
data/lib/sghtmltopdf/options.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "date"
|
|
4
|
+
# `Time#iso8601` comes from here before Ruby 3.4 (Rails loads it, a plain Ruby script may not).
|
|
5
|
+
require "time"
|
|
3
6
|
require "uri"
|
|
4
7
|
|
|
5
8
|
module Sghtmltopdf
|
|
@@ -78,6 +81,11 @@ module Sghtmltopdf
|
|
|
78
81
|
when true then [[name, nil]]
|
|
79
82
|
# An array means the same option repeated. The same rule applies to each element.
|
|
80
83
|
when Array then value.flat_map { |element| pairs_for(key, element) }
|
|
84
|
+
# `creation_date:` takes a moment in time. The CLI wants it as ISO 8601, so it is
|
|
85
|
+
# converted to UTC here rather than left to `to_s`, which would drop the zone for a Time
|
|
86
|
+
# and the subsecond part of a DateTime.
|
|
87
|
+
when Time, DateTime then [[name, value.to_time.getutc.iso8601]]
|
|
88
|
+
when Date then [[name, value.iso8601]]
|
|
81
89
|
when Hash
|
|
82
90
|
# Nesting such as wicked_pdf's `margin: {top: 10}` is not accepted. There is no
|
|
83
91
|
# corresponding CLI flag, and flattening it mechanically would let even misspelled
|
data/lib/sghtmltopdf/renderer.rb
CHANGED
|
@@ -10,6 +10,19 @@ module Sghtmltopdf
|
|
|
10
10
|
#
|
|
11
11
|
# It is a pure Ruby class with no dependency on Rails, so it can be unit tested without Rails.
|
|
12
12
|
class Renderer
|
|
13
|
+
module RenderToString
|
|
14
|
+
def render_to_string(*args, &block)
|
|
15
|
+
options = args.first.is_a?(Hash) ? args.first : args[1]
|
|
16
|
+
return super unless options.is_a?(Hash) && options.key?(:pdf)
|
|
17
|
+
|
|
18
|
+
normalized_args = args.map { |arg| arg.is_a?(Hash) ? arg.dup : arg }
|
|
19
|
+
options = _normalize_args(*normalized_args, &block)
|
|
20
|
+
renderer = Renderer.new(options.delete(:pdf), options, default_name: action_name)
|
|
21
|
+
html = super(**renderer.render_options, &block)
|
|
22
|
+
renderer.body_for(html)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
13
26
|
# The keys passed straight to `render_to_string`.
|
|
14
27
|
RAILS_RENDER_KEYS = %i[
|
|
15
28
|
action assigns body collection file formats handlers html inline layout
|
|
@@ -39,6 +52,7 @@ module Sghtmltopdf
|
|
|
39
52
|
# Register the renderer with `ActionController::Renderers.add(:pdf)`.
|
|
40
53
|
# Called from the Railtie's Action Controller load hook (`on_load`).
|
|
41
54
|
def self.register!
|
|
55
|
+
::ActionController::Rendering.prepend(RenderToString)
|
|
42
56
|
::ActionController::Renderers.add(:pdf) do |name, options|
|
|
43
57
|
renderer = ::Sghtmltopdf::Renderer.new(name, options, default_name: action_name)
|
|
44
58
|
html = render_to_string(**renderer.render_options)
|
data/lib/sghtmltopdf/version.rb
CHANGED