asciibook 0.0.2.beta2 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e3a83946ce2d5ad304d60068e12b839012d7d22b78abfd92733825baae843e0
4
- data.tar.gz: 262169c65ba8c8acae9de4de8a4dc4113b5eec8265ff1b625b5bc4a898cae55d
3
+ metadata.gz: e561b902bdbeba9e4d2d4031bcbd0fec7f666e68fe0a2bc58a4ea3a11664411e
4
+ data.tar.gz: 12c0feb2787ef840f7971f21ba7bb661de43d5aec1b5031a5550b3723728478c
5
5
  SHA512:
6
- metadata.gz: f1bcc67b55ef8c5945524eac9814fd0c9dd743a35e309d99c7d68296ccc24e0caf7988de0e2a0af1304f4fe42f7977a004d65ff547c879ed32b8e3832f4036ae
7
- data.tar.gz: 32ec9e68931f4d409a39e053c716989b4e66b06ca0ae1406c85683fbbee88af346141eb33bf5495cb04c53f3a8a319fc0986aaa88562d8f06da662b79e3295d6
6
+ metadata.gz: 343136908ff91ccf947ff08abbabb3cae77432266e74929c154dd35089997c6ea6b4427b1ff23fe471cb464aa72322d4a5ea39e62824fa60199b9472f441541a
7
+ data.tar.gz: ae4077c7403915eac598f120c5ec6fbcca50f70efa719f9f41c7c97d26316c2c03b15b266f01e5f08be7bb740d47ecc72efe36288dff3337bbb5a28caac880cc
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
- If you are familiar with Ruby, you can use <<manual-installation>>.
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
- If your are familiar with Docker, you can use <<docker-installation>>.
10
+ You can download and install docker in https://www.docker.com/products/docker-desktop .
11
11
 
12
- [[manual-installation]]
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
- For a existing AsciiDoc file, run this command to build all format books:
21
+ First, enter container enviroment in your AsciiDoc file diretory:
55
22
 
56
23
  [source, console]
57
24
  ----
58
- $ ascibook build mybook.adoc
25
+ $ docker run -it -v $(pwd):/asciibook asciibook/asciibook bash
26
+ /asciibook #
59
27
  ----
60
28
 
61
- Generated books will put in `build` directory.
29
+ Following command is executed inside the container environment.
62
30
 
63
- Or generate only partial format:
31
+ For a existing AsciiDoc file, run this command to build all formats:
64
32
 
65
33
  [source, console]
66
34
  ----
67
- $ asciibook build mybook.adoc --format html
68
- $ asciibook build mybook.adoc --format pdf,mobi
35
+ /asciibook # ascibook build mybook.adoc
69
36
  ----
70
37
 
71
- If you don't want to enter the parameters repeatedly, you can create a configuration file for the document:
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
- $ asciibook init mybook.adoc
44
+ /asciibook # asciibook build mybook.adoc --format html
45
+ /asciibook # asciibook build mybook.adoc --format pdf,mobi
76
46
  ----
77
47
 
78
- It will create a config file `asciibook.yml` in the same directory, edit config for your need, then use this command to build next time:
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
- $ asciibook build
52
+ /asciibook # asciibook init mybook.adoc
83
53
  ----
84
54
 
85
- Use this command to create a empty AsciiDoc and config file:
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
- $ asciibook new mybook
59
+ /asciibook # asciibook build
90
60
  ----
91
61
 
92
62
  == Development
@@ -1,5 +1,14 @@
1
1
  source: book.adoc
2
- #formats: ['html', 'pdf', 'epub', 'mobi']
3
- #theme_dir:
4
- #template_dir:
5
- #page_level: 1
2
+
3
+ # formats:
4
+ # - html
5
+ # - pdf
6
+ # - epub
7
+ # - mobi
8
+ #
9
+ # theme_dir:
10
+ # template_dir:
11
+ # page_level: 1
12
+ #
13
+ # plugins:
14
+ # - asciidoctor-diagram
@@ -46,21 +46,24 @@ module Asciibook
46
46
  doc.attributes['cover-image']
47
47
  end
48
48
 
49
- def toc
50
- @toc ||= outline(doc)
49
+ def outline
50
+ outline_node(doc)
51
51
  end
52
52
 
53
- def outline(node)
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
- section_data = {
57
- 'title' => section.xreftext,
58
- 'path' => section.page ? section.page.path : "#{find_page_node(section).page.path}##{section.id}"
59
- }
60
- if section.sections.count > 0 and section.level < (doc.attributes['toclevels'] || 2).to_i
61
- section_data['items'] = outline(section)
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
- 'toc' => toc
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
- #clean_workdir
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"
@@ -38,10 +38,19 @@ 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: ['html', 'pdf', 'epub', 'mobi']
42
- #theme_dir:
43
- #template_dir:
44
- #page_level: 1
41
+
42
+ # formats:
43
+ # - html
44
+ # - pdf
45
+ # - epub
46
+ # - mobi
47
+ #
48
+ # theme_dir:
49
+ # template_dir:
50
+ # page_level: 1
51
+ #
52
+ # plugins:
53
+ # - asciidoctor-diagram
45
54
  EOF
46
55
  end
47
56
  else
@@ -58,6 +67,7 @@ module Asciibook
58
67
  c.option :template_dir, '--template-dir DIR', 'Template dir.'
59
68
  c.option :dest_dir, '--dest-dir DIR', 'Destination dir.'
60
69
  c.option :page_level, '--page-level NUM', Integer, 'Page split base on section level, default is 1.'
70
+ c.option :plugins, '--plugin PLUGIN1[,PLUGIN2[,PLUGIN3...]]', Array, 'Require ruby gem or ruby script plugin.'
61
71
  c.action do |args, options|
62
72
  source = args[0] || '.'
63
73
  if File.directory?(source)
@@ -66,8 +76,10 @@ module Asciibook
66
76
  hash
67
77
  end
68
78
  options = config_options.merge(options)
79
+ load_plugins(options[:plugins])
69
80
  Asciibook::Book.load_file(options.delete(:source), options).build
70
81
  elsif File.file?(source)
82
+ load_plugins(options[:plugins])
71
83
  Asciibook::Book.load_file(source, options).build
72
84
  else
73
85
  abort "Build target '#{source}' neither a folder nor a file"
@@ -81,5 +93,13 @@ module Asciibook
81
93
 
82
94
  p.go(argv)
83
95
  end
96
+
97
+ def self.load_plugins(plugins)
98
+ if plugins
99
+ plugins.each do |plugin|
100
+ require plugin
101
+ end
102
+ end
103
+ end
84
104
  end
85
105
  end
@@ -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
@@ -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
  }
@@ -1,3 +1,3 @@
1
1
  module Asciibook
2
- VERSION = "0.0.2.beta2"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/asciibook.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "asciidoctor"
2
+ require "asciidoctor-mathematical"
2
3
  require "rexml/document"
3
4
  require "nokogiri"
4
5
  require "fileutils"
@@ -1,4 +1,9 @@
1
1
  <div class="admonition admonition-{{ node.attributes.name }}" {% if node.id %}id="{{ node.id }}"{% endif %}>
2
- {% if node.title %}<h5>{{ node.title }}</h5>{% endif %}
3
- {{ node.content }}
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.attributes.target }}"
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>
@@ -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 %} />