asciidoctor-htmlbook 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68420eba44be59d8ae3fea93a02d13416f5f18233c49c95438c6e381f6d19035
4
- data.tar.gz: 75cad414ceefed3898346561a600ad8b8d7095e767a58f835f521276fc8b6394
3
+ metadata.gz: 84191fe5cc45f3e8edc81303b20799f6a44ed3774cfd6dfd2f7245bd2a242099
4
+ data.tar.gz: cf845626c0e4fbedccbcc6038a9096364939a54209d5cd7ff866596c6b3d6ef0
5
5
  SHA512:
6
- metadata.gz: 2c13ebcab599dac5a574b5e634d3fd562fb6b7ce933c0b69e6fccc3802a9057e2cbe1c867388d3cf80bf64b8d8943640c189e118933dccba30804a3e8798fdba
7
- data.tar.gz: 8aa6a5ff99cdf3471c2c21416e099c0fc0b6e8cf0bf15bec4c69a324cedc763c5a7963e24c1ed22e45bb32a06987945ce85c5b4e7fa2c05937c83f3d5e36e989
6
+ metadata.gz: 38badaa8c38b42a6c99954f2b1c478fa8658d5d40c196cea664e0ad5128a387fa29b0b198abd7bc60986b18e2b2600cb41d39653de894b724b4522ade57ef300
7
+ data.tar.gz: dfdd788a982e8c1e4bdc32eeaac3b0464867ca6c41e241f1da8eb3858e80d8ae12eb77f13dee33ca37668b85e2c634030085aadd41bd8c07e9ca3843de8d31da
@@ -4,4 +4,4 @@ rvm:
4
4
  - 2.4
5
5
  - 2.5
6
6
  - 2.6
7
- before_install: gem install bundler -v 1.13.7
7
+ before_install: gem install bundler -v 2.0.2
@@ -1,5 +1,12 @@
1
1
  == master
2
2
 
3
+ == v0.0.5
4
+
5
+ - Fix body h1
6
+ - Fix toclevel type error
7
+ - Rename `*_to_liquid` methods to `*_to_hash` in converter.rb
8
+ - Use toc attribute instead of section name
9
+
3
10
  == v0.0.4
4
11
 
5
12
  - Update to asciidoctor 2.0
@@ -102,11 +102,6 @@ Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook', header_footer
102
102
 
103
103
  You can overwrite default templates by adding `:template_dir` option:
104
104
 
105
- [source, console]
106
- ----
107
- $ asciidoctor-htmlbook -T path/to/templates basic-example.adoc
108
- ----
109
-
110
105
  [source, ruby]
111
106
  ----
112
107
  Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook', template_dir: 'path/to/templates'
@@ -119,23 +114,6 @@ asciidoctor-htmlbook template do not compatible with asciidoctor built-in templa
119
114
  View link:./templates[] for more info.
120
115
  --
121
116
 
122
- == Add Table of Contents
123
-
124
- Asciidoctor-htmlbook ignore `:toc:` attribute in Asciidoctor, instead you can use toc section:
125
-
126
- [source, asciidoc]
127
- --
128
- [preface]
129
- == Preface
130
-
131
- [toc]
132
- == Table of Contents
133
-
134
- == Chapter
135
- --
136
-
137
- So that you can control position of toc.
138
-
139
117
  == Development
140
118
 
141
119
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "asciidoctor", "~> 2.0"
25
25
  spec.add_runtime_dependency "liquid", "~> 4.0"
26
26
 
27
- spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "bundler", "~> 2.1"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
29
29
  spec.add_development_dependency "minitest", "~> 5.0"
30
30
  end
@@ -7,20 +7,13 @@ module Asciidoctor
7
7
 
8
8
  def initialize(backend, options = {})
9
9
  super
10
- @template_dirs = (options[:template_dirs] || []).push(DEFAULT_TEMPLATE_PATH)
10
+ init_backend_traits outfilesuffix: '.html'
11
+ @template_dirs = (options[:template_dirs] || []).prepend(DEFAULT_TEMPLATE_PATH)
11
12
  @templates = {}
12
13
  end
13
14
 
14
- def convert(node, transform = nil, options = {})
15
- template = if (node.node_name == 'document' && transform == 'embedded')
16
- get_template('embedded')
17
- elsif node.node_name == 'section' && node.sectname == 'toc'
18
- get_template('toc')
19
- else
20
- get_template(node.node_name)
21
- end
22
-
23
- template.render 'node' => node_to_liquid(node)
15
+ def convert(node, transform = node.node_name, options = {})
16
+ get_template(transform).render 'node' => node_to_hash(node)
24
17
  end
25
18
 
26
19
  private
@@ -28,7 +21,7 @@ module Asciidoctor
28
21
  def get_template(name)
29
22
  return @templates[name] if @templates[name]
30
23
 
31
- @template_dirs.each do |template_dir|
24
+ @template_dirs.reverse.each do |template_dir|
32
25
  path = File.join template_dir, "#{name}.html"
33
26
  if File.exist?(path)
34
27
  @templates[name] = Liquid::Template.parse(File.read(path))
@@ -43,48 +36,36 @@ module Asciidoctor
43
36
  @templates[name]
44
37
  end
45
38
 
46
- def node_to_liquid(node)
39
+ def node_to_hash(node)
47
40
  case node
48
41
  when Asciidoctor::Document
49
- document_to_liquid(node)
42
+ document_to_hash(node)
50
43
  when Asciidoctor::Section
51
- section_to_liquid(node)
44
+ section_to_hash(node)
52
45
  when Asciidoctor::Block
53
- block_to_liquid(node)
46
+ block_to_hash(node)
54
47
  when Asciidoctor::List
55
- list_to_liquid(node)
48
+ list_to_hash(node)
56
49
  when Asciidoctor::Table
57
- table_to_liquid(node)
50
+ table_to_hash(node)
58
51
  when Asciidoctor::Inline
59
- inline_to_liquid(node)
52
+ inline_to_hash(node)
60
53
  else
61
- raise "Uncatch type #{node} #{node.attributes}"
54
+ raise "Uncatched type #{node} #{node.attributes}"
62
55
  end
63
56
  end
64
57
 
65
- def abstract_node_to_liquid(node)
58
+ def abstract_node_to_hash(node)
66
59
  {
67
60
  'context' => node.context.to_s,
68
61
  'node_name' => node.node_name,
69
62
  'id' => node.id,
70
- 'attributes' => node.attributes,
71
- 'document' => document_info(node.document)
72
- }
73
- end
74
-
75
- def document_info(document)
76
- @document_info ||= {
77
- 'references' => {
78
- 'refs' => document.references[:refs].map { |refid, node|
79
- [refid, { 'xreftext' => node.xreftext }]
80
- }.to_h
81
- },
82
- 'attributes' => document.attributes
63
+ 'attributes' => node.attributes
83
64
  }
84
65
  end
85
66
 
86
- def abstract_block_to_liquid(node)
87
- abstract_node_to_liquid(node).merge({
67
+ def abstract_block_to_hash(node)
68
+ abstract_node_to_hash(node).merge!({
88
69
  'level' => node.level,
89
70
  'title' => node.title,
90
71
  'caption' => node.caption,
@@ -95,16 +76,18 @@ module Asciidoctor
95
76
  })
96
77
  end
97
78
 
98
- def document_to_liquid(node)
99
- abstract_block_to_liquid(node).merge({
79
+ def document_to_hash(node)
80
+ abstract_block_to_hash(node).merge!({
100
81
  'header' => {
101
82
  'title' => (node.header && node.header.title)
102
- }
83
+ },
84
+ 'title' => node.attributes['doctitle'],
85
+ 'toc' => outline(node)
103
86
  })
104
87
  end
105
88
 
106
- def section_to_liquid(node)
107
- attributes = abstract_block_to_liquid(node).merge({
89
+ def section_to_hash(node)
90
+ abstract_block_to_hash(node).merge!({
108
91
  'index' => node.index,
109
92
  'number' => node.number,
110
93
  'sectname' => (node.sectname == 'section' ? "sect#{node.level}" : node.sectname),
@@ -112,30 +95,24 @@ module Asciidoctor
112
95
  'numbered' => node.numbered,
113
96
  'sectnum' => node.sectnum
114
97
  })
115
-
116
- if node.sectname == 'toc'
117
- attributes['content'] = outline(node.document)
118
- end
119
-
120
- attributes
121
98
  end
122
99
 
123
- def block_to_liquid(node)
124
- abstract_block_to_liquid(node).merge({
100
+ def block_to_hash(node)
101
+ abstract_block_to_hash(node).merge!({
125
102
  'blockname' => node.blockname
126
103
  })
127
104
  end
128
105
 
129
106
  def outline(node)
130
- result = ""
131
- if node.sections.any? && node.level < (node.document.attributes['toclevels'] || 2)
107
+ result = ''
108
+ if node.sections.any? && node.level < (node.document.attributes['toclevels'] || 2).to_i
132
109
  result << "<ol>"
133
110
  node.sections.each do |section|
134
111
  next if section.sectname == 'toc'
135
112
 
136
113
  result << "<li>"
137
114
  result << %Q(<a href="##{section.id}">)
138
- result << "#{section.sectnum} " if section.numbered && section.level < (node.document.attributes['sectnumlevels'] || 3)
115
+ result << "#{section.sectnum} " if section.numbered && section.level < (node.document.attributes['sectnumlevels'] || 3).to_i
139
116
  result << section.title
140
117
  result << "</a>"
141
118
  result << outline(section)
@@ -146,43 +123,43 @@ module Asciidoctor
146
123
  result
147
124
  end
148
125
 
149
- def list_to_liquid(node)
126
+ def list_to_hash(node)
150
127
  case node.context
151
128
  when :dlist
152
- abstract_block_to_liquid(node).merge({
129
+ abstract_block_to_hash(node).merge!({
153
130
  'items' => node.items.map { |terms, item|
154
131
  {
155
- 'terms' => terms.map {|term| listitem_to_liquid(term) },
156
- 'description' => listitem_to_liquid(item)
132
+ 'terms' => terms.map {|term| listitem_to_hash(term) },
133
+ 'description' => listitem_to_hash(item)
157
134
  }
158
135
  }
159
136
  })
160
137
  else
161
- abstract_block_to_liquid(node).merge({
162
- 'items' => node.blocks.map { |item| listitem_to_liquid(item) }
138
+ abstract_block_to_hash(node).merge!({
139
+ 'items' => node.blocks.map { |item| listitem_to_hash(item) }
163
140
  })
164
141
  end
165
142
  end
166
143
 
167
- def listitem_to_liquid(node)
168
- abstract_block_to_liquid(node).merge({
144
+ def listitem_to_hash(node)
145
+ abstract_block_to_hash(node).merge!({
169
146
  'text' => (node.text? ? node.text : nil)
170
147
  })
171
148
  end
172
149
 
173
- def table_to_liquid(node)
174
- abstract_block_to_liquid(node).merge({
150
+ def table_to_hash(node)
151
+ abstract_block_to_hash(node).merge!({
175
152
  'columns' => node.columns,
176
153
  'rows' => {
177
- 'head' => node.rows.head.map { |row| row.map {|cell| cell_to_liquid(cell) } },
178
- 'body' => node.rows.body.map { |row| row.map {|cell| cell_to_liquid(cell) } },
179
- 'foot' => node.rows.foot.map { |row| row.map {|cell| cell_to_liquid(cell) } }
154
+ 'head' => node.rows.head.map { |row| row.map {|cell| cell_to_hash(cell) } },
155
+ 'body' => node.rows.body.map { |row| row.map {|cell| cell_to_hash(cell) } },
156
+ 'foot' => node.rows.foot.map { |row| row.map {|cell| cell_to_hash(cell) } }
180
157
  }
181
158
  })
182
159
  end
183
160
 
184
- def cell_to_liquid(node)
185
- abstract_node_to_liquid(node).merge({
161
+ def cell_to_hash(node)
162
+ abstract_node_to_hash(node).merge!({
186
163
  'text' => node.text,
187
164
  'content' => node.content,
188
165
  'style' => node.style,
@@ -191,9 +168,9 @@ module Asciidoctor
191
168
  })
192
169
  end
193
170
 
194
- def inline_to_liquid(node)
195
- abstract_node_to_liquid(node).merge({
196
- 'text' => node.text,
171
+ def inline_to_hash(node)
172
+ abstract_node_to_hash(node).merge!({
173
+ 'text' => node.text || node.document.references[:refs][node.attributes['refid']]&.xreftext || "[#{node.attributes['refid']}]",
197
174
  'type' => node.type.to_s,
198
175
  'target' => node.target,
199
176
  'xreftext' => node.xreftext
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Htmlbook
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -2,9 +2,16 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
- <title>{{ node.header.title }}</title>
5
+ {% if node.title %}<title>{{ node.title }}</title>{% endif %}
6
6
  </head>
7
7
  <body data-type="book">
8
+ {% if node.title %}<h1>{{ node.title }}</h1>{% endif %}
9
+ {% if node.attributes.toc %}
10
+ <nav data-type="toc">
11
+ <h1>{{ node.attributes.toc-title }}</h1>
12
+ {{ node.toc }}
13
+ </nav>
14
+ {% endif %}
8
15
  {{ node.content }}
9
16
  </body>
10
17
  </html>
@@ -1 +1,8 @@
1
+ {% if node.title %}<h1>{{ node.title }}</h1>{% endif %}
2
+ {% if node.attributes.toc %}
3
+ <nav data-type="toc">
4
+ <h1>{{ node.attributes.toc-title }}</h1>
5
+ {{ node.toc }}
6
+ </nav>
7
+ {% endif %}
1
8
  {{ node.content }}
@@ -1,12 +1,6 @@
1
1
  {% case node.type %}
2
2
  {% when 'xref' %}
3
- {% if node.text %}
4
3
  <a data-type="xref" href="{{ node.target }}">{{ node.text }}</a>
5
- {% elsif node.document.references.refs[node.attributes.refid] %}
6
- <a data-type="xref" href="{{ node.target }}">{{ node.document.references.refs[node.attributes.refid].xreftext }}</a>
7
- {% else %}
8
- <a data-type="xref" href="{{ node.target }}">[{{ node.attributes.refid }}]</a>
9
- {% endif %}
10
4
  {% when 'ref' %}
11
5
  <a id="{{ node.id }}"></a>
12
6
  {% when 'link' %}
@@ -1,9 +1,9 @@
1
1
  {% case node.sectname %}
2
- {% when 'sect0' %}
3
- <section id="{{node.id}}" data-type="part">
2
+ {% when 'part' %}
3
+ <div id="{{node.id}}" data-type="part">
4
4
  <h1>{% if node.numbered %}{{ node.sectnum }} {% endif %}{{ node.title }}</h1>
5
5
  {{ node.content }}
6
- </section>
6
+ </div>
7
7
  {% when 'sect1' %}
8
8
  <section id="{{node.id}}" data-type="chapter">
9
9
  <h1>{% if node.numbered %}{{ node.sectnum }} {% endif %}{{ node.title }}</h1>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-htmlbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-23 00:00:00.000000000 Z
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: '2.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -133,7 +133,6 @@ files:
133
133
  - templates/stem.html
134
134
  - templates/table.html
135
135
  - templates/thematic_break.html
136
- - templates/toc.html
137
136
  - templates/ulist.html
138
137
  - templates/verse.html
139
138
  - templates/video.html
@@ -1,4 +0,0 @@
1
- <nav id="{{ node.id }}" data-type="toc">
2
- <h1>{{ node.document.attributes.toc-title }}</h1>
3
- {{ node.content }}
4
- </nav>