sghtmltopdf 0.6.0 → 0.6.1
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 +2 -0
- data/ext/sghtmltopdf/Cargo.toml +1 -1
- 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: a7dae4a51aebba6fa08381c9312a76156d801c897d0dd288b541747936192247
|
|
4
|
+
data.tar.gz: 7e4ba0e78427bfa41cb79795dc3f2529ddee8c50f5ccf294f4b0ce263dced81a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 036c27a344c48b8f78aa921e920584616b5177646ab2b29be0f3f4ee3dfa82cff5bb7e313e607469c19e7822889cc4c4e3d2c1070f04981edc83e3c432dda164
|
|
7
|
+
data.tar.gz: 8ab97193a246d8bc0335a2afe9681e893b768d7392eb829464487e6bc50e23786e91a1a1f5be383a89c592de8d8a0b504f26b9622292d87f815ae30fdb6b6437
|
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.6.
|
|
1053
|
+
version = "0.6.1"
|
|
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.6.
|
|
1080
|
+
version = "0.6.1"
|
|
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
|
@@ -89,6 +89,8 @@ end
|
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
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.
|
|
92
|
+
|
|
93
|
+
`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
94
|
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
95
|
|
|
94
96
|
### 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.6.
|
|
5
|
+
version = "0.6.1"
|
|
6
6
|
edition = "2021"
|
|
7
7
|
publish = false
|
|
8
8
|
description = "Ruby binding for sghtmltopdf (see bindings/ruby)"
|
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