sghtmltopdf 0.6.0-x86_64-linux → 0.7.0-x86_64-linux

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b4831391639b8b8e6036a95d79d3c5387a4a252874bd1e6073266f751e75c1e
4
- data.tar.gz: 354406630de9fd7fe0a570eb53c77fb8230f492701eaace98752ec1efb2173ff
3
+ metadata.gz: e593b72f956b47782af175710df5f7c0f344bc7dcc36a0228310c8c4990e2f6a
4
+ data.tar.gz: 9e39d7a29271656526c937dab6e61382ae61aa86be2964ed195262f053062aba
5
5
  SHA512:
6
- metadata.gz: 2cabd56b41588bb310e56a33eab907175ba90e695207fe02823e0ff7f8eefd816bbab80693d251f2d30c3b12cc786a23be701aaed0189863ec982cb88399d1b7
7
- data.tar.gz: bece91b0de6f4e1b81b9b8ca4977709ee57eaa36ed682d73992a870028142ede794d0a067c2fec2bf337cb3e3e6456592ebc03cf97f3b4d42c684d3917d8a3b3
6
+ metadata.gz: d4707b684abe170632868a2c05d90ced04b651b8991a77798a0bce4a856f9bd6c015d67bc952c0c0e80526c18d5c3fbe30c0e3ff72698ef701de7f7e6a6b284c
7
+ data.tar.gz: f8a8ce7d3e6d735db810fc2e40fa087f5ba69b914f111e1247cca42b766d07905fc98bb4208aa6043c7562879a0e4ae7479a785399fdc4d3e86a81e21c5f8e62
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 `x86_64-darwin`.
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 (Windows) the gem cannot run in-process — the source gem does not carry the Rust core and will refuse to build with an explanatory message.
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
Binary file
Binary file
Binary file
Binary file
@@ -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
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sghtmltopdf
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sghtmltopdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - yo_waka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-18 00:00:00.000000000 Z
11
+ date: 2026-11-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Ruby binding for sghtmltopdf, a successor to wkhtmltopdf: an HTML-to-PDF