jekyll_asciidoctor_pdf 0.3.2 → 0.3.3
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/jekyll_asciidoctor_pdf.gemspec +1 -0
- data/lib/jekyll_asciidoctor_pdf/adoc.rb +93 -3
- data/lib/jekyll_asciidoctor_pdf/commands.rb +0 -2
- data/lib/jekyll_asciidoctor_pdf/gitinfo.rb +2 -2
- data/lib/jekyll_asciidoctor_pdf/sidebar.rb +28 -3
- data/lib/jekyll_asciidoctor_pdf/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df0c08936771991bbd479c0660e3894ff098f90a8622b2a08388c75a74c7c8c8
|
4
|
+
data.tar.gz: eca5423777312dd5426656a1c295dd2c3a770fb2fabd59b0afaa686a21eb9e43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66bf3b9a3be30eb7007f1bfbb0c373453037113f3e36b2390cc3bd2edd0bef5f51d1c969ee3d052e119fa3bd055f1622bb21588110e49ca525fa18d4f246fd2e
|
7
|
+
data.tar.gz: ca588094ef6072e4dd5ae6ed4cac5c6e2543981287a2a137e483be7ac5edf32ffc92eeef854695be93f4087591a44a2753c34a1d07ed8fa36a292d101007d94d
|
@@ -45,6 +45,7 @@ Gem::Specification.new do |spec|
|
|
45
45
|
spec.add_runtime_dependency 'safe_yaml', '>= 1.0.5'
|
46
46
|
spec.add_runtime_dependency 'json', '>= 2.1.0'
|
47
47
|
spec.add_runtime_dependency 'rest-client', '>= 2.0.0'
|
48
|
+
spec.add_runtime_dependency 'prawn', '>= 2.2.2'
|
48
49
|
spec.add_runtime_dependency 'asciidoctor-pdf', '>= 1.5.1'
|
49
50
|
|
50
51
|
end
|
@@ -1,13 +1,50 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'fileutils'
|
3
|
+
require 'prawn'
|
3
4
|
require 'asciidoctor-pdf'
|
4
5
|
require 'asciidoctor'
|
5
6
|
|
6
7
|
# Do not touch, this REGEXP is taken from Jekyll source code
|
7
8
|
YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
9
|
+
RELATIVE_LINK_REGEXP = /(^|\s)link:(?!(http:|https:))/
|
10
|
+
CHECK_REGEXP = /✓/
|
8
11
|
|
9
12
|
module JekyllAsciidoctorPdf
|
10
13
|
class ADoc
|
14
|
+
|
15
|
+
##
|
16
|
+
# Search and replace expression to clean up the original file
|
17
|
+
#
|
18
|
+
# Common Issues:
|
19
|
+
# - Relative links: link:relative.html -> link:<BASE_URL>.html
|
20
|
+
# - Checkmark symbol: ✓ -> icon:check[]
|
21
|
+
# - Remove YAML front matter (we could use skip-front-matter attribute)
|
22
|
+
#
|
23
|
+
#
|
24
|
+
# Previous code
|
25
|
+
#
|
26
|
+
# subs = {
|
27
|
+
# YAML_FRONT_MATTER_REGEXP => '',
|
28
|
+
# RELATIVE_LINK_REGEXP => '\1link:' + base_url,
|
29
|
+
# CHECK_REGEXP => 'icon:check[]'
|
30
|
+
# }
|
31
|
+
#
|
32
|
+
# combined_regexp = Regexp.union(subs.keys)
|
33
|
+
#
|
34
|
+
# return content.gsub(combined_regexp, subs)
|
35
|
+
#
|
36
|
+
# Previous code didn't work properly
|
37
|
+
#
|
38
|
+
# TODO: We should try to perform mutilple regexp subs at once.
|
39
|
+
#
|
40
|
+
def self.fixCommonIssues(content, base_url)
|
41
|
+
temp = content.gsub(YAML_FRONT_MATTER_REGEXP, '')
|
42
|
+
temp = temp.gsub(RELATIVE_LINK_REGEXP, '\1link:' + base_url )
|
43
|
+
temp = temp.gsub(CHECK_REGEXP, ' icon:check[] ')
|
44
|
+
|
45
|
+
return temp
|
46
|
+
end
|
47
|
+
|
11
48
|
def self.getAuthorsList(file)
|
12
49
|
names = %x[ git log --pretty=format:"%an" #{file} | sort | uniq ]
|
13
50
|
# last_commit_date can be nil iff the file was not committed.
|
@@ -22,9 +59,12 @@ module JekyllAsciidoctorPdf
|
|
22
59
|
# Generate a PDF of an individual page
|
23
60
|
#
|
24
61
|
# - Remove the jekyll frontmatter
|
62
|
+
# - Read the content
|
63
|
+
# - Execute regexp to fix issues
|
25
64
|
# - Execute the convert process
|
26
65
|
# - Let the caller to collect information from the front_matter and from the file itself
|
27
66
|
#
|
67
|
+
#
|
28
68
|
def self.generatePdf(product_name, file, output_path, parameters, cover_page, theme_pdf, revision, authors, base_url)
|
29
69
|
|
30
70
|
front_matter = {}
|
@@ -35,7 +75,7 @@ module JekyllAsciidoctorPdf
|
|
35
75
|
front_matter = SafeYAML.load(Regexp.last_match(1))
|
36
76
|
end
|
37
77
|
|
38
|
-
stream_adoc = content
|
78
|
+
stream_adoc = fixCommonIssues(content, base_url)
|
39
79
|
|
40
80
|
# We should think about the performance of get the title in that way
|
41
81
|
adoc = Asciidoctor.load stream_adoc
|
@@ -44,7 +84,6 @@ module JekyllAsciidoctorPdf
|
|
44
84
|
filename = File.basename(file,'.*') + '.pdf'
|
45
85
|
filename_path = output_path
|
46
86
|
base_path = File.dirname(file)
|
47
|
-
#authors = getAuthorsList(file)
|
48
87
|
|
49
88
|
generateBookTypePdf(filename, filename_path, product_name, title, base_path, stream_adoc, parameters, cover_page, theme_pdf, revision, authors)
|
50
89
|
|
@@ -111,10 +150,15 @@ module JekyllAsciidoctorPdf
|
|
111
150
|
revision_s = revision.strftime('%m/%d/%Y')
|
112
151
|
end
|
113
152
|
|
153
|
+
temp_pdf = File.join(File.dirname(cover_page), 'temp-cover.pdf')
|
154
|
+
|
155
|
+
generateCoverPage(title, product_name, authors_s, revision_s, '', cover_page, temp_pdf)
|
156
|
+
|
114
157
|
text = <<~TEXT
|
115
158
|
= #{title} : #{product_name}
|
116
159
|
#{authors_s}
|
117
160
|
#{revision_s}
|
161
|
+
:notitle:
|
118
162
|
:doctype: book
|
119
163
|
:experimental:
|
120
164
|
:reproducible:
|
@@ -129,7 +173,7 @@ module JekyllAsciidoctorPdf
|
|
129
173
|
ifdef::backend-pdf[]
|
130
174
|
:pdf-theme: #{theme_pdf}
|
131
175
|
:title-page:
|
132
|
-
:
|
176
|
+
:front-cover-image: image:#{temp_pdf}[]
|
133
177
|
:source-highlighter: rouge
|
134
178
|
endif::[]
|
135
179
|
:chapter-label:
|
@@ -143,6 +187,52 @@ module JekyllAsciidoctorPdf
|
|
143
187
|
return text
|
144
188
|
end
|
145
189
|
|
190
|
+
def self.generateCoverPage(title, subtitle, authors, revision, abstract, background_image, file)
|
191
|
+
|
192
|
+
info = {
|
193
|
+
:Title => title,
|
194
|
+
:Author => authors,
|
195
|
+
:Subject => subtitle,
|
196
|
+
:Keywords => "",
|
197
|
+
:Creator => "NetApp",
|
198
|
+
:Producer => "NetApp",
|
199
|
+
:CreationDate => Time.now
|
200
|
+
}
|
201
|
+
|
202
|
+
Prawn::Document.generate(file, :page_size => 'A4', :margin => 0, :info => info) do
|
203
|
+
stroke_bounds
|
204
|
+
image background_image, :position => :left, :vposition => :top, :fit => [680,3508]
|
205
|
+
|
206
|
+
bounding_box([60, 700], :width => 500, :height => 650) do
|
207
|
+
font "Times-Roman"
|
208
|
+
#stroke_bounds
|
209
|
+
#stroke_circle [0, 0], 10
|
210
|
+
|
211
|
+
move_down 120
|
212
|
+
|
213
|
+
text "Technical Report", size: 12, color: "4B4b4b"
|
214
|
+
move_down 10
|
215
|
+
|
216
|
+
text title, size: 20, font: 'Times-Roman', color: "1667c5"
|
217
|
+
move_down 5
|
218
|
+
text subtitle, size: 16, font: 'Times-Roman', color: "999999"
|
219
|
+
|
220
|
+
move_down 10
|
221
|
+
|
222
|
+
text authors, size: 12, font: 'Times-Roman', color: "4B4b4b"
|
223
|
+
text revision, size: 12, font: 'Times-Roman', color: "4B4b4b"
|
224
|
+
|
225
|
+
|
226
|
+
#move_down 300
|
227
|
+
#text "Abstract", size: 14, font: "Times-Roman", color: "0000FF"
|
228
|
+
#move_down 10
|
229
|
+
#font_size(12) { text abstract, font: "Times-Roman" }
|
230
|
+
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
|
146
236
|
def self.getCopyright()
|
147
237
|
text = <<~TEXT
|
148
238
|
<<<
|
@@ -186,14 +186,12 @@ module JekyllAsciidoctorPdf
|
|
186
186
|
#
|
187
187
|
def init
|
188
188
|
output("Initialize files & output directories ...")
|
189
|
-
output_fullsite = File.join(absolute_output_path, '/fullsite')
|
190
189
|
output_pages = File.join(absolute_output_path, '/pages')
|
191
190
|
output_assets = File.join(absolute_output_path, '/assets')
|
192
191
|
|
193
192
|
mkdir_p(absolute_output_path, quiet)
|
194
193
|
mkdir_p(output_pages,quiet)
|
195
194
|
mkdir_p(output_assets,quiet)
|
196
|
-
mkdir_p(output_fullsite,quiet)
|
197
195
|
|
198
196
|
fullsite_config = parameters['fullsite']
|
199
197
|
background_image = File.join(absolute_working_path, fullsite_config['background_image'])
|
@@ -49,7 +49,7 @@ module JekyllAsciidoctorPdf
|
|
49
49
|
userResponse = response.body
|
50
50
|
unless userResponse.nil? || userResponse.empty?
|
51
51
|
hash = JSON.parse(userResponse)
|
52
|
-
if (hash.key?('name'))
|
52
|
+
if (hash.key?('name') and (not hash['name'].nil?))
|
53
53
|
authors_hash[login_name] = hash['name']
|
54
54
|
return hash['name']
|
55
55
|
end
|
@@ -101,7 +101,7 @@ module JekyllAsciidoctorPdf
|
|
101
101
|
rescue => e
|
102
102
|
puts "Error Message: #{e.to_s}";
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
authors = contributors.sort_by{|name, commits| [-commits, name]}.transpose[0]
|
106
106
|
|
107
107
|
if (authors.nil? || authors.empty? )
|
@@ -48,7 +48,7 @@ module JekyllAsciidoctorPdf
|
|
48
48
|
#
|
49
49
|
class SidebarYAML
|
50
50
|
|
51
|
-
attr_reader :product_name, :name, :file, :permalinks, :parameters, :section_output_path, :sidebar_output_path, :base_path, :cover_page, :theme_pdf
|
51
|
+
attr_reader :product_name, :name, :file, :permalinks, :parameters, :section_output_path, :sidebar_output_path, :base_path, :cover_page, :theme_pdf, :prefix
|
52
52
|
|
53
53
|
|
54
54
|
def initialize(product_name, name, file, permalinks, parameters, output_path, base_path, cover_page, theme_pdf )
|
@@ -57,9 +57,10 @@ module JekyllAsciidoctorPdf
|
|
57
57
|
@file = file
|
58
58
|
@permalinks = permalinks
|
59
59
|
@parameters = parameters
|
60
|
-
@base_path = base_path
|
61
60
|
@cover_page = cover_page
|
62
61
|
@theme_pdf = theme_pdf
|
62
|
+
@base_path = base_path
|
63
|
+
@prefix = nil
|
63
64
|
|
64
65
|
@section_output_path = File.join(output_path,name)
|
65
66
|
@sidebar_output_path = File.join(output_path,'/fullsite-' + name)
|
@@ -68,7 +69,27 @@ module JekyllAsciidoctorPdf
|
|
68
69
|
FileUtils::mkdir_p(sidebar_output_path)
|
69
70
|
|
70
71
|
toc = YAML.load_file(file)
|
71
|
-
|
72
|
+
|
73
|
+
|
74
|
+
##
|
75
|
+
# In the more general structure this prefix is important
|
76
|
+
# We use in two ways
|
77
|
+
#
|
78
|
+
# - Move the base path to execute the asciidoctor process
|
79
|
+
# - Use prefix + url to find in the permalinks hash
|
80
|
+
#
|
81
|
+
if toc and toc.key?('prefix')
|
82
|
+
@prefix = toc['prefix']
|
83
|
+
@base_path = File.join(base_path, @prefix)
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# A few repositories may have sidebar.yml empty.
|
88
|
+
# we should ignore it
|
89
|
+
#
|
90
|
+
if toc and toc.key?('entries')
|
91
|
+
loadAndProcess('Root', toc['entries'], true)
|
92
|
+
end
|
72
93
|
|
73
94
|
end
|
74
95
|
|
@@ -120,6 +141,10 @@ module JekyllAsciidoctorPdf
|
|
120
141
|
# We ignore absolute links
|
121
142
|
output("Absolute links are not supported!")
|
122
143
|
else
|
144
|
+
if not prefix.nil?
|
145
|
+
page = '/' + prefix + child['url']
|
146
|
+
end
|
147
|
+
|
123
148
|
if permalinks.key?(page)
|
124
149
|
# We have the content
|
125
150
|
node.add_child(JekyllAsciidoctorPdf::SidebarEntry.new(title,page, permalinks[page].content, false))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_asciidoctor_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guido Genzone
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 2.0.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: prawn
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.2.2
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.2.2
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: asciidoctor-pdf
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|