html2img-client 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f26b9fea9182f0ceb819242d093a8deaf5d661e3d25c3ff20f90286120c7b52d
4
- data.tar.gz: 41691473ff4cc2ad5d17cb27ef5cf43b7500b08bc2acb4ad5ad913d9fa0600d3
3
+ metadata.gz: ed2d883315742595595236208062902e3e9a7a184c9e544826a76cda817c369b
4
+ data.tar.gz: 953f2eceeebd093ae4864edd4cdd32022af4ba6f07d04951bca41d5e15b99e59
5
5
  SHA512:
6
- metadata.gz: fc292634a6b4cb762ca9f475187e6d3c9059983a486181926e3c98bf35a287296d16969cb8b9831e0bab741c9b3792c69a802d6edc51a81aa966e7298477e364
7
- data.tar.gz: cc605647b58582a4182335d2412474a23b9fbdbcb3c8a2938bc74cc2ee5e1e2034d372e777c3a6ecf8ad109ac1a5b0344e7555cbfca359c38d93703dea4b3107
6
+ metadata.gz: d600987f67788924bfa8f02225d469ee14e653455909c7dcc14db949586488c9063d672c29ed4e23b0ce53751b089d3d80c6a0774823a0491776cbd837cf48fc
7
+ data.tar.gz: b3b2bc28bf89c420dfc1e2af91160988b372005d1997e4ec440000f88c239da0a9fc38af66b16fb63c4df09825de4f8f927df0c6a58f6c303005ecd475a347f5
data/CHANGELOG.md CHANGED
@@ -6,6 +6,30 @@ follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.1] - 2026-08-17
10
+
11
+ ### Changed
12
+
13
+ - `documentation_uri` now points at <https://html2img.com/integrations/ruby/>.
14
+ The Ruby guide moved and the old `/docs/usage/ruby` URL 404s, so the
15
+ documentation link on the gem page pointed nowhere. Because gemspec metadata
16
+ is fixed at build time, correcting it needs a release.
17
+ - The same move applied to the guide links in the README and in the generated
18
+ `config/initializers/html2img.rb`.
19
+
20
+ ## [1.1.0] - 2026-08-16
21
+
22
+ ### Added
23
+
24
+ - A Railtie, loaded automatically when Rails is present, so a Rails app can
25
+ configure the client with `config.html2img.api_key` (and `base_url`,
26
+ `timeout`, `transport`) from any environment file.
27
+ - `rails generate html2img:install`, which writes a commented
28
+ `config/initializers/html2img.rb`.
29
+
30
+ Both are optional and add no runtime dependencies: `rails/railtie` is only
31
+ required when Rails is already loaded.
32
+
9
33
  ## [1.0.0] - 2026-08-16
10
34
 
11
35
  Initial release of the official Ruby client for the
@@ -30,5 +54,7 @@ Initial release of the official Ruby client for the
30
54
  responding to `#call` can replace it.
31
55
  - An `html2img` executable with `test`, `html`, `screenshot` and `template`.
32
56
 
33
- [Unreleased]: https://github.com/html2img/html2img-ruby/compare/v1.0.0...HEAD
57
+ [Unreleased]: https://github.com/html2img/html2img-ruby/compare/v1.1.1...HEAD
58
+ [1.1.1]: https://github.com/html2img/html2img-ruby/compare/v1.1.0...v1.1.1
59
+ [1.1.0]: https://github.com/html2img/html2img-ruby/compare/v1.0.0...v1.1.0
34
60
  [1.0.0]: https://github.com/html2img/html2img-ruby/releases/tag/v1.0.0
data/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  The official Ruby client for the [HTML to Image API](https://html2img.com) at html2img.com. Turn HTML and CSS into images, capture screenshots of live URLs, render named templates, and export A4 PDFs, all returning a typed response object.
11
11
 
12
- Every render runs in real Chrome, so flexbox, grid, custom properties, web fonts and inline JavaScript behave exactly as they do in the browser. The gem has **zero runtime dependencies** — it is built on Net::HTTP from the standard library — and works anywhere Ruby does: Rails and Sinatra apps, Sidekiq and Active Job workers, rake tasks and one-off scripts. The full API reference lives in the [documentation](https://html2img.com/docs), with a Ruby guide at [html2img.com/docs/usage/ruby](https://html2img.com/docs/usage/ruby).
12
+ Every render runs in real Chrome, so flexbox, grid, custom properties, web fonts and inline JavaScript behave exactly as they do in the browser. The gem has **zero runtime dependencies** — it is built on Net::HTTP from the standard library — and works anywhere Ruby does: Rails and Sinatra apps, Sidekiq and Active Job workers, rake tasks and one-off scripts. The full API reference lives in the [documentation](https://html2img.com/docs), with a Ruby guide at [html2img.com/integrations/ruby](https://html2img.com/integrations/ruby/).
13
13
 
14
14
  Three things this gem does, each with its own worked guide:
15
15
 
@@ -235,6 +235,22 @@ post.og_image.attach(
235
235
 
236
236
  ## Rails
237
237
 
238
+ The gem detects Rails and loads a Railtie, so there is nothing to require. Generate an initializer:
239
+
240
+ ```bash
241
+ bin/rails generate html2img:install
242
+ ```
243
+
244
+ That writes a commented `config/initializers/html2img.rb` reading your key from the environment. Or configure it from any environment file instead, which is handy for per-environment settings:
245
+
246
+ ```ruby
247
+ # config/environments/production.rb
248
+ config.html2img.api_key = Rails.application.credentials.html2img_api_key
249
+ config.html2img.timeout = 45
250
+ ```
251
+
252
+ Both routes end up at the same place. The Railtie runs before `config/initializers`, so an explicit `Html2img.configure` block wins if you use both.
253
+
238
254
  Render an Action View template into the image, so the card lives with the rest of your views:
239
255
 
240
256
  ```ruby
@@ -257,8 +273,6 @@ Then output it in your layout:
257
273
  <meta property="og:image" content="<%= @post.og_image_url %>">
258
274
  ```
259
275
 
260
- Configure the client once in an initializer, as shown in [configuration](#configuration).
261
-
262
276
  ## Background jobs
263
277
 
264
278
  Renders are a natural fit for a background job, especially full-page captures:
@@ -442,14 +456,13 @@ It prints the resulting image URL and your remaining credits, or a clear error i
442
456
  The same API has worked guides and official packages for
443
457
  [Python](https://github.com/html2img/html2img-python),
444
458
  [Django](https://github.com/html2img/html2img-django),
445
- [PHP](https://html2img.com/docs/usage/php),
446
- [Laravel](https://html2img.com/docs/usage/laravel),
447
- [Ruby on Rails](https://html2img.com/docs/usage/rails),
448
- [JavaScript and Node.js](https://html2img.com/docs/usage/javascript),
449
- [React](https://html2img.com/docs/usage/react),
450
- [Vue](https://html2img.com/docs/usage/vue),
451
- [WordPress](https://html2img.com/docs/usage/wordpress) and
452
- [Statamic](https://html2img.com/docs/usage/statamic).
459
+ [PHP](https://html2img.com/integrations/php/),
460
+ [Laravel](https://html2img.com/integrations/laravel/),
461
+ [JavaScript and Node.js](https://html2img.com/integrations/javascript/),
462
+ [React](https://html2img.com/integrations/javascript/#react-and-nextjs),
463
+ [Vue](https://html2img.com/integrations/javascript/#vue-and-nuxt),
464
+ [WordPress](https://html2img.com/integrations/wordpress/) and
465
+ [Statamic](https://html2img.com/integrations/statamic/).
453
466
 
454
467
  ## Development
455
468
 
@@ -465,7 +478,7 @@ Publishing to RubyGems is covered in [PUBLISHING.md](PUBLISHING.md).
465
478
 
466
479
  ## Links
467
480
 
468
- [HTML to Image API](https://html2img.com) · [Screenshot API](https://html2img.com/screenshot-api/) · [HTML to PDF API](https://html2img.com/html-to-pdf/) · [Documentation](https://html2img.com/docs) · [Ruby guide](https://html2img.com/docs/usage/ruby) · [Templates](https://html2img.com/templates) · [Tools](https://html2img.com/tools) · [Features](https://html2img.com/features) · [Comparisons](https://html2img.com/compare) · [Articles](https://html2img.com/articles) · [Pricing](https://html2img.com/pricing)
481
+ [HTML to Image API](https://html2img.com) · [Screenshot API](https://html2img.com/screenshot-api/) · [HTML to PDF API](https://html2img.com/html-to-pdf/) · [Documentation](https://html2img.com/docs) · [Ruby guide](https://html2img.com/integrations/ruby/) · [Templates](https://html2img.com/templates) · [Tools](https://html2img.com/tools) · [Features](https://html2img.com/features) · [Comparisons](https://html2img.com/compare) · [Articles](https://html2img.com/articles) · [Pricing](https://html2img.com/pricing)
469
482
 
470
483
  ## Licence
471
484
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/base"
4
+
5
+ module Html2img
6
+ module Generators
7
+ # Creates config/initializers/html2img.rb.
8
+ #
9
+ # rails generate html2img:install
10
+ class InstallGenerator < ::Rails::Generators::Base
11
+ source_root File.expand_path("templates", __dir__)
12
+
13
+ desc "Creates an html2img initializer at config/initializers/html2img.rb."
14
+
15
+ def copy_initializer
16
+ template "html2img.rb", "config/initializers/html2img.rb"
17
+ end
18
+
19
+ def show_readme
20
+ say ""
21
+ say "Set HTML2IMG_API_KEY in your environment, then check it works:", :green
22
+ say " bin/rails runner 'puts Html2img.html(%q{<h1>Hello</h1>}, width: 600, height: 200).url'"
23
+ say ""
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Configuration for the html2img HTML to Image API.
4
+ #
5
+ # Docs: https://html2img.com/integrations/ruby/
6
+ # Keys: https://app.html2img.com/register
7
+
8
+ Html2img.configure do |config|
9
+ # Your API key. Keep it out of version control: use an environment variable,
10
+ # or Rails credentials (Rails.application.credentials.html2img_api_key).
11
+ config.api_key = ENV.fetch("HTML2IMG_API_KEY", nil)
12
+
13
+ # Request timeout in seconds. The default sits just over the API's 30 second
14
+ # synchronous render budget. For captures that routinely take longer, pass a
15
+ # webhook_url on the request instead of raising this.
16
+ # config.timeout = 35
17
+
18
+ # Override only for a private deployment.
19
+ # config.base_url = "https://app.html2img.com"
20
+
21
+ # An object responding to #call, for retry middleware, a proxy, or a stub in
22
+ # tests. See https://github.com/html2img/html2img-ruby#custom-transports
23
+ # config.transport = nil
24
+ end
@@ -269,3 +269,7 @@ module Html2img
269
269
  end
270
270
  end
271
271
  end
272
+
273
+ # Rails applications get the Railtie for free: config.html2img.* in any
274
+ # environment file, and `rails generate html2img:install`.
275
+ require_relative "railtie" if defined?(Rails::Railtie)
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/railtie"
4
+
5
+ module Html2img
6
+ # Wires the gem into Rails.
7
+ #
8
+ # Loaded automatically when Rails is present, so a Rails app can configure the
9
+ # client from `config/application.rb` or any environment file:
10
+ #
11
+ # config.html2img.api_key = Rails.application.credentials.html2img_api_key
12
+ # config.html2img.timeout = 45
13
+ #
14
+ # Anything left unset falls back to the environment, as usual. This runs
15
+ # before `config/initializers`, so an explicit `Html2img.configure` block in an
16
+ # initializer still wins — run `rails generate html2img:install` to create one.
17
+ class Railtie < ::Rails::Railtie
18
+ config.html2img = ActiveSupport::OrderedOptions.new
19
+
20
+ initializer "html2img.configure" do |app|
21
+ options = app.config.html2img
22
+
23
+ Html2img.configure do |client|
24
+ client.api_key = options.api_key unless options.api_key.nil?
25
+ client.base_url = options.base_url unless options.base_url.nil?
26
+ client.timeout = options.timeout unless options.timeout.nil?
27
+ client.transport = options.transport unless options.transport.nil?
28
+ end
29
+ end
30
+
31
+ generators do
32
+ require "generators/html2img/install/install_generator"
33
+ end
34
+ end
35
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Html2img
4
4
  # Single source of truth for the gem version.
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.1"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html2img-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - html2img
@@ -23,11 +23,14 @@ files:
23
23
  - LICENSE
24
24
  - README.md
25
25
  - exe/html2img
26
+ - lib/generators/html2img/install/install_generator.rb
27
+ - lib/generators/html2img/install/templates/html2img.rb
26
28
  - lib/html2img-client.rb
27
29
  - lib/html2img/cli.rb
28
30
  - lib/html2img/client.rb
29
31
  - lib/html2img/configuration.rb
30
32
  - lib/html2img/errors.rb
33
+ - lib/html2img/railtie.rb
31
34
  - lib/html2img/render_response.rb
32
35
  - lib/html2img/request.rb
33
36
  - lib/html2img/transport.rb
@@ -40,7 +43,7 @@ metadata:
40
43
  source_code_uri: https://github.com/html2img/html2img-ruby
41
44
  changelog_uri: https://github.com/html2img/html2img-ruby/blob/main/CHANGELOG.md
42
45
  bug_tracker_uri: https://github.com/html2img/html2img-ruby/issues
43
- documentation_uri: https://html2img.com/docs/usage/ruby
46
+ documentation_uri: https://html2img.com/integrations/ruby/
44
47
  rubygems_mfa_required: 'true'
45
48
  rdoc_options: []
46
49
  require_paths: