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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ec64ceeb07a9f25cb3ad68fc530cb001970e4ff0645552fbfb2bbfafba6abbc
4
- data.tar.gz: c3a0cfc1eb6aba338d52f4a05584ca5404715b103b1bf6c45ebaec336e537272
3
+ metadata.gz: fb4347a438a375868d0a2173c66ea9519341d167eb4a2ea963cb54d614c3cac4
4
+ data.tar.gz: c1f4dadda074a10b9a4431dbbf2ef975083b8c1c25beb316e547c918671b910b
5
5
  SHA512:
6
- metadata.gz: 4b892abe5a88262dd9b5691692c677925ff1678ad436a47bf624d7daccf0013c89e9cb5df426705ac65bdbd608f4c674aacc7895c92c2c34297d14ee87d5f43d
7
- data.tar.gz: 993e1bfc240f5321b7aa980b527425fad2fcc5785c3ce672388b05cd89487932b564c1e6e989304be5251758b2c200073ce3e8af9f7b12eb6e876d391a6ba050
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
- 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,13 @@
1
1
  source: book.adoc
2
- #formats: ['html', 'pdf', 'epub', 'mobi']
3
- #theme_dir:
4
- #template_dir:
5
- #page_level: 1
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
@@ -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,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: ['html', 'pdf', 'epub', 'mobi']
42
- #theme_dir:
43
- #template_dir:
44
- #page_level: 1
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
@@ -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.beta1"
2
+ VERSION = "0.0.4"
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 %} />