html2img-client 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f26b9fea9182f0ceb819242d093a8deaf5d661e3d25c3ff20f90286120c7b52d
4
- data.tar.gz: 41691473ff4cc2ad5d17cb27ef5cf43b7500b08bc2acb4ad5ad913d9fa0600d3
3
+ metadata.gz: 2408ba406bee12b50306a3237e4ddd7e4bae09e170ea6e767aa870f2ce19ecd6
4
+ data.tar.gz: f2aeb2722ae4c14c07aff053a073658d968231e09500c884ab792afde5801042
5
5
  SHA512:
6
- metadata.gz: fc292634a6b4cb762ca9f475187e6d3c9059983a486181926e3c98bf35a287296d16969cb8b9831e0bab741c9b3792c69a802d6edc51a81aa966e7298477e364
7
- data.tar.gz: cc605647b58582a4182335d2412474a23b9fbdbcb3c8a2938bc74cc2ee5e1e2034d372e777c3a6ecf8ad109ac1a5b0344e7555cbfca359c38d93703dea4b3107
6
+ metadata.gz: 63780af867f2b8087bb1faf8c5818fe1b4fa3b3d4d9b527f4709de568e85ddd4ab7fa84d8b9080445c48c8ea3b049296a9ff420763d33a82b3143e4008e64d5f
7
+ data.tar.gz: d53bed7411b6b5157e2bcc78b9488d74c6ceead1fef88b0be836c8802a77714f4a0f0d72f355e49a6fa68b089e41a561da44c423807fdbcc5b43cae397f7f757
data/CHANGELOG.md CHANGED
@@ -6,6 +6,19 @@ follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.0] - 2026-08-16
10
+
11
+ ### Added
12
+
13
+ - A Railtie, loaded automatically when Rails is present, so a Rails app can
14
+ configure the client with `config.html2img.api_key` (and `base_url`,
15
+ `timeout`, `transport`) from any environment file.
16
+ - `rails generate html2img:install`, which writes a commented
17
+ `config/initializers/html2img.rb`.
18
+
19
+ Both are optional and add no runtime dependencies: `rails/railtie` is only
20
+ required when Rails is already loaded.
21
+
9
22
  ## [1.0.0] - 2026-08-16
10
23
 
11
24
  Initial release of the official Ruby client for the
@@ -30,5 +43,6 @@ Initial release of the official Ruby client for the
30
43
  responding to `#call` can replace it.
31
44
  - An `html2img` executable with `test`, `html`, `screenshot` and `template`.
32
45
 
33
- [Unreleased]: https://github.com/html2img/html2img-ruby/compare/v1.0.0...HEAD
46
+ [Unreleased]: https://github.com/html2img/html2img-ruby/compare/v1.1.0...HEAD
47
+ [1.1.0]: https://github.com/html2img/html2img-ruby/compare/v1.0.0...v1.1.0
34
48
  [1.0.0]: https://github.com/html2img/html2img-ruby/releases/tag/v1.0.0
data/README.md CHANGED
@@ -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:
@@ -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/docs/usage/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.0"
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.0
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