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 +4 -4
- data/lib/gotenberg/client.rb +1 -0
- data/lib/gotenberg/helper.rb +26 -2
- data/lib/gotenberg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f53f3f0cd1c87eae43c03fb07bc9bd9096deaa27fe9d6c2cb85f2dbf04f2e24
|
4
|
+
data.tar.gz: c79d077d87f6f60513fe293c92442527847fab4fc9c269780375c21b18b098de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5628e26404b94a39b1215be8ef597987493a01a61d9a1bddd28a912bd457bc499f99b25d0b67425bb7daf6b85d8ad37d0a478afcca231863b53631012424895d
|
7
|
+
data.tar.gz: '069da1f064e1b24b87d494efda58e2eb80387aae039db6a06067bb2f89db3dd7f6a0764623bb634623dcf5683b4cce7f0b931ae922371afebf3e6711432107ca'
|
data/lib/gotenberg/client.rb
CHANGED
@@ -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
|
|
data/lib/gotenberg/helper.rb
CHANGED
@@ -4,7 +4,8 @@ module Gotenberg
|
|
4
4
|
module Helper # rubocop:disable Style/Documentation
|
5
5
|
class ExtensionMissing < StandardError; end
|
6
6
|
|
7
|
-
|
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
|
-
#
|
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)
|
data/lib/gotenberg/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2024-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mime-types
|