gotenberg 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 117763ebd188d065008ebbfa04c29db6d164608356ed6b11f9d4457f5e798d20
4
- data.tar.gz: c4d5bb32b5fb9b638384857a3ef264097d368dd23ce976439c52374f123f86f9
3
+ metadata.gz: 8f53f3f0cd1c87eae43c03fb07bc9bd9096deaa27fe9d6c2cb85f2dbf04f2e24
4
+ data.tar.gz: c79d077d87f6f60513fe293c92442527847fab4fc9c269780375c21b18b098de
5
5
  SHA512:
6
- metadata.gz: 747de8d3f0e7b8ffe094c77fb3298307c08de8cdfc60b391bf8e91c0cee056ff2cb5bab055751e4df5f88f3c8ce691bf3b1db5430596210f9c6f9bc54dcba61b
7
- data.tar.gz: d58c30a3cfb85840ee72bc1104c68307c843b8abccb29d94953a0aed3962926a8dcef424216bd8e078a34e8130f36d04d900b81b85149714dace507a48c126b0
6
+ metadata.gz: 5628e26404b94a39b1215be8ef597987493a01a61d9a1bddd28a912bd457bc499f99b25d0b67425bb7daf6b85d8ad37d0a478afcca231863b53631012424895d
7
+ data.tar.gz: '069da1f064e1b24b87d494efda58e2eb80387aae039db6a06067bb2f89db3dd7f6a0764623bb634623dcf5683b4cce7f0b931ae922371afebf3e6711432107ca'
@@ -48,6 +48,7 @@ module Gotenberg
48
48
  # client = Gotenberg::Client.new("http://localhost:3000")
49
49
  # pdf_content = client.html(htmls, asset_paths, properties)
50
50
  #
51
+ # Credit: https://github.com/jbd0101/ruby-gotenberg-client/blob/master/lib/gotenberg.rb
51
52
  def html(htmls, asset_paths, properties = {}) # rubocop:disable Metrics/CyclomaticComplexity
52
53
  raise GotenbergDownError unless up?
53
54
 
@@ -4,7 +4,8 @@ module Gotenberg
4
4
  module Helper # rubocop:disable Style/Documentation
5
5
  class ExtensionMissing < StandardError; end
6
6
 
7
- class PropshaftAsset # rubocop:disable Style/Documentation
7
+ # Credits: https://github.com/mileszs/wicked_pdf/blob/master/lib/wicked_pdf/wicked_pdf_helper/assets.rb
8
+ class PropshaftAsset
8
9
  attr_reader :asset
9
10
 
10
11
  def initialize(asset)
@@ -63,6 +64,11 @@ module Gotenberg
63
64
  end
64
65
  end
65
66
 
67
+ # Returns the base64 encoded content of a static asset.
68
+ #
69
+ # @param asset_name [String] the name of the asset
70
+ # @raise [MissingAsset] if the asset is not found
71
+ # @return [String] the base64 encoded content of the asset
66
72
  def goten_asset_base64(asset_name)
67
73
  asset = find_asset(goten_static_asset_path(asset_name))
68
74
  raise MissingAsset.new(asset_name, "Could not find asset '#{asset_name}'") if asset.nil?
@@ -71,6 +77,11 @@ module Gotenberg
71
77
  "data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
72
78
  end
73
79
 
80
+ # Returns the static path of an asset based on its extension.
81
+ #
82
+ # @param asset_name [String] the name of the asset
83
+ # @raise [ExtensionMissing] if the asset extension is missing
84
+ # @return [String] the static path of the asset
74
85
  def goten_static_asset_path(asset_name)
75
86
  ext = File.extname(asset_name).delete(".")
76
87
 
@@ -86,6 +97,10 @@ module Gotenberg
86
97
  determine_static_path(asset_type, asset_name)
87
98
  end
88
99
 
100
+ # Returns the compiled path of an asset.
101
+ #
102
+ # @param asset_name [String] the name of the asset
103
+ # @return [String] the compiled path of the asset
89
104
  def goten_compiled_asset_path(asset_name)
90
105
  Rails.public_path.to_s +
91
106
  ActionController::Base.helpers.asset_path(asset_name)
@@ -93,6 +108,12 @@ module Gotenberg
93
108
 
94
109
  private
95
110
 
111
+ # Determines and returns the static path of an asset.
112
+ #
113
+ # @param asset_type [String] the type of the asset (e.g., "javascripts", "stylesheets", "images")
114
+ # @param asset_name [String] the name of the asset
115
+ # @raise [MissingAsset] if the asset is not found
116
+ # @return [String] the static path of the asset
96
117
  def determine_static_path(asset_type, asset_name)
97
118
  asset_root = Rails.root.join("app", "assets")
98
119
  path = asset_root.join(asset_type, asset_name)
@@ -107,7 +128,10 @@ module Gotenberg
107
128
  path.to_s
108
129
  end
109
130
 
110
- # Thanks WickedPDF 🙏
131
+ # Finds and returns the asset for the given path.
132
+ #
133
+ # @param path [String] the path of the asset
134
+ # @return [PropshaftAsset, LocalAsset, Sprockets::Asset, nil] the found asset or nil if not found
111
135
  def find_asset(path)
112
136
  if Rails.application.assets.respond_to?(:find_asset)
113
137
  Rails.application.assets.find_asset(path, base_path: Rails.application.root.to_s)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gotenberg
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
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.1
4
+ version: 1.0.2
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-17 00:00:00.000000000 Z
12
+ date: 2024-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types