epuber 0.10.3 → 0.11.0

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: 2c22c5e5a5820ba5dd1090ddc015276e877b4aa535d3b0cdd83c526a6604aa5b
4
- data.tar.gz: c8ac2c195d24bfb1971656d64777b1849b1371d59506559942c00ac826b58963
3
+ metadata.gz: fe7f3bcdad13773ba7653612826abd191b5f96feca42589372fc7b7cdf8f7fc4
4
+ data.tar.gz: c9d457b69789bdfe58d037263268a8e422fcbf388bc7f7c398e7a87456778a0a
5
5
  SHA512:
6
- metadata.gz: e5bbc9209f434dd869bbc6ca75ebaf0eca0945597665e6d1fb984cdf3e11193e3b59ee284c89c5eb46abc3fc3932b7168282dc73340e72afc2419422d8da9918
7
- data.tar.gz: bb1fe4b5fbad4f79d69b1f357ca58c58aaa7abd504b8c9fec96dd7b6105060a3ef53a93db579b0ef6ddb1565433c1d8f30dc8afbd484817dd92839aafb88109f
6
+ metadata.gz: af694d5d009b517aaf16c8af77182ef1e417c6196fec93525e5d60a1691dd736c6f34c63e854f355d264a3e16e552f0ce7b292e309d9df26a8853bdef79d8394
7
+ data.tar.gz: b30da3c708b994835b033e8522e17d0a485fd0e08182818de5c0e067b840ef3cdfb7dfc96c0a4cac91fa2575587027d44f7d3cb0c0c6b503a870a430a95dd29b
@@ -74,7 +74,7 @@ module Epuber
74
74
 
75
75
  archive_name = compiler.epub_name
76
76
 
77
- FileUtils.remove_file(archive_name) if ::File.exist?(archive_name)
77
+ FileUtils.rm_f(archive_name)
78
78
 
79
79
  archive_path = compiler.archive(archive_name)
80
80
  run_epubcheck(archive_path, build_path)
@@ -5,34 +5,44 @@ module Epuber
5
5
  module FileTypes
6
6
  require_relative 'generated_file'
7
7
 
8
- class NavFile < GeneratedFile
9
- # @return [Epuber::Version]
8
+ class NavAbstractFile < GeneratedFile
9
+ # @return [Class]
10
10
  #
11
- attr_reader :epub_version
11
+ attr_reader :generator_type
12
12
 
13
- # @param [Epuber::Version] epub_version
13
+ # @param [String] filename
14
+ # @param [Class] generator Class of generator (subclass of Epuber::Compiler::Generator)
14
15
  #
15
- def initialize(epub_version)
16
+ def initialize(filename, generator_type, properties = [])
16
17
  super()
17
18
 
18
- @epub_version = epub_version
19
-
20
- properties << :navigation
21
-
22
- self.destination_path = if epub_version >= 3
23
- 'nav.xhtml'
24
- else
25
- 'nav.ncx'
26
- end
19
+ @generator_type = generator_type
27
20
 
21
+ self.properties = properties
22
+ self.destination_path = filename
28
23
  self.path_type = :manifest
29
24
  end
30
25
 
31
26
  # @param [Compiler::CompilationContext] compilation_context
32
27
  #
33
28
  def process(compilation_context)
34
- gen = NavGenerator.new(compilation_context)
35
- write_generate(gen.generate_nav.to_s)
29
+ result = generator_type.new(compilation_context)
30
+ .generate
31
+ .to_s
32
+
33
+ write_generate(result)
34
+ end
35
+ end
36
+
37
+ class NavFile < NavAbstractFile
38
+ def initialize
39
+ super('nav.xhtml', NavGenerator, [:navigation])
40
+ end
41
+ end
42
+
43
+ class NcxFile < NavAbstractFile
44
+ def initialize
45
+ super('toc.ncx', NcxGenerator, [])
36
46
  end
37
47
  end
38
48
  end
@@ -2,17 +2,12 @@
2
2
 
3
3
  require_relative '../book/toc_item'
4
4
 
5
-
6
5
  module Epuber
7
6
  class Compiler
8
7
  require_relative 'file_resolver'
9
8
  require_relative 'generator'
10
9
 
11
10
  class NavGenerator < Generator
12
- NCX_NAMESPACES = {
13
- 'xmlns' => 'http://www.daisy.org/z3986/2005/ncx/',
14
- }.freeze
15
-
16
11
  XHTML_NAMESPACES = {
17
12
  'xmlns' => 'http://www.w3.org/1999/xhtml',
18
13
  'xmlns:epub' => 'http://www.idpf.org/2007/ops',
@@ -37,13 +32,9 @@ module Epuber
37
32
  #
38
33
  # @return [Nokogiri::XML::Document]
39
34
  #
40
- def generate_nav
35
+ def generate
41
36
  generate_xml do
42
- if @target.epub_version >= 3
43
- generate_xhtml_content
44
- else
45
- generate_ncx_content
46
- end
37
+ generate_xhtml_content
47
38
  end
48
39
  end
49
40
 
@@ -53,13 +44,9 @@ module Epuber
53
44
  # @return [Hash<String, String>]
54
45
  #
55
46
  def nav_namespaces
56
- if @target.epub_version >= 3
57
- dict = XHTML_NAMESPACES
58
- dict = dict.merge(XHTML_IBOOKS_NAMESPACES) if @target.ibooks?
59
- dict
60
- else
61
- NCX_NAMESPACES
62
- end
47
+ dict = XHTML_NAMESPACES
48
+ dict = dict.merge(XHTML_IBOOKS_NAMESPACES) if @target.ibooks?
49
+ dict
63
50
  end
64
51
 
65
52
  # @return nil
@@ -86,46 +73,15 @@ module Epuber
86
73
  end
87
74
  end
88
75
 
89
- def generate_ncx_content
90
- @xml.doc.create_internal_subset('ncx',
91
- '-//NISO//DTD ncx 2005-1//EN',
92
- 'http://www.daisy.org/z3986/2005/ncx-2005-1.dtd')
93
-
94
- @xml.ncx(nav_namespaces, version: '2005-1') do
95
- # head
96
- @xml.head do
97
- @xml.meta(name: 'dtb:uid', content: @target.identifier || "urn:isbn:#{@target.isbn}")
98
- end
99
-
100
- # title
101
- @xml.docTitle do
102
- @xml.text_(@book.title)
103
- end
104
-
105
- @nav_nav_point_id = 1
106
-
107
- # nav map
108
- @xml.navMap do
109
- visit_toc_items(@target.root_toc.sub_items)
110
- end
111
- end
112
- end
113
-
114
76
  # @param [Array<Epuber::Book::TocItem>] toc_items
115
77
  #
116
78
  def visit_toc_items(toc_items)
117
- iterate_lambda = lambda do
118
- toc_items.each do |child_item|
119
- visit_toc_item(child_item)
120
- end
121
- end
122
-
123
- if @target.epub_version >= 3 && toc_items.length.positive? && contains_item_with_title(toc_items)
79
+ if toc_items.length.positive? && contains_item_with_title(toc_items)
124
80
  @xml.ol do
125
- iterate_lambda.call
81
+ toc_items.each do |child_item|
82
+ visit_toc_item(child_item)
83
+ end
126
84
  end
127
- else
128
- iterate_lambda.call
129
85
  end
130
86
  end
131
87
 
@@ -140,23 +96,11 @@ module Epuber
140
96
 
141
97
  if toc_item.title.nil?
142
98
  visit_toc_items(toc_item.sub_items)
143
- elsif @target.epub_version >= 3
99
+ else
144
100
  @xml.li do
145
101
  node_builder = @xml.a(href: result_file_path)
146
102
  node_builder.node.inner_html = toc_item.title
147
103
 
148
- visit_toc_items(toc_item.sub_items)
149
- end
150
- else
151
- @xml.navPoint(id: "navPoint_#{@nav_nav_point_id}") do
152
- @xml.navLabel do
153
- node_builder = @xml.text_
154
- node_builder.node.inner_html = toc_item.title
155
- end
156
- @xml.content(src: result_file_path)
157
-
158
- @nav_nav_point_id += 1
159
-
160
104
  visit_toc_items(toc_item.sub_items)
161
105
  end
162
106
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../book/toc_item'
4
+
5
+ module Epuber
6
+ class Compiler
7
+ class NcxGenerator < Generator
8
+ NCX_NAMESPACES = {
9
+ 'xmlns' => 'http://www.daisy.org/z3986/2005/ncx/',
10
+ }.freeze
11
+
12
+ def generate
13
+ generate_xml do
14
+ _generate_ncx_content
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def _generate_ncx_content
21
+ @xml.doc.create_internal_subset('ncx',
22
+ '-//NISO//DTD ncx 2005-1//EN',
23
+ 'http://www.daisy.org/z3986/2005/ncx-2005-1.dtd')
24
+
25
+ @xml.ncx(NCX_NAMESPACES, version: '2005-1') do
26
+ # head
27
+ @xml.head do
28
+ @xml.meta(name: 'dtb:uid', content: @target.identifier || "urn:isbn:#{@target.isbn}")
29
+ end
30
+
31
+ # title
32
+ @xml.docTitle do
33
+ @xml.text_(@book.title)
34
+ end
35
+
36
+ @nav_nav_point_id = 1
37
+
38
+ # nav map
39
+ @xml.navMap do
40
+ _visit_toc_items(@target.root_toc.sub_items)
41
+ end
42
+ end
43
+ end
44
+
45
+ # @param [Array<Epuber::Book::TocItem>] toc_items
46
+ #
47
+ def _visit_toc_items(toc_items)
48
+ toc_items.each do |child_item|
49
+ _visit_toc_item(child_item)
50
+ end
51
+ end
52
+
53
+ # @param [Epuber::Book::TocItem] toc_item
54
+ #
55
+ def _visit_toc_item(toc_item)
56
+ result_file_path = pretty_path_for_toc_item(toc_item)
57
+
58
+ if toc_item.title.nil?
59
+ _visit_toc_items(toc_item.sub_items)
60
+ else
61
+ @xml.navPoint(id: "navPoint_#{@nav_nav_point_id}", playOrder: @nav_nav_point_id.to_s) do
62
+ @xml.navLabel do
63
+ node_builder = @xml.text_
64
+ node_builder.node.inner_html = toc_item.title
65
+ end
66
+ @xml.content(src: result_file_path)
67
+
68
+ @nav_nav_point_id += 1
69
+
70
+ _visit_toc_items(toc_item.sub_items)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -184,14 +184,12 @@ module Epuber
184
184
  # @return nil
185
185
  #
186
186
  def generate_spine
187
- args = if @target.epub_version >= 3
188
- {}
189
- else
190
- nav_file = @file_resolver.manifest_files.find { |file| file.destination_path.end_with?('.ncx') }
191
- raise 'not found nav file' if nav_file.nil?
192
-
193
- { toc: create_id_from_path(pretty_path(nav_file)) }
194
- end
187
+ ncx_file = @file_resolver.manifest_files.find { |file| file.is_a?(FileTypes::NcxFile) }
188
+ raise 'not found NCX file' if ncx_file.nil?
189
+
190
+ args = {
191
+ toc: create_id_from_path(pretty_path(ncx_file)),
192
+ }
195
193
 
196
194
  all_items = @target.root_toc.flat_sub_items.map do |toc_item|
197
195
  result_file = @file_resolver.file_from_request(toc_item.file_request)
@@ -14,6 +14,7 @@ module Epuber
14
14
 
15
15
  require_relative 'compiler/opf_generator'
16
16
  require_relative 'compiler/nav_generator'
17
+ require_relative 'compiler/ncx_generator'
17
18
  require_relative 'compiler/meta_inf_generator'
18
19
 
19
20
  require_relative 'compiler/file_resolver'
@@ -199,10 +200,17 @@ module Epuber
199
200
  # @return nil
200
201
  #
201
202
  def generate_other_files
202
- # generate nav file (nav.xhtml or nav.ncx)
203
- nav_file = FileTypes::NavFile.new(@target.epub_version)
204
- @file_resolver.add_file(nav_file)
205
- process_file(nav_file)
203
+ # generate ncx file (nav.ncx)
204
+ ncx_file = FileTypes::NcxFile.new
205
+ @file_resolver.add_file(ncx_file)
206
+ process_file(ncx_file)
207
+
208
+ if @target.epub_version >= 3.0
209
+ # generate nav file (nav.xhtml)
210
+ nav_file = FileTypes::NavFile.new
211
+ @file_resolver.add_file(nav_file)
212
+ process_file(nav_file)
213
+ end
206
214
 
207
215
  # generate .opf file
208
216
  opf_file = FileTypes::OPFFile.new
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'date'
4
-
5
4
  require 'active_support/core_ext/string/inflections'
6
5
 
7
6
  module Epuber
@@ -33,7 +32,6 @@ module Epuber
33
32
  default_value: nil,
34
33
  auto_convert: {},
35
34
  types: nil)
36
-
37
35
  @name = name
38
36
 
39
37
  @inherited = inherited
@@ -3,6 +3,7 @@
3
3
  require_relative 'attribute'
4
4
  require_relative 'attribute_support'
5
5
 
6
+ require 'logger' # for active_support to work in version 6.1.7.10
6
7
  require 'active_support'
7
8
  require 'active_support/core_ext/string/inflections'
8
9
 
@@ -34,7 +34,7 @@ module Epuber
34
34
  end
35
35
 
36
36
  def error?
37
- level == :error || level == :fatal
37
+ %i[error fatal].include?(level)
38
38
  end
39
39
  end
40
40
 
@@ -48,7 +48,7 @@ module Epuber
48
48
 
49
49
  Dir.mktmpdir('epubcheck-') do |tmpdir|
50
50
  json_path = File.join(tmpdir, 'epubcheck.json')
51
- Open3.popen2('epubcheck', path, '--json', json_path) do |_stdin, _stdout, wait_thr|
51
+ Open3.popen3('epubcheck', path, '--json', json_path) do |_in, _out, _err, wait_thr|
52
52
  wait_thr.value # wait for the process to finish
53
53
  report = _parse_json(File.read(json_path))
54
54
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Epuber
4
- VERSION = '0.10.3'
4
+ VERSION = '0.11.0'
5
5
 
6
6
  HOME_URL = 'https://github.com/epuber-io/epuber'
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epuber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Kříž
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-09-03 00:00:00.000000000 Z
10
+ date: 2025-01-23 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -330,7 +329,6 @@ dependencies:
330
329
  - - ">="
331
330
  - !ruby/object:Gem::Version
332
331
  version: 1.1.1
333
- description:
334
332
  email:
335
333
  - samnung@gmail.com
336
334
  executables:
@@ -385,6 +383,7 @@ files:
385
383
  - lib/epuber/compiler/generator.rb
386
384
  - lib/epuber/compiler/meta_inf_generator.rb
387
385
  - lib/epuber/compiler/nav_generator.rb
386
+ - lib/epuber/compiler/ncx_generator.rb
388
387
  - lib/epuber/compiler/opf_generator.rb
389
388
  - lib/epuber/compiler/problem.rb
390
389
  - lib/epuber/compiler/xhtml_processor.rb
@@ -582,7 +581,6 @@ licenses:
582
581
  - MIT
583
582
  metadata:
584
583
  rubygems_mfa_required: 'true'
585
- post_install_message:
586
584
  rdoc_options: []
587
585
  require_paths:
588
586
  - lib
@@ -597,8 +595,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
597
595
  - !ruby/object:Gem::Version
598
596
  version: '0'
599
597
  requirements: []
600
- rubygems_version: 3.5.18
601
- signing_key:
598
+ rubygems_version: 3.6.3
602
599
  specification_version: 4
603
600
  summary: Epuber is simple tool to compile and pack source files into EPUB format.
604
601
  test_files: []