epuber 0.7.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -2
  3. data/LICENSE.txt +1 -1
  4. data/README.md +4 -3
  5. data/epuber.gemspec +11 -16
  6. data/lib/epuber/book/contributor.rb +10 -7
  7. data/lib/epuber/book/file_request.rb +3 -3
  8. data/lib/epuber/book/target.rb +30 -33
  9. data/lib/epuber/book/toc_item.rb +2 -4
  10. data/lib/epuber/book.rb +21 -21
  11. data/lib/epuber/checker/bookspec_checker.rb +26 -0
  12. data/lib/epuber/checker/text_checker.rb +16 -7
  13. data/lib/epuber/checker.rb +16 -2
  14. data/lib/epuber/checker_transformer_base.rb +3 -6
  15. data/lib/epuber/command/build.rb +40 -25
  16. data/lib/epuber/command/from_file.rb +39 -0
  17. data/lib/epuber/command/init.rb +34 -32
  18. data/lib/epuber/command/server.rb +3 -3
  19. data/lib/epuber/command.rb +18 -20
  20. data/lib/epuber/compiler/compilation_context.rb +10 -8
  21. data/lib/epuber/compiler/file_database.rb +2 -4
  22. data/lib/epuber/compiler/file_finders/abstract.rb +36 -26
  23. data/lib/epuber/compiler/file_finders/imaginary.rb +40 -35
  24. data/lib/epuber/compiler/file_resolver.rb +79 -89
  25. data/lib/epuber/compiler/file_stat.rb +4 -4
  26. data/lib/epuber/compiler/file_types/abstract_file.rb +4 -7
  27. data/lib/epuber/compiler/file_types/bade_file.rb +20 -15
  28. data/lib/epuber/compiler/file_types/coffee_script_file.rb +1 -1
  29. data/lib/epuber/compiler/file_types/css_file.rb +103 -0
  30. data/lib/epuber/compiler/file_types/generated_file.rb +1 -1
  31. data/lib/epuber/compiler/file_types/image_file.rb +4 -2
  32. data/lib/epuber/compiler/file_types/nav_file.rb +0 -1
  33. data/lib/epuber/compiler/file_types/opf_file.rb +0 -1
  34. data/lib/epuber/compiler/file_types/source_file.rb +8 -3
  35. data/lib/epuber/compiler/file_types/stylus_file.rb +4 -3
  36. data/lib/epuber/compiler/file_types/xhtml_file.rb +67 -13
  37. data/lib/epuber/compiler/generator.rb +1 -2
  38. data/lib/epuber/compiler/meta_inf_generator.rb +1 -1
  39. data/lib/epuber/compiler/nav_generator.rb +10 -11
  40. data/lib/epuber/compiler/opf_generator.rb +26 -27
  41. data/lib/epuber/compiler/problem.rb +12 -21
  42. data/lib/epuber/compiler/xhtml_processor.rb +63 -32
  43. data/lib/epuber/compiler.rb +77 -25
  44. data/lib/epuber/config.rb +16 -10
  45. data/lib/epuber/dsl/attribute.rb +17 -18
  46. data/lib/epuber/dsl/attribute_support.rb +7 -7
  47. data/lib/epuber/dsl/object.rb +19 -17
  48. data/lib/epuber/dsl/tree_object.rb +2 -3
  49. data/lib/epuber/epubcheck.rb +15 -0
  50. data/lib/epuber/from_file/bookspec_generator.rb +371 -0
  51. data/lib/epuber/from_file/encryption_handler.rb +146 -0
  52. data/lib/epuber/from_file/from_file_executor.rb +140 -0
  53. data/lib/epuber/from_file/nav_file.rb +163 -0
  54. data/lib/epuber/from_file/opf_file.rb +219 -0
  55. data/lib/epuber/helper.rb +0 -1
  56. data/lib/epuber/lockfile.rb +7 -9
  57. data/lib/epuber/plugin.rb +2 -3
  58. data/lib/epuber/ruby_extensions/match_data.rb +1 -1
  59. data/lib/epuber/ruby_extensions/thread.rb +1 -0
  60. data/lib/epuber/server/base.styl +0 -1
  61. data/lib/epuber/server/basic.styl +1 -30
  62. data/lib/epuber/server/handlers.rb +1 -1
  63. data/lib/epuber/server.rb +81 -80
  64. data/lib/epuber/third_party/bower.rb +5 -5
  65. data/lib/epuber/transformer/book_transformer.rb +108 -0
  66. data/lib/epuber/transformer/text_transformer.rb +4 -2
  67. data/lib/epuber/transformer.rb +4 -2
  68. data/lib/epuber/user_interface.rb +49 -38
  69. data/lib/epuber/vendor/hash_binding.rb +9 -2
  70. data/lib/epuber/vendor/ruby_templater.rb +4 -8
  71. data/lib/epuber/vendor/version.rb +12 -12
  72. data/lib/epuber/version.rb +1 -1
  73. metadata +79 -100
  74. data/lib/epuber/server/fonts/AvenirNext/AvenirNext-Bold.ttf +0 -0
  75. data/lib/epuber/server/fonts/AvenirNext/AvenirNext-BoldItalic.ttf +0 -0
  76. data/lib/epuber/server/fonts/AvenirNext/AvenirNext-Italic.ttf +0 -0
  77. data/lib/epuber/server/fonts/AvenirNext/AvenirNext-Regular.ttf +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af051eead00739e08c4b2aa7b4dcd418eee3c8dacbe4ba14f03d59eb0b0c5c9c
4
- data.tar.gz: d5d6bac0ca3655ac9a121c9f259ea550015d4395ca39c7a403ea6937ba469809
3
+ metadata.gz: 603ed8123e624a5756c2e66ef8e2561f76f60b7c2ba386040e62cc1bace24c52
4
+ data.tar.gz: bc9fd362419d5fd05444398221f8d0e9bbfa4675273635b893c3a160a3330048
5
5
  SHA512:
6
- metadata.gz: 49e6fd074fc50782e9227aac3ccd45997eb1760ca3e85acc3c14ac4f1660e8d77df877df1981993320ed432b5e9222fca02482813d25ec8e8464c6f6e0c93016
7
- data.tar.gz: b26d34e7bbbb3903ab99d6f1b731854602e92a942aee598d2590fa44b9df292212eaa2242e6c8370f75f9d3fdd6d71310ed3a39684366aa29b7033d9bd5c36dd
6
+ metadata.gz: 5f04920782210213a3c5fb8e424d8b22e3a316d83187dae331057759d4bda04b61b81c163215086fa4cad4abd736de37db43c428b56b51472f8d93c9bbadb5e3
7
+ data.tar.gz: a683e1930bf8c58b8b9f64529ac55c50dbe0895af5acbb4d4820cf1f5d0559349e87cd3f02c0bf7a90c77b04d4a9a07acee849cb867f8f81a658484e74514e35
data/Gemfile CHANGED
@@ -5,7 +5,15 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in Epuber.gemspec
6
6
  gemspec
7
7
 
8
+ # dev
9
+ gem 'fakefs', '>= 1.3', '< 3.0' # 2.0.0 is not compatible with Ruby 2.5
10
+ gem 'rake', '~> 13.0'
11
+ gem 'rspec', '~> 3.2'
12
+ gem 'rubocop', '~> 1.14'
13
+
14
+ # VSCode plugins
15
+ gem 'ruby-lsp', require: false
16
+
8
17
  group :dev, optional: true do
9
- gem 'debase', require: false
10
- gem 'ruby-debug-ide', require: false
18
+ gem 'rubocop-rspec', require: false
11
19
  end
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Roman Kříž
3
+ Copyright (c) 2015-2023 Roman Kříž
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  Epuber is simple tool to compile and pack source files into EPUB format. Offers to define multiple "targets" which allows to create multiple versions of the book by running only one command. Eliminates copying code and information, eliminates needs to use _git_ branches to differ ebook content.
6
6
 
7
+ For more information look at [documentation](./docs/README.md).
7
8
 
8
9
  ## Features
9
10
 
@@ -71,7 +72,7 @@ First of all Epuber uses [RMagick](https://github.com/rmagick/rmagick) which has
71
72
  - pkg-config
72
73
 
73
74
  On OS X make sure you Xcode Command Line Tools installed:
74
-
75
+
75
76
  xcode-select --install
76
77
 
77
78
  And the easiest way to install prerequisites on macOS is to use [brew](http://brew.sh):
@@ -103,9 +104,9 @@ To install this gem onto your local machine, run `bundle exec rake install`.
103
104
 
104
105
  ## Contributing
105
106
 
106
- Bug reports and pull requests are welcome on GitHub at https://github.com/epuber-io/epuber. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
107
+ Bug reports and pull requests are welcome on GitHub at https://github.com/epuber-io/epuber. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://www.contributor-covenant.org/) code of conduct.
107
108
 
108
109
 
109
110
  ## License
110
111
 
111
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
112
+ The gem is available as open source under the terms of the [MIT License](./LICENSE.txt).
data/epuber.gemspec CHANGED
@@ -1,8 +1,6 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
-
4
- require 'epuber/version'
1
+ # frozen_string_literal: true
5
2
 
3
+ require_relative 'lib/epuber/version'
6
4
 
7
5
  Gem::Specification.new do |spec|
8
6
  spec.name = 'epuber'
@@ -13,23 +11,24 @@ Gem::Specification.new do |spec|
13
11
  spec.homepage = Epuber::HOME_URL
14
12
  spec.license = 'MIT'
15
13
  spec.required_ruby_version = '>= 2.5'
14
+ spec.metadata['rubygems_mfa_required'] = 'true'
16
15
 
17
- spec.files = Dir['bin/**/*'] + Dir['lib/**/*'] + %w(epuber.gemspec Gemfile LICENSE.txt README.md)
16
+ spec.files = Dir['bin/**/*'] + Dir['lib/**/*'] + %w[epuber.gemspec Gemfile LICENSE.txt README.md]
18
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
18
  spec.require_paths = ['lib']
21
19
 
22
20
  spec.add_runtime_dependency 'activesupport', '>= 6.0', '< 8.0'
23
21
  spec.add_runtime_dependency 'addressable', '~> 2.7'
24
- spec.add_runtime_dependency 'nokogiri', '~> 1.8', '>= 1.8.2'
25
- spec.add_runtime_dependency 'mime-types', '~> 3.0'
26
22
  spec.add_runtime_dependency 'claide', '~> 1.0'
27
23
  spec.add_runtime_dependency 'listen', '~> 3.0'
24
+ spec.add_runtime_dependency 'mime-types', '~> 3.0'
25
+ spec.add_runtime_dependency 'nokogiri', '~> 1.8', '>= 1.8.2'
28
26
  spec.add_runtime_dependency 'os', '~> 1.0'
27
+ spec.add_runtime_dependency 'uuidtools', '~> 2.1'
29
28
 
30
29
  spec.add_runtime_dependency 'sinatra', '>= 2.0', '< 4.0'
31
- spec.add_runtime_dependency 'sinatra-websocket', '~> 0.3'
32
30
  spec.add_runtime_dependency 'sinatra-contrib', '>= 2.0', '< 4.0'
31
+ spec.add_runtime_dependency 'sinatra-websocket', '~> 0.3'
33
32
  spec.add_runtime_dependency 'thin', '~> 1.6'
34
33
 
35
34
  spec.add_runtime_dependency 'rmagick', '>= 4.2', '< 6.0'
@@ -37,12 +36,8 @@ Gem::Specification.new do |spec|
37
36
 
38
37
  spec.add_runtime_dependency 'epubcheck-ruby', '>= 4.0', '< 6.0'
39
38
 
40
- spec.add_runtime_dependency 'epuber-stylus', '~> 1.1', '>= 1.1.1'
41
- spec.add_runtime_dependency 'coffee-script', '~> 2.4'
42
39
  spec.add_runtime_dependency 'bade', '~> 0.3', '>= 0.3.1'
43
-
44
- spec.add_development_dependency 'rspec', '~> 3.2'
45
- spec.add_development_dependency 'rubocop', '~> 1.14'
46
- spec.add_development_dependency 'rake', '~> 13.0'
47
- spec.add_development_dependency 'fakefs', '>= 1.3', '< 3.0' # 2.0.0 is not compatible with Ruby 2.5
40
+ spec.add_runtime_dependency 'coffee-script', '~> 2.4'
41
+ spec.add_runtime_dependency 'css_parser', '>= 0.8', '< 2.0'
42
+ spec.add_runtime_dependency 'epuber-stylus', '~> 1.1', '>= 1.1.1'
48
43
  end
@@ -31,22 +31,26 @@ module Epuber
31
31
 
32
32
  # Creates new instance of Contributor dependent on obj content
33
33
  #
34
- # @param obj [Hash<Symbol, String>, Array<Hash<Symbol,String>, String, Array<String>] input object
35
- # @param role [String] role of contributor
34
+ # @param [Hash<Symbol, String>, Array<Hash<Symbol,String>, String, Array<String>] obj input object
35
+ # @param [String] role role of contributor
36
36
  #
37
37
  # @return [Contributor]
38
38
  #
39
- def self.from_obj(obj, role)
39
+ def self.from_obj(obj, role = 'aut')
40
40
  if obj.is_a?(String)
41
- components = obj.split(' ')
41
+ components = obj.split
42
42
  if components.length >= 2
43
43
  NormalContributor.new(components.first(components.length - 1).join(' '), components.last, role)
44
+ else
45
+ Contributor.new(obj, obj, role)
44
46
  end
45
47
  elsif obj.is_a?(Hash)
46
48
  if obj.key?(:first_name)
47
- NormalContributor.new(obj[:first_name], obj[:last_name], role)
49
+ NormalContributor.new(obj[:first_name], obj[:last_name], obj[:role] || role)
48
50
  elsif obj.key?(:file_as)
49
- Contributor.new(obj[:pretty_name], obj[:file_as], role)
51
+ Contributor.new(obj[:pretty_name], obj[:file_as], obj[:role] || role)
52
+ elsif obj.key?(:name)
53
+ Contributor.from_obj(obj[:name], obj[:role] || role)
50
54
  end
51
55
  end
52
56
  end
@@ -73,7 +77,6 @@ module Epuber
73
77
  @last_name = last_name
74
78
  end
75
79
 
76
-
77
80
  # @return [String]
78
81
  #
79
82
  def pretty_name
@@ -29,7 +29,7 @@ module Epuber
29
29
  # @param [Symbol] group group of file, see Epuber::Compiler::FileFinder::GROUP_EXTENSIONS
30
30
  # @param [Array<Symbol>, Set<Symbol>] properties list of properties
31
31
  #
32
- def initialize(source_pattern, only_one = true, group: nil, properties: [])
32
+ def initialize(source_pattern, only_one: true, group: nil, properties: [])
33
33
  @source_pattern = source_pattern
34
34
  @only_one = only_one
35
35
  @group = group
@@ -45,10 +45,10 @@ module Epuber
45
45
  # @return [Numeric]
46
46
  #
47
47
  def hash
48
- @source_pattern.hash ^ @group.hash ^ @only_one.hash
48
+ [@source_pattern, @group, @only_one].hash
49
49
  end
50
50
 
51
- # @param other [String, self]
51
+ # @param [String, self] other
52
52
  #
53
53
  def ==(other)
54
54
  if other.is_a?(String)
@@ -12,7 +12,7 @@ module Epuber
12
12
  # @param [Target] parent reference to parent target
13
13
  # @param [String] name name of this target
14
14
  #
15
- def initialize(parent = nil, name)
15
+ def initialize(name, parent: nil)
16
16
  super(parent)
17
17
 
18
18
  @name = name
@@ -51,7 +51,7 @@ module Epuber
51
51
 
52
52
  # @return [Array<self>] list of sub targets
53
53
  #
54
- alias_method :sub_targets, :sub_items
54
+ alias sub_targets sub_items
55
55
 
56
56
  # @return [Epuber::Book::TocItem]
57
57
  #
@@ -59,16 +59,14 @@ module Epuber
59
59
 
60
60
  # @return [Epuber::Book] reference to book
61
61
  #
62
- attr_accessor :book
63
-
62
+ attr_writer :book
64
63
 
65
64
  # @return [Epuber::Book] reference to book
66
65
  #
67
66
  def book
68
- @book || (parent && parent.book)
67
+ @book || parent&.book
69
68
  end
70
69
 
71
-
72
70
  # Create new sub_target with name
73
71
  #
74
72
  # @param [String] name
@@ -77,7 +75,7 @@ module Epuber
77
75
  #
78
76
  def sub_target(name)
79
77
  child = create_child_item(name)
80
- child.book = self.book
78
+ child.book = book
81
79
 
82
80
  yield child if block_given?
83
81
 
@@ -92,7 +90,7 @@ module Epuber
92
90
  #
93
91
  def sub_abstract_target(name)
94
92
  child = create_child_item(name)
95
- child.book = self.book
93
+ child.book = book
96
94
  child.is_abstract = true
97
95
 
98
96
  yield child if block_given?
@@ -119,9 +117,7 @@ module Epuber
119
117
  # parent files plus our files
120
118
  all_files = ((parent && parent.files) || []) + @files + @default_styles + @default_scripts
121
119
 
122
- unless @attributes_values[:cover_image].nil?
123
- all_files << @attributes_values[:cover_image]
124
- end
120
+ all_files << @attributes_values[:cover_image] unless @attributes_values[:cover_image].nil?
125
121
 
126
122
  all_files
127
123
  end
@@ -130,7 +126,7 @@ module Epuber
130
126
  # @return [Hash<String, Object>]
131
127
  #
132
128
  def constants
133
- ((parent && parent.constants) || {}).merge(@constants)
129
+ (parent&.constants || {}).merge(@constants)
134
130
  end
135
131
 
136
132
  # @return [Array<Epuber::Book::FileRequest>]
@@ -158,8 +154,8 @@ module Epuber
158
154
  # @return [String] version of result epub
159
155
  #
160
156
  attribute :epub_version,
161
- required: true,
162
- inherited: true,
157
+ required: true,
158
+ inherited: true,
163
159
  auto_convert: { [String, Integer, Float] => Version },
164
160
  default_value: 3.0
165
161
 
@@ -176,38 +172,40 @@ module Epuber
176
172
  # @return [String] target will use custom font (for iBooks only)
177
173
  #
178
174
  attribute :custom_fonts,
179
- types: [TrueClass, FalseClass],
175
+ types: [TrueClass, FalseClass],
180
176
  inherited: true
181
177
 
182
178
  # @return [Bool] hint for compiler to add some iBooks related stuff
183
179
  #
184
180
  attribute :is_ibooks,
185
- types: [TrueClass, FalseClass],
181
+ types: [TrueClass, FalseClass],
186
182
  inherited: true
187
183
 
188
184
  # @return [Bool] whether the target uses fixed layout
189
185
  #
190
186
  attribute :fixed_layout,
191
- types: [TrueClass, FalseClass],
187
+ types: [TrueClass, FalseClass],
192
188
  inherited: true
193
189
 
194
190
  # @return [FileRequest] file request to cover image
195
191
  #
196
192
  attribute :cover_image,
197
- types: [FileRequest],
198
- inherited: true,
199
- auto_convert: { [String] => ->(value) { FileRequest.new(value, group: :image, properties: [:cover_image]) } }
193
+ types: [FileRequest],
194
+ inherited: true,
195
+ auto_convert: { [String] => lambda { |value|
196
+ FileRequest.new(value, group: :image, properties: [:cover_image])
197
+ } }
200
198
 
201
199
  # @return [Size] size of view port, mainly this is used for fixed layout
202
200
  #
203
201
  attribute :default_viewport,
204
- types: [Size],
202
+ types: [Size],
205
203
  inherited: true
206
204
 
207
205
  # @return [Bool] whether the target should create mobi
208
206
  #
209
207
  attribute :create_mobi,
210
- types: [TrueClass, FalseClass],
208
+ types: [TrueClass, FalseClass],
211
209
  inherited: true
212
210
 
213
211
  # @return [Bool] allows to create abstract targets that are only used as template for other targets
@@ -217,8 +215,8 @@ module Epuber
217
215
  inherited: false
218
216
 
219
217
 
220
- # @param file_path [String | Epuber::Book::File]
221
- # @param group [Symbol]
218
+ # @param [String | Epuber::Book::File] file_path
219
+ # @param [Symbol] group
222
220
  #
223
221
  # @return [Epuber::Book::File] created file
224
222
  #
@@ -240,7 +238,7 @@ module Epuber
240
238
  end
241
239
  end
242
240
 
243
- # @param file_paths [Array<String>]
241
+ # @param [Array<String>] file_paths
244
242
  #
245
243
  # @return [void]
246
244
  #
@@ -251,8 +249,8 @@ module Epuber
251
249
  end
252
250
  end
253
251
 
254
- # @param key [String]
255
- # @param value [String]
252
+ # @param [String] key
253
+ # @param [String] value
256
254
  #
257
255
  # @return [void]
258
256
  #
@@ -264,8 +262,7 @@ module Epuber
264
262
  end
265
263
  end
266
264
 
267
-
268
- # @param file_paths [Array<String>]
265
+ # @param [Array<String>] file_paths
269
266
  #
270
267
  # @return [void]
271
268
  #
@@ -281,7 +278,7 @@ module Epuber
281
278
  # Add default styles to default target, default styles will be automatically added to xhtml document
282
279
  #
283
280
  # Only difference with #add_default_style is it adds multiple files with one pattern
284
- # @param file_paths [Array<String>]
281
+ # @param [Array<String>] file_paths
285
282
  #
286
283
  # @return [void]
287
284
  #
@@ -294,7 +291,7 @@ module Epuber
294
291
  end
295
292
  end
296
293
 
297
- # @param file_paths [Array<String>]
294
+ # @param [Array<String>] file_paths
298
295
  #
299
296
  # @return [void]
300
297
  #
@@ -310,7 +307,7 @@ module Epuber
310
307
  # Add default scripts to target, default scripts will be automatically added to xhtml document
311
308
  #
312
309
  # Only difference with #add_default_script is it adds multiple files with one pattern
313
- # @param file_paths [Array<String>]
310
+ # @param [Array<String>] file_paths
314
311
  #
315
312
  # @return [void]
316
313
  #
@@ -333,7 +330,7 @@ module Epuber
333
330
  yield(@root_toc, self) if block_given?
334
331
  end
335
332
 
336
- # @param path [String] use some file/module/package
333
+ # @param [String] path use some file/module/package
337
334
  #
338
335
  # @return [nil]
339
336
  #
@@ -11,7 +11,7 @@ module Epuber
11
11
  #
12
12
  attribute :file_request,
13
13
  auto_convert: { String => FileRequest },
14
- inherited: true
14
+ inherited: true
15
15
 
16
16
  # @return [String]
17
17
  #
@@ -91,9 +91,7 @@ module Epuber
91
91
  item.file_request = file_obj
92
92
  end
93
93
 
94
- unless file_fragment.nil? || file_fragment.empty?
95
- item.file_fragment = file_fragment
96
- end
94
+ item.file_fragment = file_fragment unless file_fragment.nil? || file_fragment.empty?
97
95
  end
98
96
 
99
97
  if title.is_a?(String)
data/lib/epuber/book.rb CHANGED
@@ -61,12 +61,12 @@ module Epuber
61
61
  @default_target.send(sym)
62
62
  end
63
63
 
64
- unless readonly
65
- # setter
66
- setter_method = sym.to_s + '='
67
- define_method(setter_method) do |newValue|
68
- @default_target.send(setter_method, newValue)
69
- end
64
+ return if readonly
65
+
66
+ # setter
67
+ setter_method = "#{sym}="
68
+ define_method(setter_method) do |new_value|
69
+ @default_target.send(setter_method, new_value)
70
70
  end
71
71
  end
72
72
 
@@ -78,7 +78,7 @@ module Epuber
78
78
  # @return [Array<Target>]
79
79
  #
80
80
  def all_targets
81
- if @default_target.sub_targets.length == 0
81
+ if @default_target.sub_targets.empty?
82
82
  [@default_target]
83
83
  else
84
84
  @default_target.sub_targets
@@ -86,7 +86,7 @@ module Epuber
86
86
  end
87
87
 
88
88
  def flat_all_targets
89
- if @default_target.sub_targets.length == 0
89
+ if @default_target.sub_targets.empty?
90
90
  [@default_target]
91
91
  else
92
92
  @default_target.flat_sub_items
@@ -94,7 +94,7 @@ module Epuber
94
94
  end
95
95
 
96
96
  def buildable_targets
97
- flat_all_targets.select { |t| !t.is_abstract }
97
+ flat_all_targets.reject(&:is_abstract)
98
98
  end
99
99
 
100
100
  # Defines new target
@@ -125,7 +125,8 @@ module Epuber
125
125
  #
126
126
  def targets(*names, &block)
127
127
  if names.empty?
128
- UI.warning('Book#targets to get all targets is deprecated, use #all_targets instead', location: caller_locations.first)
128
+ UI.warning('Book#targets to get all targets is deprecated, use #all_targets instead',
129
+ location: caller_locations.first)
129
130
  return all_targets
130
131
  end
131
132
 
@@ -155,11 +156,11 @@ module Epuber
155
156
  # @return [Array<Contributor>] authors of book
156
157
  #
157
158
  attribute :authors,
158
- types: [Contributor, NormalContributor],
159
- container: Array,
160
- required: true,
161
- singularize: true,
162
- auto_convert: { [String, Hash] => ->(value) { Contributor.from_obj(value, 'aut') } }
159
+ types: [Contributor, NormalContributor],
160
+ container: Array,
161
+ required: true,
162
+ singularize: true,
163
+ auto_convert: { [String, Hash] => ->(value) { Contributor.from_obj(value) } }
163
164
 
164
165
 
165
166
  # @return [String] publisher name
@@ -214,7 +215,7 @@ module Epuber
214
215
  # @return [Date] date of book was published
215
216
  #
216
217
  attribute :published,
217
- types: [Date],
218
+ types: [Date],
218
219
  auto_convert: { String => Date }
219
220
 
220
221
 
@@ -222,14 +223,14 @@ module Epuber
222
223
  # @note Is used only for ibooks versions
223
224
  #
224
225
  attribute :version,
225
- inherited: true,
226
- types: [Version],
226
+ inherited: true,
227
+ types: [Version],
227
228
  auto_convert: { [String, Integer, Float] => Version }
228
229
 
229
230
  # @return [String] build version of book
230
231
  #
231
232
  attribute :build_version,
232
- types: [Version],
233
+ types: [Version],
233
234
  auto_convert: { [String, Integer, Float] => Version }
234
235
 
235
236
  # @return [String] base name for output epub file
@@ -250,7 +251,6 @@ module Epuber
250
251
  @default_target.add_files(*file_paths)
251
252
  end
252
253
 
253
-
254
254
  # Add constant to target, constants can be used within text files
255
255
  #
256
256
  def add_const(*args)
@@ -294,7 +294,7 @@ module Epuber
294
294
 
295
295
  # Finds target with name or nil when not found
296
296
  #
297
- # @param target_name [Symbol, String, Epuber::Book::Target]
297
+ # @param [Symbol, String, Epuber::Book::Target] target_name
298
298
  #
299
299
  # @return [Epuber::Book::Target, nil]
300
300
  #
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../checker'
4
+
5
+ module Epuber
6
+ class Checker
7
+ class BookspecChecker < Checker
8
+ # @return [Epuber::Book]
9
+ #
10
+ attr_reader :book
11
+
12
+ # @param [Epuber::Book] book
13
+ # @param [CompilationContext] compilation_context
14
+ #
15
+ # @return nil
16
+ #
17
+ def call(book, compilation_context)
18
+ @book = book
19
+
20
+ @block.call(self, book, compilation_context)
21
+
22
+ @book = nil
23
+ end
24
+ end
25
+ end
26
+ end
@@ -10,9 +10,9 @@ module Epuber
10
10
  class Checker
11
11
  class TextChecker < Checker
12
12
  class MatchProblem < Compiler::Problem
13
- # @param message [String]
14
- # @param file_path [String]
15
- # @param match [MatchData]
13
+ # @param [String] message
14
+ # @param [String] file_path
15
+ # @param [MatchData] match
16
16
  #
17
17
  def initialize(match, message, file_path)
18
18
  whole_text = match.pre_match + match.matched_string + match.post_match
@@ -36,8 +36,8 @@ module Epuber
36
36
 
37
37
 
38
38
 
39
- # @param file_path [String]
40
- # @param text [String]
39
+ # @param [String] file_path
40
+ # @param [String] text
41
41
  # @param [CompilationContext] compilation_context
42
42
  #
43
43
  # @return nil
@@ -52,7 +52,7 @@ module Epuber
52
52
  @file_path = nil
53
53
  end
54
54
 
55
- # @param regexp [Regexp]
55
+ # @param [Regexp] regexp
56
56
  # @param [String] message message to display, when the regexp found something
57
57
  #
58
58
  def should_not_contain(regexp, message)
@@ -61,9 +61,18 @@ module Epuber
61
61
  matches = text.to_enum(:scan, regexp).map { Regexp.last_match }
62
62
  matches.each do |match|
63
63
  # @type match [MatchData]
64
- UI.print_processing_problem MatchProblem.new(match, message, Config.instance.pretty_path_from_project(file_path))
64
+ UI.print_processing_problem MatchProblem.new(match, message,
65
+ Config.instance.pretty_path_from_project(file_path))
65
66
  end
66
67
  end
68
+
69
+ def error(message, location: nil)
70
+ super(message, location: location || Config.instance.pretty_path_from_project(file_path))
71
+ end
72
+
73
+ def warning(message, location: nil)
74
+ super(message, location: location || Config.instance.pretty_path_from_project(file_path))
75
+ end
67
76
  end
68
77
  end
69
78
  end
@@ -5,14 +5,28 @@ require_relative 'checker_transformer_base'
5
5
  module Epuber
6
6
  class Checker < CheckerTransformerBase
7
7
  require_relative 'checker/text_checker'
8
+ require_relative 'checker/bookspec_checker'
8
9
 
9
10
  # @return [Hash<Symbol, Class>]
10
11
  #
11
12
  def self.map_source_type__class
12
13
  {
13
- :result_text_xhtml_string => TextChecker,
14
- :source_text_file => TextChecker,
14
+ result_text_xhtml_string: TextChecker,
15
+ source_text_file: TextChecker,
16
+ bookspec: BookspecChecker,
15
17
  }.merge(super)
16
18
  end
19
+
20
+ def warning(messsage, location: nil)
21
+ UI.warning(messsage, location: location)
22
+ end
23
+
24
+ def error(messsage, location: nil)
25
+ if Config.instance.release_build
26
+ UI.error!(messsage, location: location)
27
+ else
28
+ UI.error(messsage, location: location)
29
+ end
30
+ end
17
31
  end
18
32
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Epuber
4
4
  class CheckerTransformerBase
5
-
6
5
  # Type of source value for this checker, valid values are:
7
6
  # :result_text_xhtml_string just before writing result xhtml to build folder
8
7
  #
@@ -41,8 +40,6 @@ module Epuber
41
40
  [:run_only_before_release]
42
41
  end
43
42
 
44
-
45
-
46
43
  def call(*args)
47
44
  raise NotImplementedError, 'You should override this method'
48
45
  end
@@ -58,14 +55,14 @@ module Epuber
58
55
  {}
59
56
  end
60
57
 
61
-
62
- # @param type [Symbol]
58
+ # @param [Symbol] type
63
59
  #
64
60
  # @return [Class]
65
61
  #
66
62
  def self.class_for_source_type(type)
67
- checker_class = self.map_source_type__class[type]
63
+ checker_class = map_source_type__class[type]
68
64
  raise "#{self} class not found for type: #{type.inspect}" if checker_class.nil?
65
+
69
66
  checker_class
70
67
  end
71
68
  end