gotenberg 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gotenberg/assets.rb +39 -0
- data/lib/gotenberg/client.rb +7 -1
- data/lib/gotenberg/helper.rb +13 -6
- data/lib/gotenberg/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 489dc50093dc4d7dfcf8934e4f7f1e66c42c3ee331b8f6712206a4f9e4bb3f95
|
4
|
+
data.tar.gz: 32a0dacebb19c92447cc448ea93fa94de7081cc7fdff11a5fd271d20d262ae1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a39d81adfa325e16a1a9e5105103e1e9f68acd22600d6b56fcf951f8a45c97353eb676dc1e36c17f6f9113ef20c4bfe05280cc0fa53552a18f4a6d3d176d6674
|
7
|
+
data.tar.gz: dc6294d7356a315e002eb47e8a311908c541c18b0980e3d29325558fd72612bcb628f999f9b841b88c7e68480796a4adb49437a8bd20690f990c76a2771bb2c9
|
@@ -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
|
data/lib/gotenberg/client.rb
CHANGED
@@ -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 = {})
|
52
|
+
def html(htmls, asset_paths, properties = {})
|
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 .
|
data/lib/gotenberg/helper.rb
CHANGED
@@ -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
|
@@ -87,12 +89,7 @@ module Gotenberg
|
|
87
89
|
|
88
90
|
raise ExtensionMissing if ext.empty?
|
89
91
|
|
90
|
-
asset_type =
|
91
|
-
case ext
|
92
|
-
when "js" then "javascripts"
|
93
|
-
when "css" then "stylesheets"
|
94
|
-
else "images"
|
95
|
-
end
|
92
|
+
asset_type = Assets::ASSET_TYPES.fetch(ext)
|
96
93
|
|
97
94
|
determine_static_path(asset_type, asset_name)
|
98
95
|
end
|
@@ -106,6 +103,16 @@ module Gotenberg
|
|
106
103
|
ActionController::Base.helpers.asset_path(asset_name)
|
107
104
|
end
|
108
105
|
|
106
|
+
# Returns the compiled name of an asset.
|
107
|
+
#
|
108
|
+
# @param asset_name [String] the name of the asset
|
109
|
+
# @return [String] the compiled name of the asset
|
110
|
+
|
111
|
+
def goten_compiled_asset_name(asset_name)
|
112
|
+
path = goten_compiled_asset_path(asset_name)
|
113
|
+
path.split("/").last
|
114
|
+
end
|
115
|
+
|
109
116
|
private
|
110
117
|
|
111
118
|
# Determines and returns the static path of an asset.
|
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.3
|
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-24 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
|