make_pdf-jekyll 0.0.4 → 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 +74 -42
- data/lib/make_pdf.rb +25 -35
- 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
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'jekyll'
|
2
2
|
require 'make_pdf'
|
3
|
+
require 'path_of'
|
3
4
|
|
4
5
|
module MakePDF
|
5
6
|
LOG_NAME = "make_pdf:"
|
6
7
|
|
7
8
|
# MakePDF Jekyll plugin
|
8
|
-
class
|
9
|
-
attr_reader :reason
|
9
|
+
class Processor
|
10
|
+
attr_reader :reason, :doc, :name
|
10
11
|
|
11
12
|
def valid?
|
12
13
|
@reason.nil?
|
@@ -29,32 +30,42 @@ module MakePDF
|
|
29
30
|
"no" => false
|
30
31
|
}
|
31
32
|
|
32
|
-
[ key, possible[value.downcase] ]
|
33
|
+
[ key, possible[value.to_s.downcase] ]
|
33
34
|
else
|
34
35
|
[ key.sub("make-pdf-", "").to_sym, value ] if key.start_with?("make-pdf-")
|
35
36
|
end
|
36
37
|
end.to_h.merge(options)
|
37
38
|
end
|
38
39
|
|
39
|
-
def initialize(current_doc, **options)
|
40
|
-
@
|
40
|
+
def initialize(site, current_doc, **options)
|
41
|
+
@site = site
|
42
|
+
@file = current_doc.destination(@base_source)
|
41
43
|
@options = filter_options(current_doc, **options)
|
42
|
-
|
44
|
+
@name = current_doc.name
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
+
logger.debug("base_paths: input → #{@options[:input_base_url]} output → #{@options[:output_base_path]} host → #{@options[:input_host]}")
|
47
|
+
|
48
|
+
current_options = make_options(@options, options, filter_options(current_doc))
|
46
49
|
|
47
50
|
logger.debug("options : #{current_options}")
|
48
51
|
|
52
|
+
return if check_failure(current_options[:disabled], "MakePDF disabled")
|
53
|
+
|
49
54
|
return if check_failure(File.extname(@file) != '.html', "#{@file} is not an html")
|
55
|
+
|
50
56
|
return if check_failure(current_options[:make_pdf].nil? && !@opt_in, "#{current_doc.name} has not opted in")
|
57
|
+
|
51
58
|
return if check_failure(current_options[:make_pdf] == false, "#{current_doc.name} has opted out")
|
52
59
|
|
53
|
-
writer = current_options[:writer]
|
60
|
+
writer = current_options[:writer] || site.options[:writer]
|
54
61
|
return if check_failure(writer.nil?, "No writer defined for #{current_doc.name} (#{writer})")
|
55
62
|
|
56
|
-
logger.info(" processing #{current_doc.name}")
|
57
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
|
58
69
|
end
|
59
70
|
|
60
71
|
def targets
|
@@ -62,10 +73,12 @@ module MakePDF
|
|
62
73
|
end
|
63
74
|
|
64
75
|
def method_missing(method_name, *args, **options)
|
65
|
-
if
|
66
|
-
return
|
67
|
-
elsif
|
68
|
-
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)
|
69
82
|
else
|
70
83
|
super
|
71
84
|
end
|
@@ -76,6 +89,7 @@ module MakePDF
|
|
76
89
|
|
77
90
|
attempted = 0
|
78
91
|
begin
|
92
|
+
logger.info("processing #{@file}")
|
79
93
|
@writer.process(@file, **options.merge(@options))
|
80
94
|
rescue => error
|
81
95
|
attempted += 1
|
@@ -99,9 +113,19 @@ module MakePDF
|
|
99
113
|
end
|
100
114
|
end
|
101
115
|
|
102
|
-
class
|
116
|
+
class Site
|
103
117
|
include PathManip
|
104
|
-
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
|
105
129
|
|
106
130
|
def make_options(options, *more_options)
|
107
131
|
return {} if options.nil?
|
@@ -113,41 +137,49 @@ module MakePDF
|
|
113
137
|
end
|
114
138
|
end
|
115
139
|
|
116
|
-
def
|
117
|
-
@logger ||= MakePDF::Logger.new(**options)
|
118
|
-
end
|
119
|
-
|
120
|
-
def setup(site, **options)
|
121
|
-
return unless @site.nil?
|
122
|
-
|
140
|
+
def initialize(site, **options)
|
123
141
|
config = site.config["make-pdf"]||{}
|
124
|
-
logger(logger: ::Jekyll.logger, level: (config["log-map-level"] || :debug)
|
142
|
+
@logger = MakePDF::Logger.new(logger: ::Jekyll.logger, level: (config["log-map-level"] || :debug))
|
125
143
|
@site = site
|
126
|
-
@
|
127
|
-
|
128
|
-
|
129
|
-
:input_scheme => "file"
|
130
|
-
}.merge(make_options(@site.config["make-pdf"], options))
|
131
|
-
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}.")
|
132
147
|
end
|
133
148
|
|
134
|
-
def
|
135
|
-
|
136
|
-
|
137
|
-
|
149
|
+
def queue(processor)
|
150
|
+
logger.info("Adding #{processor.name} to queue")
|
151
|
+
@queue.push(processor)
|
152
|
+
end
|
138
153
|
|
139
|
-
|
140
|
-
|
141
|
-
|
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}")
|
142
160
|
end
|
161
|
+
end
|
143
162
|
|
144
|
-
|
163
|
+
def process
|
164
|
+
@queue.each do |processor|
|
165
|
+
processor.process(**@options)
|
166
|
+
end
|
145
167
|
end
|
146
168
|
end
|
147
169
|
end
|
148
|
-
end
|
149
170
|
|
150
|
-
::Jekyll.logger.info("Loaded #{MakePDF::LOG_NAME} plugin")
|
151
|
-
|
152
|
-
|
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
|
153
185
|
end
|
data/lib/make_pdf.rb
CHANGED
@@ -1,20 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
|
+
require 'path_of'
|
4
5
|
|
5
6
|
module MakePDF
|
6
7
|
module PathManip
|
7
|
-
def path_of(base, *path_components)
|
8
|
-
other = unless path_components.empty?
|
9
|
-
path_components
|
10
|
-
.map { |component| path_of(component) }
|
11
|
-
.sum Pathname.new(".")
|
12
|
-
else
|
13
|
-
Pathname.new("")
|
14
|
-
end
|
15
|
-
base = Pathname.new(".") if base.nil?
|
16
|
-
if base.instance_of?(Pathname) then base else Pathname.new(base) end + other
|
17
|
-
end
|
18
8
|
|
19
9
|
def relative_path(file, base_path)
|
20
10
|
path_of(file).relative_path_from(path_of(base_path))
|
@@ -77,40 +67,41 @@ module MakePDF
|
|
77
67
|
include PathManip
|
78
68
|
attr_reader :output_dir, :source_url, :logger
|
79
69
|
|
80
|
-
def initialize(
|
70
|
+
def initialize(input_base_url:, output_base_path:, input_scheme: "file", input_host: nil, logger: Logger.new() ,**options)
|
81
71
|
@logger = logger
|
82
|
-
|
72
|
+
raise ArgumentError.new("Scheme `#{input_scheme}` requires an `input_host`.") if input_scheme != "file" && input_host.nil?
|
73
|
+
@options = options.merge({ input_base_url:, output_base_path:, input_scheme:, input_host: })
|
74
|
+
|
83
75
|
end
|
84
76
|
|
85
|
-
def
|
86
|
-
|
77
|
+
def make_relative_file(file, input_location:, **options)
|
78
|
+
path_of(file).relative_path_from(path_of(input_location))
|
79
|
+
end
|
80
|
+
|
81
|
+
def make_source_url(file, input_base_url:, output_base_path:, input_scheme: , input_host: , input_location:, **options)
|
82
|
+
target_file = make_relative_file(file, input_location:, **options)
|
83
|
+
input_location = path_of(input_location)
|
84
|
+
input_base_url = relative_path_of(input_base_url)
|
87
85
|
if (input_scheme != "file")
|
88
|
-
return input_scheme + "://" +
|
86
|
+
return input_scheme + "://" + input_host + "/" + (input_base_url / target_file).to_path
|
89
87
|
else
|
90
|
-
return
|
88
|
+
return (input_location / input_location / target_file).to_path
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
94
|
-
def
|
95
|
-
base_path =
|
96
|
-
|
97
|
-
|
98
|
-
result
|
99
|
-
end
|
100
|
-
|
101
|
-
def make_pdf_filename(file, input_base_path:, **options)
|
102
|
-
base_path = relative_path(file, input_base_path:, **options)
|
103
|
-
filename = Pathname.new(file).basename.sub_ext(".pdf")
|
104
|
-
result = base_path / filename
|
105
|
-
@logger.verbose("make_pdf_filename(#{file}, #{input_base_path}) → base_path: #{base_path}, filename: #{filename} ⇒ #{result}")
|
92
|
+
def make_pdf_filename(file, output_base_path:, input_location:, output_dir:, **options)
|
93
|
+
base_path = path_of(output_base_path)
|
94
|
+
filepath = make_relative_file(file, input_location:).sub_ext(".pdf")
|
95
|
+
result = base_path / relative_path_of(output_dir) / filepath
|
96
|
+
@logger.verbose("make_pdf_filename(#{file}, #{output_base_path}) → base_path: #{base_path}, filepath: #{filepath} ⇒ #{result}")
|
106
97
|
result
|
107
98
|
end
|
108
99
|
|
109
|
-
def make_output_filename(file,
|
110
|
-
@logger.verbose("make_output_filename(#{file}, #{
|
111
|
-
filename = make_pdf_filename(file,
|
112
|
-
output_base_path =
|
113
|
-
output = output_base_path /
|
100
|
+
def make_output_filename(file, input_location:, output_base_path:, output_dir: ".", **options)
|
101
|
+
@logger.verbose("make_output_filename(#{file}, #{input_location}, #{output_base_path})")
|
102
|
+
filename = make_pdf_filename(file, output_base_path:, output_dir:, input_location:, **options)
|
103
|
+
output_base_path = path_of(output_base_path)
|
104
|
+
output = output_base_path / relative_path_of(output_dir) / filename
|
114
105
|
FileUtils::mkdir_p(output.dirname)
|
115
106
|
@logger.debug("filename: #{filename} ⇒ #{output}")
|
116
107
|
output
|
@@ -130,6 +121,5 @@ module MakePDF
|
|
130
121
|
end
|
131
122
|
|
132
123
|
Dir[File.join(__dir__, 'make_pdf/', '**', '*.rb')].each do |file|
|
133
|
-
print "#{file}\n"
|
134
124
|
require file
|
135
125
|
end
|
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 '
|