asciidoctor-fb2 0.1.0 → 0.2.0

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: c8d4c3a2aa4774098306334ce565317f632d1a18915560dd25df96ce059fa24d
4
- data.tar.gz: fe4bc5213b9009120a250db9ef89db70c5c312a09f57ee3b74bf11f68a4ed180
3
+ metadata.gz: 5b60e7a379175a8473e96c61ed95598104689ac84def256f01ec626d850025af
4
+ data.tar.gz: 96c60b98e0245a9aa4d61037d538f31b623dfd53e0c24407428c784a2753f9c9
5
5
  SHA512:
6
- metadata.gz: 2d9cc6fa6b74be5c852752a2836d0a1607a0d3baeefbeb4047565e2a2b4b68cc7098250a6ad359c58456d55fbf025bcad4c6e0da5f1ad7eb8ba28fccaceebb92
7
- data.tar.gz: d1ba09be9557da949cccef970a09efdd4a78003b8e3f1d726293da17d69d08435f31f9eeab9e96650cb0c37f962f11d4eea20b05e7f0fb787b2a8b10feac460e
6
+ metadata.gz: 13bc939cf1450190c85b87e51333c6d58f3e2d3b2181be4c9a5af8705dd645900cd00a1290f74f68adfed42ad1570cfc4c6ed8974940b7317e5c524b96824b74
7
+ data.tar.gz: 314760eafb08dfda7c44087dab1d7d6a5309ac45f134612a455b84e894d1b8b328beb06d65be37e7e7a7d20de4bc589841a461c3b50c2e666264c8b8ae505ee6
@@ -7,6 +7,14 @@
7
7
  This document provides a high-level view of the changes to the {project-name} by release.
8
8
  For a detailed view of what has changed, refer to the {uri-project}/commits/master[commit history] on GitHub.
9
9
 
10
+ == 0.2.0 (2020-11-23) - @slonopotamus
11
+
12
+ * add support for cover image via `+:front-cover-image:+` attribute. https://github.com/slonopotamus/asciidoctor-fb2/issues/3[#3]
13
+ * update fb2rb to 0.3.0
14
+ * add support for nested lists. https://github.com/slonopotamus/asciidoctor-fb2/issues/2[#2]
15
+ * output uncompressed book if filename doesn't end with `.zip`
16
+ * add support for `menu` inline macro. https://github.com/slonopotamus/asciidoctor-fb2/issues/12[#12]
17
+
10
18
  == 0.1.0 (2020-07-24) - @slonopotamus
11
19
 
12
- * Initial release
20
+ * initial release
@@ -14,24 +14,39 @@ image:{uri-project}/workflows/CI/badge.svg?branch=master[Build Status,link={uri-
14
14
 
15
15
  == Installation
16
16
 
17
+ {project-name} is published on RubyGems.org.
18
+ You can install the published gem using the following command:
19
+
17
20
  [source,shell script]
18
21
  ----
19
- $ gem install asciidoctor-fb2 --pre
22
+ $ gem install asciidoctor-fb2
20
23
  ----
21
24
 
22
- == Usage
25
+ Assuming all the required gems install properly, verify you can run the `{project-handle}` script:
23
26
 
24
27
  [source,shell script]
25
28
  ----
26
- asciidoctor-fb2 /path/to/book.adoc
29
+ $ asciidoctor-fb2 -v
27
30
  ----
28
31
 
29
- == Development
32
+ If you see the version of {project-name} printed, you're ready to use {project-name}.
30
33
 
31
- After checking out the repo, run `bundle install` to install dependencies.
32
- Then, run `bundle exec rake spec` to run the tests.
34
+ == Usage
35
+
36
+ Converting an AsciiDoc document to FB2 is as simple as passing your document to the `{project-handle}` command.
37
+ This command should be available on your PATH if you installed the `{project-handle}` gem.
38
+ Otherwise, you can find the command in the [path]_bin_ folder of the project.
39
+ We also recommend specifying an output directory using the `-D` option flag.
40
+
41
+ [source,shell script]
42
+ ----
43
+ $ asciidoctor-fb2 -D output path/to/book.adoc
44
+ ----
45
+
46
+ When the script completes, you'll see the file [file]_book.fb2.zip_ appear in the [path]_output_ directory.
47
+ Open that file with an FB2 reader to view the result.
33
48
 
34
- === FB2-related AsciiDoc Attributes
49
+ == FB2-related AsciiDoc Attributes
35
50
 
36
51
  The metadata in the generated FB2 file is populated from attributes in the AsciiDoc document.
37
52
  The names of the attributes and the metadata elements to which they map are documented in this section.
@@ -48,10 +63,18 @@ The names of the attributes and the metadata elements to which they map are docu
48
63
  |Populates the content language in FB2 metadata.
49
64
 
50
65
  |keywords
51
- |Populates keywords list in FB2 metadata
66
+ |Populates keywords list in FB2 metadata.
52
67
  The keywords should be represented as comma-separated values (CSV).
53
68
 
54
69
  |genres
55
- |Populates genres list in FB2 metadata
70
+ |Populates genres list in FB2 metadata.
56
71
  The genres should be represented as comma-separated values (CSV).
72
+
73
+ |front-cover-image
74
+ |Specifies path to front cover image.
57
75
  |===
76
+
77
+ == Development
78
+
79
+ After checking out the repo, run `bundle install` to install dependencies.
80
+ Then, run `bundle exec rake spec` to run the tests.
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ['lib']
20
20
 
21
21
  s.add_runtime_dependency 'asciidoctor', '~> 2.0'
22
- s.add_runtime_dependency 'fb2rb', '~> 0.2.0'
22
+ s.add_runtime_dependency 'fb2rb', '~> 0.3.0'
23
23
 
24
24
  s.add_development_dependency 'asciidoctor-diagram', '~> 2.0'
25
25
  s.add_development_dependency 'rake', '~> 13.0'
26
- s.add_development_dependency 'rspec', '~> 3.9.0'
27
- s.add_development_dependency 'rubocop', '~> 0.88.0'
28
- s.add_development_dependency 'rubocop-rspec', '~> 1.42.0'
26
+ s.add_development_dependency 'rspec', '~> 3.10.0'
27
+ s.add_development_dependency 'rubocop', '~> 0.93.0'
28
+ s.add_development_dependency 'rubocop-rspec', '~> 1.44.0'
29
29
  end
@@ -23,7 +23,7 @@ module Asciidoctor
23
23
  end
24
24
 
25
25
  # @param node [Asciidoctor::Document]
26
- def convert_document(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
26
+ def convert_document(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
27
27
  @book = FB2rb::Book.new
28
28
  document_info = @book.description.document_info
29
29
  title_info = @book.description.title_info
@@ -57,6 +57,12 @@ module Asciidoctor
57
57
  fb2date = FB2rb::FB2Date.new(date, Date.parse(date))
58
58
  title_info.date = document_info.date = fb2date
59
59
 
60
+ unless (cover_image = node.attr('front-cover-image')).nil?
61
+ cover_image_path = node.image_uri(cover_image)
62
+ register_binary(node, cover_image_path)
63
+ title_info.coverpage = FB2rb::Coverpage.new([%(##{cover_image_path})])
64
+ end
65
+
60
66
  document_info.id = node.attr('uuid', '')
61
67
  document_info.version = node.attr('revnumber')
62
68
  document_info.program_used = %(Asciidoctor FB2 #{VERSION} using Asciidoctor #{node.attr('asciidoctor-version')})
@@ -141,6 +147,20 @@ module Asciidoctor
141
147
  %(#{open}#{node.text}#{close})
142
148
  end
143
149
 
150
+ # @param node [Asciidoctor::Inline]
151
+ def convert_inline_menu(node)
152
+ caret = '&#160;<strong>&#8250;</strong> '
153
+ menu = node.attr('menu')
154
+ menuitem = node.attr('menuitem')
155
+ submenus = node.attr('submenus').join(%(</b>#{caret}<b>))
156
+
157
+ result = %(<strong>#{menu}</strong>)
158
+ result += %(#{caret}<strong>#{submenus}</strong>) unless submenus.empty?
159
+ result += %(#{caret}<strong>#{menuitem}</strong>) unless menuitem.empty?
160
+
161
+ result
162
+ end
163
+
144
164
  # @param node [Asciidoctor::Inline]
145
165
  def convert_inline_anchor(node) # rubocop:disable Metrics/MethodLength
146
166
  case node.type
@@ -169,13 +189,13 @@ module Asciidoctor
169
189
 
170
190
  # @param node [Asciidoctor::Inline]
171
191
  def convert_inline_image(node)
172
- image_attrs = resolve_image_attrs(node, node.target)
192
+ image_attrs = register_binary(node, node.image_uri(node.target))
173
193
  %(<image #{image_attrs * ' '}/>)
174
194
  end
175
195
 
176
196
  # @param node [Asciidoctor::Block]
177
197
  def convert_image(node)
178
- image_attrs = resolve_image_attrs(node, node.attr('target'))
198
+ image_attrs = register_binary(node, node.image_uri(node.attr('target')))
179
199
  image_attrs << %(title="#{node.captioned_title}") if node.title?
180
200
  image_attrs << %(id="#{node.id}") if node.id
181
201
  %(<p><image #{image_attrs * ' '}/></p>)
@@ -190,8 +210,7 @@ module Asciidoctor
190
210
 
191
211
  # @param node [Asciidoctor::AbstractNode]
192
212
  # @param target [String]
193
- def resolve_image_attrs(node, target) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
194
- target = node.image_uri(target)
213
+ def register_binary(node, target) # rubocop:disable Metrics/MethodLength
195
214
  unless Asciidoctor::Helpers.uriish?(target)
196
215
  out_dir = node.attr('outdir', nil, true) || doc_option(node.document, :to_dir)
197
216
  fs_path = File.join(out_dir, target)
@@ -212,30 +231,40 @@ module Asciidoctor
212
231
 
213
232
  # @param node [Asciidoctor::Block]
214
233
  def convert_admonition(node)
215
- %(<p><strong>#{node.title || node.caption}:</strong>
234
+ lines = [%(<p><strong>#{node.title || node.caption}:</strong>
216
235
  #{node.content}
217
- </p>)
236
+ </p>)]
237
+ lines << '<empty-line/>' unless node.has_role?('last')
238
+ lines * "\n"
218
239
  end
219
240
 
220
241
  # @param node [Asciidoctor::List]
221
242
  def convert_ulist(node)
222
243
  lines = []
244
+ @stack ||= []
245
+
223
246
  node.items.each do |item|
224
- lines << %(<p>• #{item.text}</p>)
247
+ @stack << '•'
248
+ lines << %(<p>#{@stack * ' '} #{item.text}</p>)
225
249
  lines << %(<p>#{item.content}</p>) if item.blocks?
250
+ @stack.pop
226
251
  end
227
- lines << '<empty-line/>' unless node.has_role?('last')
252
+
253
+ lines << '<empty-line/>' unless node.has_role?('last') || !@stack.empty?
228
254
  lines * "\n"
229
255
  end
230
256
 
231
257
  # @param node [Asciidoctor::List]
232
- def convert_olist(node)
258
+ def convert_olist(node) # rubocop:disable Metrics/AbcSize
233
259
  lines = []
260
+ @stack ||= []
234
261
  node.items.each_with_index do |item, index|
235
- lines << %(<p>#{index + 1}. #{item.text}</p>)
262
+ @stack << %(#{index + 1}.)
263
+ lines << %(<p>#{@stack * ' '} #{item.text}</p>)
236
264
  lines << %(<p>#{item.content}</p>) if item.blocks?
265
+ @stack.pop
237
266
  end
238
- lines << '<empty-line/>' unless node.has_role?('last')
267
+ lines << '<empty-line/>' unless node.has_role?('last') || !@stack.empty?
239
268
  lines * "\n"
240
269
  end
241
270
 
@@ -319,7 +348,11 @@ module Asciidoctor
319
348
 
320
349
  # @param output [FB2rb::Book]
321
350
  def write(output, target)
322
- output.write(target)
351
+ if target.respond_to?(:end_with?) && target.end_with?('.zip')
352
+ output.write_compressed(target)
353
+ else
354
+ output.write_uncompressed(target)
355
+ end
323
356
  end
324
357
  end
325
358
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module FB2
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-fb2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marat Radchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-24 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.0
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.0
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: asciidoctor-diagram
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,42 +72,42 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.9.0
75
+ version: 3.10.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.9.0
82
+ version: 3.10.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.88.0
89
+ version: 0.93.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.88.0
96
+ version: 0.93.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.42.0
103
+ version: 1.44.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.42.0
110
+ version: 1.44.0
111
111
  description:
112
112
  email:
113
113
  - marat@slonopotamus.org
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  requirements: []
158
- rubygems_version: 3.1.2
158
+ rubygems_version: 3.1.4
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Converts AsciiDoc documents to FB2 e-book formats