gotenberg 1.0.2 → 1.0.4

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: 8f53f3f0cd1c87eae43c03fb07bc9bd9096deaa27fe9d6c2cb85f2dbf04f2e24
4
- data.tar.gz: c79d077d87f6f60513fe293c92442527847fab4fc9c269780375c21b18b098de
3
+ metadata.gz: f2b00fd8125872fab5eaf54be4cef7fca244eac5ae7579a9b46cf5e3f377011e
4
+ data.tar.gz: 26903108cc7083cdc13f97f821ba8da327cb832c6d40b0777a6f5967537397aa
5
5
  SHA512:
6
- metadata.gz: 5628e26404b94a39b1215be8ef597987493a01a61d9a1bddd28a912bd457bc499f99b25d0b67425bb7daf6b85d8ad37d0a478afcca231863b53631012424895d
7
- data.tar.gz: '069da1f064e1b24b87d494efda58e2eb80387aae039db6a06067bb2f89db3dd7f6a0764623bb634623dcf5683b4cce7f0b931ae922371afebf3e6711432107ca'
6
+ metadata.gz: c3c3a7b03e8cc60f5b9b375f4f97ccd4d188def9af195e24db03d34f41f6e0caca69cc5fae9d88c2094d1e43d79376be486ce6590af526925f65db76a2761d98
7
+ data.tar.gz: ecd8f9587285eecf4a9d3410048bfd012dce3d1d5c72cdf8d8591eb61d20f1a6352b15caf43b8b8fd9e696b765d2c02d3f611e559ac72e1b7d223ce484b1847d
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gotenberg
4
+ module Assets
5
+ ASSET_TYPES = {
6
+ "js" => "javascripts",
7
+ "css" => "stylesheets",
8
+
9
+ # Fonts
10
+ "otf" => "fonts",
11
+ "ttf" => "fonts",
12
+ "woff" => "fonts",
13
+ "woff2" => "fonts",
14
+ "eot" => "fonts",
15
+ "sfnt" => "fonts",
16
+ "fnt" => "fonts",
17
+ "pfa" => "fonts",
18
+ "pfb" => "fonts",
19
+ "afm" => "fonts",
20
+ "pcf" => "fonts",
21
+ "snf" => "fonts",
22
+ "bdf" => "fonts",
23
+
24
+ # Images
25
+ "bmp" => "images",
26
+ "gif" => "images",
27
+ "jpg" => "images",
28
+ "jpeg" => "images",
29
+ "png" => "images",
30
+ "svg" => "images",
31
+ "tiff" => "images",
32
+ "tif" => "images",
33
+ "webp" => "images",
34
+ "ico" => "images",
35
+ "psd" => "images",
36
+ "heic" => "images"
37
+ }.freeze
38
+ end
39
+ end
@@ -24,7 +24,7 @@ module Gotenberg
24
24
  # Convert HTML files to PDF and write it to the output file
25
25
  #
26
26
  # @param htmls [Hash{Symbol => String}] A hash with the file name as the key and the HTML content as the value
27
- # @param asset_paths [Array<String>] Paths to the asset files (like CSS, images) required by the HTML files
27
+ # @param asset_paths [Array<String>] Optional args, paths to the asset files (like CSS, images) required by the HTML files # rubocop:disable Layout/LineLength
28
28
  # @param properties [Hash] Additional properties for PDF conversion
29
29
  # @option properties [Float] :paperWidth The width of the paper
30
30
  # @option properties [Float] :paperHeight The height of the paper
@@ -49,7 +49,7 @@ module Gotenberg
49
49
  # pdf_content = client.html(htmls, asset_paths, properties)
50
50
  #
51
51
  # Credit: https://github.com/jbd0101/ruby-gotenberg-client/blob/master/lib/gotenberg.rb
52
- def html(htmls, asset_paths, properties = {}) # rubocop:disable Metrics/CyclomaticComplexity
52
+ def html(htmls, asset_paths = [], properties = {}) # rubocop:disable Metrics/CyclomaticComplexity
53
53
  raise GotenbergDownError unless up?
54
54
 
55
55
  raise IndexFileMissing unless (htmls.keys & ["index", :index]).any?
@@ -67,6 +67,12 @@ module Gotenberg
67
67
  # Gotenberg requires all files to be in the same directory
68
68
  asset_paths.each do |path|
69
69
  FileUtils.cp(path, dir_path)
70
+ next unless path.split(".").last == "css"
71
+
72
+ # This preprocessing is necessary for the gotenberg
73
+ raw_css = File.read(path)
74
+ preprocessed = raw_css.gsub("url(/assets/", "url(").gsub("url(/", "url(")
75
+ File.write(path, preprocessed)
70
76
  end
71
77
 
72
78
  # Rejecting .. and .
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "assets"
4
+
3
5
  module Gotenberg
4
6
  module Helper # rubocop:disable Style/Documentation
5
7
  class ExtensionMissing < StandardError; end
@@ -64,7 +66,7 @@ module Gotenberg
64
66
  end
65
67
  end
66
68
 
67
- # Returns the base64 encoded content of a static asset.
69
+ # Returns the base64 encoded content of an asset.
68
70
  #
69
71
  # @param asset_name [String] the name of the asset
70
72
  # @raise [MissingAsset] if the asset is not found
@@ -77,6 +79,19 @@ module Gotenberg
77
79
  "data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
78
80
  end
79
81
 
82
+ # Returns the base64 encoded content of a static asset.
83
+ #
84
+ # @param asset_name [String] the name of the asset
85
+ # @raise [MissingAsset] if the asset is not found
86
+ # @return [String] the base64 encoded content of the asset
87
+ def goten_static_asset_base64(asset_name)
88
+ asset = LocalAsset.new(goten_static_asset_path(asset_name))
89
+ raise MissingAsset.new(asset_name, "Could not find asset '#{asset_name}'") if asset.nil?
90
+
91
+ base64 = Base64.encode64(asset.to_s).delete("\n")
92
+ "data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
93
+ end
94
+
80
95
  # Returns the static path of an asset based on its extension.
81
96
  #
82
97
  # @param asset_name [String] the name of the asset
@@ -87,12 +102,7 @@ module Gotenberg
87
102
 
88
103
  raise ExtensionMissing if ext.empty?
89
104
 
90
- asset_type =
91
- case ext
92
- when "js" then "javascripts"
93
- when "css" then "stylesheets"
94
- else "images"
95
- end
105
+ asset_type = Assets::ASSET_TYPES.fetch(ext)
96
106
 
97
107
  determine_static_path(asset_type, asset_name)
98
108
  end
@@ -106,6 +116,15 @@ module Gotenberg
106
116
  ActionController::Base.helpers.asset_path(asset_name)
107
117
  end
108
118
 
119
+ # Returns the compiled name of an asset.
120
+ #
121
+ # @param asset_name [String] the name of the asset
122
+ # @return [String] the compiled name of the asset
123
+ def goten_compiled_asset_name(asset_name)
124
+ path = goten_compiled_asset_path(asset_name)
125
+ path.split("/").last
126
+ end
127
+
109
128
  private
110
129
 
111
130
  # Determines and returns the static path of an asset.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gotenberg
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gotenberg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - bugloper
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-06-20 00:00:00.000000000 Z
12
+ date: 2025-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types
@@ -47,6 +47,7 @@ extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - lib/gotenberg.rb
50
+ - lib/gotenberg/assets.rb
50
51
  - lib/gotenberg/client.rb
51
52
  - lib/gotenberg/helper.rb
52
53
  - lib/gotenberg/railtie.rb
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  - !ruby/object:Gem::Version
76
77
  version: '0'
77
78
  requirements: []
78
- rubygems_version: 3.4.10
79
+ rubygems_version: 3.0.3.1
79
80
  signing_key:
80
81
  specification_version: 4
81
82
  summary: A simple Ruby client for gotenberg