make_pdf-jekyll 0.0.4 → 0.0.5
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/jekyll.rb +9 -2
- data/lib/make_pdf.rb +25 -34
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5ca4768cc346d06fd2b534d43a33232e50ba7054da2974ca89bf53d87eb052f
|
4
|
+
data.tar.gz: e5fa0a4c6aa2affb970cbd9e950d0af1b359ed60caadad94874924e3c716f88f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80ef0cd96743d8ec50fd55de00716963e80bf1c9842d4c1578131c9a685758dcc235280555f218d8022780c090768201623fdcc3aa743a7b1d68eeb4941de6c6
|
7
|
+
data.tar.gz: a0a030c29b3fb29fbf6a42b8c63067eb8af4d5540518431fd41097726d23ffa6d7acbf530eb2a2c11d3c7356b239efcb5385e16511f8557f0c2d8782c459f173
|
data/lib/make_pdf/jekyll.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
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:"
|
@@ -39,7 +40,10 @@ module MakePDF
|
|
39
40
|
def initialize(current_doc, **options)
|
40
41
|
@file = current_doc.destination(@base_source)
|
41
42
|
@options = filter_options(current_doc, **options)
|
42
|
-
|
43
|
+
splited_url = site.config["url"].match(Regexp.new("^\(.*\)://\([^/]+\)/?.*$")).to_a
|
44
|
+
@options[:input_base_url] ||= site.baseurl
|
45
|
+
@options[:input_host] ||= splited_url[2]
|
46
|
+
logger.debug("base_paths: input → #{@options[:input_base_url]} output → #{@options[:output_base_path]} host → #{@options[:input_host]}")
|
43
47
|
|
44
48
|
current_options = make_options(@options, site_options, filter_options(current_doc))
|
45
49
|
output_dir = @options[:output_dir] || path_of(site.dest).dirname
|
@@ -123,9 +127,12 @@ module MakePDF
|
|
123
127
|
config = site.config["make-pdf"]||{}
|
124
128
|
logger(logger: ::Jekyll.logger, level: (config["log-map-level"] || :debug).to_sym, verbose: config['log-verbose'])
|
125
129
|
@site = site
|
130
|
+
input_location = path_of(site.dest)
|
131
|
+
input_base_url = relative_path_of(site.baseurl)
|
126
132
|
@site_options = {
|
127
133
|
:output_base_path => site.source,
|
128
|
-
|
134
|
+
input_location:,
|
135
|
+
input_base_url:,
|
129
136
|
:input_scheme => "file"
|
130
137
|
}.merge(make_options(@site.config["make-pdf"], options))
|
131
138
|
logger.debug("Initialized with #{self.site_options}.")
|
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
|