make_pdf-jekyll 0.0.5 → 0.0.6
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 +4 -4
- data/lib/make_pdf/firefox.rb +2 -2
- data/lib/make_pdf/jekyll.rb +72 -47
- data/lib/make_pdf.rb +0 -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: 68f4407fd68b80e7a2f87419480396c0eb7b543ddf86e5bcd8a8b4c60f9d71a6
|
4
|
+
data.tar.gz: 85e8793030dc76e217a4f1882d3befd3fc4a7d49ed01efe888a6789198d6730f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f38ee9054a2ae250228ebac98ef1a97fe7e13fadeee5dba66aa1b9afb302e0f4e9cc4a9a9d35e21e28dded6af688c66362793add3fd488b877fa27a316f3a52
|
7
|
+
data.tar.gz: fc8c51cd0bb88aacf8ba5dfce138eeca83e71fed79ea80c60ea02e37eac7f71d1393d7c4cbd5ebece01dcc1bb8990983761c2da391ed3b932fe07f7fa9dcac14
|
data/lib/make_pdf/firefox.rb
CHANGED
@@ -12,14 +12,14 @@ module MakePDF
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(options)
|
15
|
-
|
15
|
+
Processor.logger.info('MakePDF firefox:', options)
|
16
16
|
@args = make_arguments(**options)
|
17
17
|
@driver_opts = Selenium::WebDriver::Firefox::Options.new(args: @opts)
|
18
18
|
setup
|
19
19
|
end
|
20
20
|
|
21
21
|
def setup
|
22
|
-
|
22
|
+
Processor.logger.info('MakePDF firefox: start driver')
|
23
23
|
@driver = Selenium::WebDriver.for :firefox, capabilities: @driver_opts
|
24
24
|
end
|
25
25
|
|
data/lib/make_pdf/jekyll.rb
CHANGED
@@ -6,8 +6,8 @@ module MakePDF
|
|
6
6
|
LOG_NAME = "make_pdf:"
|
7
7
|
|
8
8
|
# MakePDF Jekyll plugin
|
9
|
-
class
|
10
|
-
attr_reader :reason
|
9
|
+
class Processor
|
10
|
+
attr_reader :reason, :doc, :name
|
11
11
|
|
12
12
|
def valid?
|
13
13
|
@reason.nil?
|
@@ -30,35 +30,42 @@ module MakePDF
|
|
30
30
|
"no" => false
|
31
31
|
}
|
32
32
|
|
33
|
-
[ key, possible[value.downcase] ]
|
33
|
+
[ key, possible[value.to_s.downcase] ]
|
34
34
|
else
|
35
35
|
[ key.sub("make-pdf-", "").to_sym, value ] if key.start_with?("make-pdf-")
|
36
36
|
end
|
37
37
|
end.to_h.merge(options)
|
38
38
|
end
|
39
39
|
|
40
|
-
def initialize(current_doc, **options)
|
41
|
-
@
|
40
|
+
def initialize(site, current_doc, **options)
|
41
|
+
@site = site
|
42
|
+
@file = current_doc.destination(@base_source)
|
42
43
|
@options = filter_options(current_doc, **options)
|
43
|
-
|
44
|
-
|
45
|
-
@options[:input_host] ||= splited_url[2]
|
44
|
+
@name = current_doc.name
|
45
|
+
|
46
46
|
logger.debug("base_paths: input → #{@options[:input_base_url]} output → #{@options[:output_base_path]} host → #{@options[:input_host]}")
|
47
47
|
|
48
|
-
current_options = make_options(@options,
|
49
|
-
output_dir = @options[:output_dir] || path_of(site.dest).dirname
|
48
|
+
current_options = make_options(@options, options, filter_options(current_doc))
|
50
49
|
|
51
50
|
logger.debug("options : #{current_options}")
|
52
51
|
|
52
|
+
return if check_failure(current_options[:disabled], "MakePDF disabled")
|
53
|
+
|
53
54
|
return if check_failure(File.extname(@file) != '.html', "#{@file} is not an html")
|
55
|
+
|
54
56
|
return if check_failure(current_options[:make_pdf].nil? && !@opt_in, "#{current_doc.name} has not opted in")
|
57
|
+
|
55
58
|
return if check_failure(current_options[:make_pdf] == false, "#{current_doc.name} has opted out")
|
56
59
|
|
57
|
-
writer = current_options[:writer]
|
60
|
+
writer = current_options[:writer] || site.options[:writer]
|
58
61
|
return if check_failure(writer.nil?, "No writer defined for #{current_doc.name} (#{writer})")
|
59
62
|
|
60
|
-
logger.info(" processing #{current_doc.name}")
|
61
63
|
@writer = MakePDF.const_get(writer.capitalize).new(logger:, **current_options)
|
64
|
+
@doc = current_doc
|
65
|
+
end
|
66
|
+
|
67
|
+
def output_dir
|
68
|
+
@writer.output_dir
|
62
69
|
end
|
63
70
|
|
64
71
|
def targets
|
@@ -66,10 +73,12 @@ module MakePDF
|
|
66
73
|
end
|
67
74
|
|
68
75
|
def method_missing(method_name, *args, **options)
|
69
|
-
if
|
70
|
-
return
|
71
|
-
elsif
|
72
|
-
return
|
76
|
+
if @options.include?(method_name)
|
77
|
+
return @options[method_name]
|
78
|
+
elsif not @site.options.nil? and @site.options.include?(method_name)
|
79
|
+
return @site.options[method_name]
|
80
|
+
elsif @site.respond_to?(method_name, false)
|
81
|
+
return @site.send(method_name, *args, **options)
|
73
82
|
else
|
74
83
|
super
|
75
84
|
end
|
@@ -80,6 +89,7 @@ module MakePDF
|
|
80
89
|
|
81
90
|
attempted = 0
|
82
91
|
begin
|
92
|
+
logger.info("processing #{@file}")
|
83
93
|
@writer.process(@file, **options.merge(@options))
|
84
94
|
rescue => error
|
85
95
|
attempted += 1
|
@@ -103,9 +113,19 @@ module MakePDF
|
|
103
113
|
end
|
104
114
|
end
|
105
115
|
|
106
|
-
class
|
116
|
+
class Site
|
107
117
|
include PathManip
|
108
|
-
attr_reader :
|
118
|
+
attr_reader :options, :site, :logger
|
119
|
+
|
120
|
+
def default_options
|
121
|
+
return {
|
122
|
+
output_base_path: site.source,
|
123
|
+
input_location: path_of(site.dest),
|
124
|
+
input_base_url: relative_path_of(site.baseurl[1..]),
|
125
|
+
input_host: site.config["url"].match(Regexp.new("^[^:]*://\([^/]+\)/?.*$"))[1],
|
126
|
+
input_scheme: "file"
|
127
|
+
}.freeze
|
128
|
+
end
|
109
129
|
|
110
130
|
def make_options(options, *more_options)
|
111
131
|
return {} if options.nil?
|
@@ -117,44 +137,49 @@ module MakePDF
|
|
117
137
|
end
|
118
138
|
end
|
119
139
|
|
120
|
-
def
|
121
|
-
@logger ||= MakePDF::Logger.new(**options)
|
122
|
-
end
|
123
|
-
|
124
|
-
def setup(site, **options)
|
125
|
-
return unless @site.nil?
|
126
|
-
|
140
|
+
def initialize(site, **options)
|
127
141
|
config = site.config["make-pdf"]||{}
|
128
|
-
logger(logger: ::Jekyll.logger, level: (config["log-map-level"] || :debug)
|
142
|
+
@logger = MakePDF::Logger.new(logger: ::Jekyll.logger, level: (config["log-map-level"] || :debug))
|
129
143
|
@site = site
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
:output_base_path => site.source,
|
134
|
-
input_location:,
|
135
|
-
input_base_url:,
|
136
|
-
:input_scheme => "file"
|
137
|
-
}.merge(make_options(@site.config["make-pdf"], options))
|
138
|
-
logger.debug("Initialized with #{self.site_options}.")
|
144
|
+
@options = default_options.merge(make_options(@site.config["make-pdf"], options))
|
145
|
+
@queue = []
|
146
|
+
logger.debug("Initialized with #{self.options}.")
|
139
147
|
end
|
140
148
|
|
141
|
-
def
|
142
|
-
|
143
|
-
|
144
|
-
|
149
|
+
def queue(processor)
|
150
|
+
logger.info("Adding #{processor.name} to queue")
|
151
|
+
@queue.push(processor)
|
152
|
+
end
|
145
153
|
|
146
|
-
|
147
|
-
|
148
|
-
|
154
|
+
def <<(doc)
|
155
|
+
processor = Processor.new(self, doc, **@options)
|
156
|
+
if processor.valid?
|
157
|
+
queue(processor)
|
158
|
+
else
|
159
|
+
logger.info("Skip #{doc.name} => #{processor.reason}")
|
149
160
|
end
|
161
|
+
end
|
150
162
|
|
151
|
-
|
163
|
+
def process
|
164
|
+
@queue.each do |processor|
|
165
|
+
processor.process(**@options)
|
166
|
+
end
|
152
167
|
end
|
153
168
|
end
|
154
169
|
end
|
155
|
-
end
|
156
170
|
|
157
|
-
::Jekyll.logger.info("Loaded #{MakePDF::LOG_NAME} plugin")
|
158
|
-
|
159
|
-
|
171
|
+
::Jekyll.logger.info("Loaded #{MakePDF::LOG_NAME} plugin")
|
172
|
+
|
173
|
+
::Jekyll::Hooks.register [:site], :after_init do |site|
|
174
|
+
@@site = MakePDF::Processor::Site.new(site)
|
175
|
+
@@site.logger.info("site :after_init #{@@site}")
|
176
|
+
end
|
177
|
+
|
178
|
+
::Jekyll::Hooks.register [:pages, :documents, :posts], :post_write do |doc|
|
179
|
+
@@site << doc
|
180
|
+
end
|
181
|
+
|
182
|
+
::Jekyll::Hooks.register [:site], :post_write do |site|
|
183
|
+
@@site.process
|
184
|
+
end
|
160
185
|
end
|
data/lib/make_pdf.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: make_pdf-jekyll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Bogado da Silva Lins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Allows that some documents, or pages to have a pdf version pre generated.
|
14
14
|
email: 'victor@bogado.net '
|