rake_jekyll_asciidoctor_pdf 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/README.adoc +145 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rake_jekyll_asciidoctor_pdf.rb +13 -0
- data/lib/rake_jekyll_asciidoctor_pdf/commands.rb +364 -0
- data/lib/rake_jekyll_asciidoctor_pdf/tree.rb +72 -0
- data/lib/rake_jekyll_asciidoctor_pdf/version.rb +3 -0
- data/rake_jekyll_asciidoctor_pdf.gemspec +48 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d8d203b6b5e6eb099d0e8927930076f0545873ada8b4cd9a3f1dcb530cfa6936
|
4
|
+
data.tar.gz: e9dc0be4a827341905725418d52198d1bd7107a03abb1c3016ed7d6eae382d7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c047b3645780f97c8fe05857cbc45791513da1bee4e9fc4df7c9be79ff5d851f7ae1b1fbb91084e60fb74ae67dcbbb516cf3f96bbff3c3fd77b8ab112be7205
|
7
|
+
data.tar.gz: b7101d48e69dcfca2f3978cc704d8481f4a9129ef9362d68aa24688e9255c75c0e452165c1789b5b72c0c4362d4801f1f274e6ef21a2acc64cdf6e22e6984def
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.adoc
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
= Jekyll Pages + Asciidoctor => PDF
|
2
|
+
:gem-name: rake_jekyll_asciidoctor_pdf
|
3
|
+
:gh-name: ggenzone/{gem-name}
|
4
|
+
:gh-branch: master
|
5
|
+
:badge-style: flat
|
6
|
+
|
7
|
+
image:https://img.shields.io/gem/v/{gem-name}.svg?style={badge-style}[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
|
8
|
+
|
9
|
+
toc::[]
|
10
|
+
|
11
|
+
== Overview
|
12
|
+
|
13
|
+
The basic idea is to be able to generate PDFs files for each page in Jekyll, and also to generate one complete PDF with the whole site using the sidebar structure as starting point.
|
14
|
+
|
15
|
+
== Constraints
|
16
|
+
|
17
|
+
* We assume that the original pages use **Asciidoc** with traditional front matter like this
|
18
|
+
|
19
|
+
[source,asciidoc]
|
20
|
+
----
|
21
|
+
|
22
|
+
---
|
23
|
+
layout: info
|
24
|
+
permalink: /sample/
|
25
|
+
---
|
26
|
+
= Sample Page
|
27
|
+
:url-asciidoctor: http://asciidoctor.org
|
28
|
+
|
29
|
+
This is a sample page composed in AsciiDoc.
|
30
|
+
Jekyll converts it to HTML using {url-asciidoctor}[Asciidoctor].
|
31
|
+
|
32
|
+
[source,ruby]
|
33
|
+
puts "Hello, World!"
|
34
|
+
----
|
35
|
+
|
36
|
+
* Each page **must** have a permalink attribute in the front matter and **must** be unique.
|
37
|
+
* The permalink will be used in the sidebar as foreign key of each page
|
38
|
+
* The sidebar structure **should** be like this
|
39
|
+
|
40
|
+
entries:
|
41
|
+
- title: Chapter 1
|
42
|
+
url: /chapter1.html
|
43
|
+
- title: Chapter 2
|
44
|
+
entries:
|
45
|
+
- title: Section 1
|
46
|
+
url: /chapter_2_section_1.html
|
47
|
+
- title: Section 2
|
48
|
+
url: /chapter_2_section_2.html
|
49
|
+
...
|
50
|
+
|
51
|
+
|
52
|
+
== Process
|
53
|
+
. Generate PDF files for each page
|
54
|
+
.. Copy all files and remove the front matter information
|
55
|
+
.. Execute **asciidoctor-pdf** in each new file
|
56
|
+
|
57
|
+
. Generate a fullsite.adoc using the sidebar.yml structure
|
58
|
+
.. Copy all files, remove front matter information and rename it with the permalink as name
|
59
|
+
.. Load sidebar.yml into a *tree* like structure
|
60
|
+
.. Generate the whole content using recursion over the *tree*
|
61
|
+
.. Execute **asciidoctor-pdf** in the new file
|
62
|
+
|
63
|
+
|
64
|
+
== Installation
|
65
|
+
|
66
|
+
Add this line to your application’s Gemfile:
|
67
|
+
|
68
|
+
gem 'rake_jekyll_asciidoctor_pdf'
|
69
|
+
|
70
|
+
and then execute:
|
71
|
+
|
72
|
+
$ bundle
|
73
|
+
|
74
|
+
== Tasks
|
75
|
+
|
76
|
+
=== BuildTask
|
77
|
+
|
78
|
+
This task builds the full
|
79
|
+
|
80
|
+
==== Usage
|
81
|
+
|
82
|
+
The most simple usage is
|
83
|
+
|
84
|
+
[source, ruby]
|
85
|
+
----
|
86
|
+
require 'rake_jekyll_asciidoctor_pdf'
|
87
|
+
|
88
|
+
RakeJekyllAsciidoctorPdf::BuildTask.new
|
89
|
+
----
|
90
|
+
|
91
|
+
This listing introduces all the configurable options with their default values:
|
92
|
+
|
93
|
+
[source, ruby]
|
94
|
+
----
|
95
|
+
require 'rake_jekyll_asciidoctor_pdf'
|
96
|
+
|
97
|
+
RakeJekyllAsciidoctorPdf::BuildTask.new(:build) do |t|
|
98
|
+
|
99
|
+
# Description of the rake task.
|
100
|
+
t.description = 'Generate PDFs files'
|
101
|
+
t.config_pdf_file = 'pdf-theme.yml'
|
102
|
+
t.sidebar_file = 'data/sidebar.yml'
|
103
|
+
t.data_path = 'data'
|
104
|
+
|
105
|
+
end
|
106
|
+
----
|
107
|
+
|
108
|
+
== Example
|
109
|
+
|
110
|
+
$ rake buildAll
|
111
|
+
|
112
|
+
Or
|
113
|
+
|
114
|
+
$ rake SOURCE_PATH='<PATH_LIKE_DATA_EXAMPLE>'
|
115
|
+
|
116
|
+
If you want to use a diferent SOURCE_PATH you should know the structure of the data folder.
|
117
|
+
|
118
|
+
media
|
119
|
+
sidebar.yml
|
120
|
+
*.adoc
|
121
|
+
|
122
|
+
|
123
|
+
== Known Limitations
|
124
|
+
* Mp4 is not supported
|
125
|
+
* Gif files need prawn-gmagick
|
126
|
+
* Absolute URL not supported in the sidebar.yml
|
127
|
+
* Problems with image labels like that
|
128
|
+
* Problems with interal *links:*
|
129
|
+
* Unicode characters are not supported by AsciiDocPdf (e.i. ✓)
|
130
|
+
|
131
|
+
[source,asciidoc]
|
132
|
+
----
|
133
|
+
//image:diagram_networking_cloud.png[service, a] not working, shoud be like this
|
134
|
+
image:diagram_networking_cloud.png["service, a"]
|
135
|
+
----
|
136
|
+
|
137
|
+
|
138
|
+
== ToDo List ==
|
139
|
+
|
140
|
+
* [*] Remove front matter from original files
|
141
|
+
* [x] Generate a combined file with each item in the sidebar.yml
|
142
|
+
* [ ] Allow to customize PDF using a theme of AsciiDoctor-PDF
|
143
|
+
* [ ] Remove header attribuites in the original files
|
144
|
+
* [x] Increase 1 level each time we combine a child in the sidebar
|
145
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rake_jekyll_asciidoctor_pdf'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'rake_jekyll_asciidoctor_pdf/version'
|
3
|
+
require 'rake_jekyll_asciidoctor_pdf/commands'
|
4
|
+
|
5
|
+
|
6
|
+
# RakeJekyllAsciidoctorPdf
|
7
|
+
#
|
8
|
+
# Empty module being initialized.
|
9
|
+
# This RubyGem holds examples of how to make Rake tasks for Rake using a
|
10
|
+
# RubyGem and some custom stuff. It helps clean up the Rakefile later.
|
11
|
+
module RakeJekyllAsciidoctorPdf
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,364 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
require 'yaml'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'asciidoctor-pdf'
|
8
|
+
require 'asciidoctor'
|
9
|
+
require 'rake_jekyll_asciidoctor_pdf/tree'
|
10
|
+
|
11
|
+
|
12
|
+
# Do not touch, this REGEXP is taken from Jekyll source code
|
13
|
+
YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
14
|
+
|
15
|
+
|
16
|
+
module RakeJekyllAsciidoctorPdf
|
17
|
+
|
18
|
+
|
19
|
+
class BuildTask < ::Rake::TaskLib
|
20
|
+
|
21
|
+
##
|
22
|
+
# @private
|
23
|
+
# Defines attribute accessor with optional default value.
|
24
|
+
# When attribute's value is a +Proc+ with arity 0, then the attribute
|
25
|
+
# reader calls it and returns the result.
|
26
|
+
#
|
27
|
+
# @param attr_name [#to_s] name of the attribute to define.
|
28
|
+
# @param default_value [Object] the default value (optional).
|
29
|
+
# @yield When the block is given, then it's used as a default value.
|
30
|
+
# It takes precedence over the +default_value+. It's evaluated in an
|
31
|
+
# instance context.
|
32
|
+
def self.callable_attr(attr_name, default_value = nil, &default_block)
|
33
|
+
var_name = "@#{attr_name}".sub('?', '').to_sym
|
34
|
+
|
35
|
+
define_method attr_name do
|
36
|
+
value = instance_variable_get(var_name)
|
37
|
+
|
38
|
+
if value.nil? && default_block
|
39
|
+
do_in_working_dir { instance_eval &default_block }
|
40
|
+
elsif value.nil?
|
41
|
+
default_value
|
42
|
+
elsif value.is_a?(Proc) && value.arity.zero?
|
43
|
+
do_in_working_dir &value
|
44
|
+
else
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
attr_writer attr_name.to_s.sub('?', '')
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [#to_sym] name of the task.
|
53
|
+
attr_accessor :name
|
54
|
+
|
55
|
+
# @return [#to_s] description of the task.
|
56
|
+
attr_accessor :description
|
57
|
+
|
58
|
+
attr_accessor :parameters
|
59
|
+
|
60
|
+
attr_reader :absolute_temp_path
|
61
|
+
attr_reader :absolute_working_path
|
62
|
+
attr_reader :absolute_source_path
|
63
|
+
attr_reader :absolute_assets_list
|
64
|
+
attr_reader :absolute_config_file
|
65
|
+
attr_reader :absolute_sidebar_file
|
66
|
+
attr_reader :absolute_output_path
|
67
|
+
|
68
|
+
attr_reader :assets_list
|
69
|
+
attr_reader :quiet
|
70
|
+
|
71
|
+
callable_attr :jekyll_config_file, '_config.yml'
|
72
|
+
|
73
|
+
def initialize(name = :build_pdf)
|
74
|
+
@name = name
|
75
|
+
@description = 'Generate PDF files for each *.adoc in the source_list '
|
76
|
+
|
77
|
+
@absolute_working_path = Dir.pwd
|
78
|
+
@absolute_temp_path = Dir.mktmpdir
|
79
|
+
|
80
|
+
@quiet = { verbose: true }
|
81
|
+
|
82
|
+
#file = __FILE__
|
83
|
+
#file = File.readlink(file) if File.symlink?(file)
|
84
|
+
#@base_dir = File.dirname(file)
|
85
|
+
|
86
|
+
#puts @base_dir
|
87
|
+
|
88
|
+
yield self if block_given?
|
89
|
+
|
90
|
+
@absolute_config_file = File.join(@absolute_working_path, jekyll_config_file);
|
91
|
+
|
92
|
+
do_jekyll_config_ok? do |t|
|
93
|
+
@absolute_source_path = File.join(@absolute_working_path, @parameters['source_path']);
|
94
|
+
@absolute_output_path = File.join(@absolute_working_path, @parameters['output_path']);
|
95
|
+
@absolute_sidebar_file = File.join(@absolute_working_path, @parameters['sidebar_file']);
|
96
|
+
|
97
|
+
files = []
|
98
|
+
FileList[@parameters['assets_list']].each do |file|
|
99
|
+
files << File.join(@absolute_working_path,file)
|
100
|
+
end
|
101
|
+
|
102
|
+
@absolute_assets_list = files
|
103
|
+
|
104
|
+
define_task!
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
def define_task!
|
111
|
+
|
112
|
+
desc "Print information variables"
|
113
|
+
task :info do
|
114
|
+
print_variables
|
115
|
+
end
|
116
|
+
|
117
|
+
desc "Cleaning files & directories"
|
118
|
+
task :clean do
|
119
|
+
clean
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
# We can improve it using replace inline and cp
|
124
|
+
desc "Rewriting *.adoc files and generating auxiliary files without front matter"
|
125
|
+
task :generateTempFiles => [ :clean ] do
|
126
|
+
generate_temp_files
|
127
|
+
end
|
128
|
+
|
129
|
+
desc "Generating PDFs files for each page"
|
130
|
+
task :generatePdf => [:clean, :generateTempFiles] do
|
131
|
+
generate_pdf
|
132
|
+
end
|
133
|
+
|
134
|
+
desc "Generate the fullsite.adoc file"
|
135
|
+
file 'fullsite.adoc' => ['generateTempFiles'] do
|
136
|
+
|
137
|
+
generate_fullsite_adoc
|
138
|
+
end
|
139
|
+
|
140
|
+
desc "Generate the fullsite.pdf file"
|
141
|
+
file 'fullsite.pdf' => 'fullsite.adoc' do
|
142
|
+
|
143
|
+
generate_fullsite_pdf
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
desc description
|
148
|
+
task name.to_sym => [:generatePdf, 'fullsite.pdf'] do
|
149
|
+
remove_entry absolute_temp_path
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# Check if Jekyll configuration is Okay
|
159
|
+
#
|
160
|
+
def do_jekyll_config_ok?
|
161
|
+
config = YAML.load_file(absolute_config_file)
|
162
|
+
|
163
|
+
assert_key(config, 'jap_config', "Expected key 'jap_config' to exist, but does not")
|
164
|
+
|
165
|
+
@parameters = config['jap_config']
|
166
|
+
|
167
|
+
assert_key(@parameters, 'source_path' , "Expected key 'jap_config.source_path' to exist, but does not")
|
168
|
+
assert_key(@parameters, 'assets_list' , "Expected key 'jap_config.assets_list' to exist, but does not")
|
169
|
+
assert_key(@parameters, 'output_path' , "Expected key 'jap_config.output_path' to exist, but does not")
|
170
|
+
assert_key(@parameters, 'sidebar_file', "Expected key 'jap_config.sidebar_file' to exist, but does not")
|
171
|
+
|
172
|
+
yield
|
173
|
+
end
|
174
|
+
|
175
|
+
def assert_key(array, key, message)
|
176
|
+
if not array.has_key? key
|
177
|
+
output(message)
|
178
|
+
exit 1
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
def print_variables
|
184
|
+
output("Current directory: " + absolute_working_path)
|
185
|
+
output("Jekyll Config File: " + absolute_config_file)
|
186
|
+
output("Source directory: " + absolute_source_path)
|
187
|
+
output("Assets files: " + absolute_assets_list.join("\n"))
|
188
|
+
output("Temporary directory: " + absolute_temp_path)
|
189
|
+
output("Building directory: " + absolute_output_path)
|
190
|
+
end
|
191
|
+
|
192
|
+
def clean
|
193
|
+
output_pages = File.join(absolute_output_path, '/pages')
|
194
|
+
output("Removing files & ouput directories ...")
|
195
|
+
rm_rf(absolute_output_path, quiet)
|
196
|
+
mkdir_p(absolute_output_path, quiet)
|
197
|
+
mkdir_p(output_pages,quiet)
|
198
|
+
end
|
199
|
+
|
200
|
+
def generate_temp_files
|
201
|
+
temp_pages = File.join(absolute_temp_path, '/pages')
|
202
|
+
temp_links = File.join(absolute_temp_path, '/links')
|
203
|
+
|
204
|
+
output("Creating Temporary Folders and Ouput Directories ...")
|
205
|
+
mkdir_p(temp_pages,quiet)
|
206
|
+
mkdir_p(temp_links, quiet)
|
207
|
+
|
208
|
+
FileList[absolute_assets_list].each do |file|
|
209
|
+
cp_r(file, temp_pages, quiet)
|
210
|
+
end
|
211
|
+
|
212
|
+
output("Rewriting *.adoc files and generating auxiliary files without front matter ...")
|
213
|
+
FileList[absolute_source_path + "/*.adoc"].each do |file|
|
214
|
+
|
215
|
+
filename = SafeYAML.load_file(file)
|
216
|
+
front_matter = {}
|
217
|
+
|
218
|
+
content = File.read(file)
|
219
|
+
if content =~ YAML_FRONT_MATTER_REGEXP
|
220
|
+
#content = $POSTMATCH
|
221
|
+
front_matter = SafeYAML.load(Regexp.last_match(1))
|
222
|
+
end
|
223
|
+
|
224
|
+
result = content.gsub(YAML_FRONT_MATTER_REGEXP, '')
|
225
|
+
|
226
|
+
if front_matter.key?('permalink')
|
227
|
+
output = File.join(temp_links, front_matter['permalink'] + '.adoc')
|
228
|
+
else
|
229
|
+
output = File.join(temp_links, File.basename(file))
|
230
|
+
end
|
231
|
+
# Write the auxiliary file for combine later in the full pdf file
|
232
|
+
File.write(output, result)
|
233
|
+
|
234
|
+
# Write the auxiliary file for individual pages
|
235
|
+
output = File.join(temp_pages, File.basename(file))
|
236
|
+
File.write(output, result)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def generate_pdf
|
241
|
+
output("Generating PDFs files for each page ...")
|
242
|
+
temp_pages = File.join(absolute_temp_path, '/pages')
|
243
|
+
pdf_pages = File.join(absolute_output_path, '/pages')
|
244
|
+
|
245
|
+
FileList[temp_pages + "/*.adoc"].each do |file|
|
246
|
+
Asciidoctor.convert_file file, backend: 'pdf', doctype: 'article', to_dir: pdf_pages , mkdirs: true, safe: :safe
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def generate_fullsite_adoc
|
251
|
+
|
252
|
+
output("Generating fullside.adoc ...")
|
253
|
+
toc = YAML.load_file(absolute_sidebar_file)
|
254
|
+
|
255
|
+
tree = create_from_menu('Root', toc['entries'], true)
|
256
|
+
|
257
|
+
Tree.printTree(tree,2)
|
258
|
+
|
259
|
+
#tree.traverse_subtree do |node|
|
260
|
+
# children = node.children.map { |child| child.title}
|
261
|
+
# puts "#{node.title}: #{children}"
|
262
|
+
#end
|
263
|
+
|
264
|
+
temp_links = File.join(absolute_temp_path, '/links')
|
265
|
+
output = File.join(absolute_temp_path,'fullsite.adoc')
|
266
|
+
File.write(output, Tree.updateContent(tree, temp_links))
|
267
|
+
|
268
|
+
output("Full site AsciiDoc generated in [ " + output +" ]")
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
def generate_fullsite_pdf
|
273
|
+
|
274
|
+
FileList[absolute_assets_list].each do |file|
|
275
|
+
cp_r(file, absolute_temp_path, quiet)
|
276
|
+
end
|
277
|
+
|
278
|
+
output = File.join(absolute_output_path,'fullsite_template.pdf')
|
279
|
+
#cp(File.join('fullsite_template.adoc'),build_fullsite_output , quiet)
|
280
|
+
cd(absolute_temp_path)
|
281
|
+
File.open("pdf-theme.yml", "w") { |file| file.write(getPdfTheme() ) }
|
282
|
+
File.open("fullsite_template.adoc", "w") { |file| file.write(getFullsiteTemplate() ) }
|
283
|
+
#content = getFullsiteTemplate()
|
284
|
+
|
285
|
+
Asciidoctor.convert_file 'fullsite_template.adoc', backend: 'pdf', mkdirs: true, safe: :safe
|
286
|
+
cp_r('fullsite_template.pdf',absolute_output_path, quiet)
|
287
|
+
output("Full site PDF generated in [ " + output +" ]")
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
def assert(condition, message)
|
292
|
+
if not condition
|
293
|
+
output(message)
|
294
|
+
exit 1
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
|
299
|
+
# Print functionallity
|
300
|
+
def output(string)
|
301
|
+
puts ' * ' + string
|
302
|
+
end
|
303
|
+
|
304
|
+
def getFullsiteTemplate()
|
305
|
+
fullsite_config = parameters['fullsite']
|
306
|
+
|
307
|
+
title = fullsite_config['title']
|
308
|
+
subtitle = fullsite_config['subtitle']
|
309
|
+
authors = fullsite_config['authors']
|
310
|
+
revision = fullsite_config['revision']
|
311
|
+
background_image = fullsite_config['background_image']
|
312
|
+
|
313
|
+
text = <<~TEXT
|
314
|
+
= #{title} : #{subtitle}
|
315
|
+
#{authors}
|
316
|
+
#{revision}
|
317
|
+
:doctype: book
|
318
|
+
:experimental:
|
319
|
+
:reproducible:
|
320
|
+
:icons: font
|
321
|
+
:listing-caption: Listing
|
322
|
+
:sectnums:
|
323
|
+
:imagesdir: ./media/
|
324
|
+
:toc:
|
325
|
+
:toclevels: 2
|
326
|
+
ifeval::["{asciidoctor-version}" < "1.5.7"]
|
327
|
+
:legacy-footnoteref:
|
328
|
+
endif::[]
|
329
|
+
ifdef::backend-pdf[]
|
330
|
+
:pdf-theme: pdf-theme.yml
|
331
|
+
:title-page:
|
332
|
+
:title-page-background-image: image:#{background_image}[fit=none,pdfwidth=100%,position=top]
|
333
|
+
:source-highlighter: rouge
|
334
|
+
//:rouge-style: github
|
335
|
+
endif::[]
|
336
|
+
:chapter-label:
|
337
|
+
|
338
|
+
:leveloffset: +1
|
339
|
+
include::fullsite.adoc[]
|
340
|
+
:leveloffset: -1
|
341
|
+
TEXT
|
342
|
+
|
343
|
+
return text
|
344
|
+
end
|
345
|
+
|
346
|
+
def getPdfTheme()
|
347
|
+
return parameters['pdf_theme'].to_yaml
|
348
|
+
end
|
349
|
+
|
350
|
+
def create_from_menu(name, children, root)
|
351
|
+
root_node = Tree::Node.new(name, '','',root)
|
352
|
+
children.each do |child|
|
353
|
+
if child.key?('entries')
|
354
|
+
root_node.add_child(create_from_menu(child['title'], child['entries'],false))
|
355
|
+
else
|
356
|
+
root_node.add_child(Tree::Node.new(child['title'],child['url'], '', false))
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
return root_node
|
361
|
+
end
|
362
|
+
|
363
|
+
end
|
364
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Tree
|
5
|
+
|
6
|
+
class Node
|
7
|
+
attr_reader :children, :content, :page, :title, :root
|
8
|
+
|
9
|
+
def initialize(title, page, content, root)
|
10
|
+
@children = []
|
11
|
+
@root = root
|
12
|
+
@page = page
|
13
|
+
@title = title
|
14
|
+
@content = content
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_content(content)
|
18
|
+
@content << "\n"
|
19
|
+
@content << content
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_child(child)
|
23
|
+
@children << child
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def traverse_subtree(&block)
|
28
|
+
node_queue = [self] # Step 1
|
29
|
+
until node_queue.empty? # Step 2
|
30
|
+
node = node_queue.shift # Step 3
|
31
|
+
yield node # Step 4
|
32
|
+
node_queue = node.children.concat(node_queue) # Step 5
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.updateContent(tree, temp_dir)
|
39
|
+
content = ''
|
40
|
+
if tree.page.length > 0
|
41
|
+
file = File.join(temp_dir, tree.page + '.adoc')
|
42
|
+
tree.add_content(File.read(file))
|
43
|
+
else
|
44
|
+
if not tree.root
|
45
|
+
tree.add_content("= " + tree.title)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if not tree.root
|
50
|
+
tree.add_content(":leveloffset: +1 \n")
|
51
|
+
end
|
52
|
+
|
53
|
+
if tree.children.length > 0
|
54
|
+
tree.children.map { |child| tree.add_content(updateContent(child, temp_dir)) }
|
55
|
+
end
|
56
|
+
|
57
|
+
if not tree.root
|
58
|
+
tree.add_content(":leveloffset: -1 \n")
|
59
|
+
end
|
60
|
+
return tree.content
|
61
|
+
end
|
62
|
+
def self.printTree(tree, level)
|
63
|
+
puts str = ("-" * level) + tree.title
|
64
|
+
if tree.children.length > 0
|
65
|
+
tree.children.map { |child| printTree(child, level + 1) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'rake_jekyll_asciidoctor_pdf/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'rake_jekyll_asciidoctor_pdf'
|
9
|
+
spec.version = RakeJekyllAsciidoctorPdf::VERSION
|
10
|
+
spec.authors = ['Guido Genzone']
|
11
|
+
spec.email = ['guido.genzone@netapp.com']
|
12
|
+
|
13
|
+
spec.summary = 'Rake tasks to convert *.adoc files from Jekyll to PDF using asciidoctor-pdf'
|
14
|
+
spec.description = 'Rake tasks to convert *.adoc files from Jekyll to PDF using asciidoctor-pdf'
|
15
|
+
spec.homepage = 'https://github.com/ggenzone/rake_jekyll_asciidoctor_pdf'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
#if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
#else
|
23
|
+
# raise 'RubyGems 2.0 or newer is required to protect against ' \
|
24
|
+
# 'public gem pushes.'
|
25
|
+
#end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
spec.bindir = 'exe'
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
spec.required_ruby_version = '>= 2.0'
|
35
|
+
|
36
|
+
spec.add_development_dependency 'bundler', '~> 2.1.4'
|
37
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
38
|
+
spec.add_development_dependency 'rubocop', '~> 0.52'
|
39
|
+
|
40
|
+
#spec.add_runtime_dependency 'rake', '>= 12.3.3'
|
41
|
+
|
42
|
+
#We shoudn't use this version for a security issue
|
43
|
+
spec.add_runtime_dependency 'rake', '>= 10.0'
|
44
|
+
spec.add_runtime_dependency 'fileutils', '>= 1.1'
|
45
|
+
spec.add_runtime_dependency 'safe_yaml', '>= 1.0.5'
|
46
|
+
spec.add_runtime_dependency 'asciidoctor-pdf', '>= 1.5.1'
|
47
|
+
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rake_jekyll_asciidoctor_pdf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.12
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guido Genzone
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.4
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.52'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.52'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: fileutils
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: safe_yaml
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.5
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.5
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: asciidoctor-pdf
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.5.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.5.1
|
111
|
+
description: Rake tasks to convert *.adoc files from Jekyll to PDF using asciidoctor-pdf
|
112
|
+
email:
|
113
|
+
- guido.genzone@netapp.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- README.adoc
|
122
|
+
- Rakefile
|
123
|
+
- bin/console
|
124
|
+
- bin/setup
|
125
|
+
- lib/rake_jekyll_asciidoctor_pdf.rb
|
126
|
+
- lib/rake_jekyll_asciidoctor_pdf/commands.rb
|
127
|
+
- lib/rake_jekyll_asciidoctor_pdf/tree.rb
|
128
|
+
- lib/rake_jekyll_asciidoctor_pdf/version.rb
|
129
|
+
- rake_jekyll_asciidoctor_pdf.gemspec
|
130
|
+
homepage: https://github.com/ggenzone/rake_jekyll_asciidoctor_pdf
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '2.0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.7.6
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Rake tasks to convert *.adoc files from Jekyll to PDF using asciidoctor-pdf
|
154
|
+
test_files: []
|