asciibook 0.0.2.beta1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +18 -48
- data/book_template/asciibook.yml +12 -4
- data/lib/asciibook/book.rb +15 -12
- data/lib/asciibook/builders/epub_builder.rb +2 -2
- data/lib/asciibook/builders/html_builder.rb +2 -2
- data/lib/asciibook/builders/pdf_builder.rb +4 -3
- data/lib/asciibook/command.rb +23 -4
- data/lib/asciibook/converter.rb +9 -1
- data/lib/asciibook/page.rb +38 -1
- data/lib/asciibook/version.rb +1 -1
- data/lib/asciibook.rb +1 -0
- data/templates/admonition.html +7 -2
- data/templates/image.html +1 -1
- data/templates/inline_break.html +1 -0
- data/templates/inline_callout.html +1 -1
- data/templates/inline_image.html +3 -1
- data/theme/html/html.css +352 -39
- data/theme/html/html.js +134 -4
- data/theme/html/icon.png +0 -0
- data/theme/html/layout.html +122 -52
- data/theme/mobi/fontawesome/solid.css +13 -0
- data/theme/mobi/mobi.css +1 -1
- data/theme/pdf/pdf.css +6 -0
- data/theme/share/default.css +70 -1
- metadata +47 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb4347a438a375868d0a2173c66ea9519341d167eb4a2ea963cb54d614c3cac4
|
4
|
+
data.tar.gz: c1f4dadda074a10b9a4431dbbf2ef975083b8c1c25beb316e547c918671b910b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0bf598a7570cacd63f6939c55a115f28651b375d87711a08486a6419af87947521ab12ada2b6984efacc3716d3226411f62109b552f877ddd4090c9e1095cad
|
7
|
+
data.tar.gz: 0db9909fc5f9cb62775d5d3452522090e79567352cbdd433b9d1162e97bec5a9e0989245f637551c26b5b6cab47d87c8e5f894127ea2969b4f1fbddec0fb5094
|
data/README.adoc
CHANGED
@@ -5,88 +5,58 @@ Asciibook is an Ebook generator for converting AsciiDoc to HTML, PDF, EPUB and M
|
|
5
5
|
|
6
6
|
== Installation
|
7
7
|
|
8
|
-
|
8
|
+
Asciibook uses docker as distribution tool. Docker helps deal with dependencies, keeps the local environment clean, and works well with CI / CD tools.
|
9
9
|
|
10
|
-
|
10
|
+
You can download and install docker in https://www.docker.com/products/docker-desktop .
|
11
11
|
|
12
|
-
|
13
|
-
=== Manual installation
|
14
|
-
|
15
|
-
Install by rubygems:
|
16
|
-
|
17
|
-
[source, console]
|
18
|
-
----
|
19
|
-
$ gem install asciibook
|
20
|
-
----
|
21
|
-
|
22
|
-
For PDF generate, download and install wkhtmltopdf in https://wkhtmltopdf.org/downloads.html .
|
23
|
-
|
24
|
-
For Mobi generate, download and install kindlegen in https://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211 .
|
25
|
-
|
26
|
-
|
27
|
-
[[docker-installation]]
|
28
|
-
=== Docker Installation
|
29
|
-
|
30
|
-
Pull docker image:
|
12
|
+
After installed docker, Pull the docker image:
|
31
13
|
|
32
14
|
[source, consle]
|
33
15
|
----
|
34
16
|
$ docker pull asciibook/asciibook
|
35
17
|
----
|
36
18
|
|
37
|
-
Then use asciibook CLI in this way:
|
38
|
-
|
39
|
-
[source, console]
|
40
|
-
----
|
41
|
-
$ docker run -v $(pwd):/asciibook asciibook/asciibook asciibook build mybook.adoc
|
42
|
-
----
|
43
|
-
|
44
|
-
Or enter the container environment to avoid repeating lengthy commands:
|
45
|
-
|
46
|
-
[source, console]
|
47
|
-
----
|
48
|
-
$ docker run -v $(pwd):/asciibook asciibook/asciibook bash
|
49
|
-
/asciibook $ asciibook build mybook.adoc
|
50
|
-
----
|
51
|
-
|
52
19
|
== Usage
|
53
20
|
|
54
|
-
|
21
|
+
First, enter container enviroment in your AsciiDoc file diretory:
|
55
22
|
|
56
23
|
[source, console]
|
57
24
|
----
|
58
|
-
$
|
25
|
+
$ docker run -it -v $(pwd):/asciibook asciibook/asciibook bash
|
26
|
+
/asciibook #
|
59
27
|
----
|
60
28
|
|
61
|
-
|
29
|
+
Following command is executed inside the container environment.
|
62
30
|
|
63
|
-
|
31
|
+
For a existing AsciiDoc file, run this command to build all formats:
|
64
32
|
|
65
33
|
[source, console]
|
66
34
|
----
|
67
|
-
|
68
|
-
$ asciibook build mybook.adoc --format pdf,mobi
|
35
|
+
/asciibook # ascibook build mybook.adoc
|
69
36
|
----
|
70
37
|
|
71
|
-
|
38
|
+
Generated results will be placed in the `build` folder.
|
39
|
+
|
40
|
+
Or generate partial formats:
|
72
41
|
|
73
42
|
[source, console]
|
74
43
|
----
|
75
|
-
|
44
|
+
/asciibook # asciibook build mybook.adoc --format html
|
45
|
+
/asciibook # asciibook build mybook.adoc --format pdf,mobi
|
76
46
|
----
|
77
47
|
|
78
|
-
|
48
|
+
If you don't want to type the parameters repeatedly, you can create a configuration file for the document:
|
79
49
|
|
80
50
|
[source, console]
|
81
51
|
----
|
82
|
-
|
52
|
+
/asciibook # asciibook init mybook.adoc
|
83
53
|
----
|
84
54
|
|
85
|
-
|
55
|
+
It will create a config file named `asciibook.yml` in the same directory, edit config for your need, then use this command to build next time:
|
86
56
|
|
87
57
|
[source, console]
|
88
58
|
----
|
89
|
-
|
59
|
+
/asciibook # asciibook build
|
90
60
|
----
|
91
61
|
|
92
62
|
== Development
|
data/book_template/asciibook.yml
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
source: book.adoc
|
2
|
-
#formats:
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
2
|
+
# formats:
|
3
|
+
# - html
|
4
|
+
# - pdf
|
5
|
+
# - epub
|
6
|
+
# - mobi
|
7
|
+
#
|
8
|
+
# theme_dir:
|
9
|
+
# template_dir:
|
10
|
+
# page_level: 1
|
11
|
+
#
|
12
|
+
# plugins:
|
13
|
+
# - asciidoctor-diagram
|
data/lib/asciibook/book.rb
CHANGED
@@ -46,21 +46,24 @@ module Asciibook
|
|
46
46
|
doc.attributes['cover-image']
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
|
49
|
+
def outline
|
50
|
+
outline_node(doc)
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
# book outline only list sections that split as page
|
54
|
+
def outline_node(node)
|
54
55
|
data = []
|
55
56
|
node.sections.each do |section|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
if section.page
|
58
|
+
section_data = {
|
59
|
+
'title' => section.xreftext,
|
60
|
+
'path' => section.page.path
|
61
|
+
}
|
62
|
+
if section.sections.count > 0 and section.level < @page_level
|
63
|
+
section_data['items'] = outline_node(section)
|
64
|
+
end
|
65
|
+
data << section_data
|
62
66
|
end
|
63
|
-
data << section_data
|
64
67
|
end
|
65
68
|
data
|
66
69
|
end
|
@@ -79,7 +82,7 @@ module Asciibook
|
|
79
82
|
{
|
80
83
|
'title' => doc.attributes['doctitle'],
|
81
84
|
'attributes' => doc.attributes,
|
82
|
-
'
|
85
|
+
'outline' => outline
|
83
86
|
}
|
84
87
|
end
|
85
88
|
|
@@ -143,7 +146,7 @@ module Asciibook
|
|
143
146
|
end
|
144
147
|
|
145
148
|
def assets
|
146
|
-
Dir.glob('**/*.{jpg,png,gif,mp3,mp4,ogg,wav}', File::FNM_CASEFOLD, base: @base_dir).reject do |path|
|
149
|
+
Dir.glob('**/*.{jpg,png,svg,gif,mp3,mp4,ogg,wav}', File::FNM_CASEFOLD, base: @base_dir).reject do |path|
|
147
150
|
@exclude_patterns.any? do |pattern|
|
148
151
|
File.fnmatch?(pattern, path)
|
149
152
|
end
|
@@ -32,11 +32,11 @@ module Asciibook
|
|
32
32
|
book.add_item(@book.cover_image_path, content: File.open(File.join(@book.base_dir, @book.cover_image_path)), id: 'cover_image').cover_image
|
33
33
|
end
|
34
34
|
|
35
|
-
Dir.glob('**/*.{jpb,png,gif,svg,css,js}', File::FNM_CASEFOLD, base: @theme_share_dir).each do |path|
|
35
|
+
Dir.glob('**/*.{jpb,png,gif,svg,css,js,eot,ttf,woff,woff2}', File::FNM_CASEFOLD, base: @theme_share_dir).each do |path|
|
36
36
|
book.add_item path, content: File.open(File.join(@theme_share_dir, path)), id: id_pool.generate_key(prefix: 'theme_asset_')
|
37
37
|
end
|
38
38
|
|
39
|
-
Dir.glob('**/*.{jpb,png,gif,svg,css,js}', File::FNM_CASEFOLD, base: @theme_dir).each do |path|
|
39
|
+
Dir.glob('**/*.{jpb,png,gif,svg,css,js,eot,ttf,woff,woff2}', File::FNM_CASEFOLD, base: @theme_dir).each do |path|
|
40
40
|
book.add_item path, content: File.open(File.join(@theme_dir, path)), id: id_pool.generate_key(prefix: 'theme_asset_')
|
41
41
|
end
|
42
42
|
|
@@ -32,11 +32,11 @@ module Asciibook
|
|
32
32
|
copy_file(path, @book.base_dir, @dest_dir)
|
33
33
|
end
|
34
34
|
|
35
|
-
Dir.glob('**/*.{jpb,png,gif,svg,css,js}', File::FNM_CASEFOLD, base: @theme_share_dir).each do |path|
|
35
|
+
Dir.glob('**/*.{jpb,png,gif,svg,css,js,eot,ttf,woff,woff2}', File::FNM_CASEFOLD, base: @theme_share_dir).each do |path|
|
36
36
|
copy_file(path, @theme_share_dir, @dest_dir)
|
37
37
|
end
|
38
38
|
|
39
|
-
Dir.glob('**/*.{jpb,png,gif,svg,css,js}', File::FNM_CASEFOLD, base: @theme_dir).each do |path|
|
39
|
+
Dir.glob('**/*.{jpb,png,gif,svg,css,js,eot,ttf,woff,woff2}', File::FNM_CASEFOLD, base: @theme_dir).each do |path|
|
40
40
|
copy_file(path, @theme_dir, @dest_dir)
|
41
41
|
end
|
42
42
|
end
|
@@ -15,7 +15,7 @@ module Asciibook
|
|
15
15
|
copy_assets
|
16
16
|
generate_header_footer
|
17
17
|
generate_pdf
|
18
|
-
|
18
|
+
clean_workdir
|
19
19
|
end
|
20
20
|
|
21
21
|
def prepare_workdir
|
@@ -44,11 +44,11 @@ module Asciibook
|
|
44
44
|
copy_file(path, @book.base_dir, @tmp_dir)
|
45
45
|
end
|
46
46
|
|
47
|
-
Dir.glob('**/*.{jpb,png,gif,svg,css,js}', File::FNM_CASEFOLD, base: @theme_share_dir).each do |path|
|
47
|
+
Dir.glob('**/*.{jpb,png,gif,svg,css,js,eot,ttf,woff,woff2}', File::FNM_CASEFOLD, base: @theme_share_dir).each do |path|
|
48
48
|
copy_file(path, @theme_share_dir, @tmp_dir)
|
49
49
|
end
|
50
50
|
|
51
|
-
Dir.glob('**/*.{jpb,png,gif,svg,css,js}', File::FNM_CASEFOLD, base: @theme_dir).each do |path|
|
51
|
+
Dir.glob('**/*.{jpb,png,gif,svg,css,js,eot,ttf,woff,woff2}', File::FNM_CASEFOLD, base: @theme_dir).each do |path|
|
52
52
|
copy_file(path, @theme_dir, @tmp_dir)
|
53
53
|
end
|
54
54
|
end
|
@@ -123,6 +123,7 @@ module Asciibook
|
|
123
123
|
command << 'toc' << '--xsl-style-sheet' << 'toc.xsl'
|
124
124
|
else
|
125
125
|
command << page.path
|
126
|
+
command << '--allow' << File.expand_path(@tmp_dir)
|
126
127
|
end
|
127
128
|
end
|
128
129
|
filename = "#{@book.basename}.pdf"
|
data/lib/asciibook/command.rb
CHANGED
@@ -38,10 +38,18 @@ module Asciibook
|
|
38
38
|
File.open(File.join(dir, 'asciibook.yml'), 'w') do |file|
|
39
39
|
file.write <<~EOF
|
40
40
|
source: #{filename}
|
41
|
-
#formats:
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
41
|
+
# formats:
|
42
|
+
# - html
|
43
|
+
# - pdf
|
44
|
+
# - epub
|
45
|
+
# - mobi
|
46
|
+
#
|
47
|
+
# theme_dir:
|
48
|
+
# template_dir:
|
49
|
+
# page_level: 1
|
50
|
+
#
|
51
|
+
# plugins:
|
52
|
+
# - asciidoctor-diagram
|
45
53
|
EOF
|
46
54
|
end
|
47
55
|
else
|
@@ -58,6 +66,7 @@ module Asciibook
|
|
58
66
|
c.option :template_dir, '--template-dir DIR', 'Template dir.'
|
59
67
|
c.option :dest_dir, '--dest-dir DIR', 'Destination dir.'
|
60
68
|
c.option :page_level, '--page-level NUM', Integer, 'Page split base on section level, default is 1.'
|
69
|
+
c.option :plugins, '-r', '--require PLUGIN1[,PLUGIN2[,PLUGIN3...]]', Array, 'Require plugins'
|
61
70
|
c.action do |args, options|
|
62
71
|
source = args[0] || '.'
|
63
72
|
if File.directory?(source)
|
@@ -66,8 +75,10 @@ module Asciibook
|
|
66
75
|
hash
|
67
76
|
end
|
68
77
|
options = config_options.merge(options)
|
78
|
+
load_plugins(options[:plugins])
|
69
79
|
Asciibook::Book.load_file(options.delete(:source), options).build
|
70
80
|
elsif File.file?(source)
|
81
|
+
load_plugins(options[:plugins])
|
71
82
|
Asciibook::Book.load_file(source, options).build
|
72
83
|
else
|
73
84
|
abort "Build target '#{source}' neither a folder nor a file"
|
@@ -81,5 +92,13 @@ module Asciibook
|
|
81
92
|
|
82
93
|
p.go(argv)
|
83
94
|
end
|
95
|
+
|
96
|
+
def self.load_plugins(plugins)
|
97
|
+
if plugins
|
98
|
+
plugins.each do |plugin|
|
99
|
+
require plugin
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
84
103
|
end
|
85
104
|
end
|
data/lib/asciibook/converter.rb
CHANGED
@@ -127,9 +127,15 @@ module Asciibook
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def block_to_hash(node)
|
130
|
-
abstract_block_to_hash(node).merge!({
|
130
|
+
data = abstract_block_to_hash(node).merge!({
|
131
131
|
'blockname' => node.blockname
|
132
132
|
})
|
133
|
+
|
134
|
+
if node.node_name == 'image'
|
135
|
+
data['target'] = node.image_uri(node.attributes['target'])
|
136
|
+
end
|
137
|
+
|
138
|
+
data
|
133
139
|
end
|
134
140
|
|
135
141
|
def list_to_hash(node)
|
@@ -235,6 +241,8 @@ module Asciibook
|
|
235
241
|
end
|
236
242
|
|
237
243
|
data['id'] = id
|
244
|
+
when 'inline_image'
|
245
|
+
data['target'] = node.image_uri(node.target)
|
238
246
|
end
|
239
247
|
|
240
248
|
data
|
data/lib/asciibook/page.rb
CHANGED
@@ -14,7 +14,41 @@ module Asciibook
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def content
|
17
|
-
node.convert
|
17
|
+
@content ||= node.convert
|
18
|
+
end
|
19
|
+
|
20
|
+
def doc
|
21
|
+
@doc ||= Nokogiri::HTML.fragment(content)
|
22
|
+
end
|
23
|
+
|
24
|
+
def image_url
|
25
|
+
doc.css('img').first&.attr('src')
|
26
|
+
end
|
27
|
+
|
28
|
+
def description
|
29
|
+
doc.css('p').first&.text
|
30
|
+
end
|
31
|
+
|
32
|
+
def outline
|
33
|
+
outline_node(@node)
|
34
|
+
end
|
35
|
+
|
36
|
+
# page outline only list sections that not split as page
|
37
|
+
def outline_node(node)
|
38
|
+
data = []
|
39
|
+
node.sections.each do |section|
|
40
|
+
if !section.page
|
41
|
+
section_data = {
|
42
|
+
'title' => section.xreftext,
|
43
|
+
'path' => "##{section.id}"
|
44
|
+
}
|
45
|
+
if section.sections.count > 0
|
46
|
+
section_data['items'] = outline_node(section)
|
47
|
+
end
|
48
|
+
data << section_data
|
49
|
+
end
|
50
|
+
end
|
51
|
+
data
|
18
52
|
end
|
19
53
|
|
20
54
|
def to_hash
|
@@ -22,6 +56,9 @@ module Asciibook
|
|
22
56
|
'path' => path,
|
23
57
|
'title' => title,
|
24
58
|
'content' => content,
|
59
|
+
'image_url' => image_url,
|
60
|
+
'description' => description,
|
61
|
+
'outline' => outline,
|
25
62
|
'prev_page' => prev_page && { 'path' => prev_page.path, 'title' => prev_page.title },
|
26
63
|
'next_page' => next_page && { 'path' => next_page.path, 'title' => next_page.title }
|
27
64
|
}
|
data/lib/asciibook/version.rb
CHANGED
data/lib/asciibook.rb
CHANGED
data/templates/admonition.html
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
<div class="admonition admonition-{{ node.attributes.name }}" {% if node.id %}id="{{ node.id }}"{% endif %}>
|
2
|
-
|
3
|
-
|
2
|
+
<div class="admonition-icon">
|
3
|
+
<b>{{ node.attributes.name | upcase }}</b>
|
4
|
+
</div>
|
5
|
+
<div class="admonition-content">
|
6
|
+
{% if node.title %}<h5>{{ node.title }}</h5>{% endif %}
|
7
|
+
{{ node.content }}
|
8
|
+
</div>
|
4
9
|
</div>
|
data/templates/image.html
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<figure class="image" {% if node.id %}id="{{ node.id }}"{% endif %}>
|
2
2
|
{% if node.attributes.link %}<a href="{{ node.attributes.link }}">{% endif %}
|
3
|
-
<img src="{{ node.
|
3
|
+
<img src="{{ node.target }}"
|
4
4
|
{% if node.attributes.alt %}alt="{{ node.attributes.alt }}"{% endif %}
|
5
5
|
{% if node.attributes.width %}width="{{ node.attributes.width }}"{% endif %}
|
6
6
|
{% if node.attributes.height %}height="{{ node.attributes.height }}"{% endif %} />
|
@@ -0,0 +1 @@
|
|
1
|
+
{{ node.text }}<br/>
|
@@ -1 +1 @@
|
|
1
|
-
<a class="callout" id="callout-{{ node.id }}" href="#colist-{{ node.id }}">{{ node.text }}</a>
|
1
|
+
<a class="callout" id="callout-{{ node.id }}" href="#colist-{{ node.id }}">{{ node.text }}</a>
|
data/templates/inline_image.html
CHANGED
@@ -1,3 +1,5 @@
|
|
1
1
|
<img src="{{ node.target }}"
|
2
2
|
{% if node.attributes.alt %}alt="{{ node.attributes.alt }}"{% endif %}
|
3
|
-
{% if node.attributes.title %}title="{{ node.attributes.title }}"{% endif %}
|
3
|
+
{% if node.attributes.title %}title="{{ node.attributes.title }}"{% endif %}
|
4
|
+
{% if node.attributes.width %}width="{{ node.attributes.width }}"{% endif %}
|
5
|
+
{% if node.attributes.height %}height="{{ node.attributes.height }}"{% endif %} />
|