epuber 0.7.4 → 0.8.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 +4 -4
- data/Gemfile +1 -2
- data/README.md +2 -1
- data/epuber.gemspec +10 -12
- data/lib/epuber/book/contributor.rb +0 -1
- data/lib/epuber/book/file_request.rb +1 -1
- data/lib/epuber/book/target.rb +20 -23
- data/lib/epuber/book/toc_item.rb +2 -4
- data/lib/epuber/book.rb +19 -19
- data/lib/epuber/checker/bookspec_checker.rb +26 -0
- data/lib/epuber/checker/text_checker.rb +2 -1
- data/lib/epuber/checker.rb +16 -2
- data/lib/epuber/checker_transformer_base.rb +2 -5
- data/lib/epuber/command/build.rb +34 -24
- data/lib/epuber/command/init.rb +23 -23
- data/lib/epuber/command/server.rb +2 -2
- data/lib/epuber/command.rb +17 -20
- data/lib/epuber/compiler/compilation_context.rb +10 -8
- data/lib/epuber/compiler/file_database.rb +0 -2
- data/lib/epuber/compiler/file_finders/abstract.rb +33 -23
- data/lib/epuber/compiler/file_finders/imaginary.rb +40 -35
- data/lib/epuber/compiler/file_resolver.rb +77 -88
- data/lib/epuber/compiler/file_stat.rb +4 -4
- data/lib/epuber/compiler/file_types/abstract_file.rb +3 -4
- data/lib/epuber/compiler/file_types/bade_file.rb +12 -7
- data/lib/epuber/compiler/file_types/coffee_script_file.rb +1 -1
- data/lib/epuber/compiler/file_types/generated_file.rb +1 -1
- data/lib/epuber/compiler/file_types/image_file.rb +4 -2
- data/lib/epuber/compiler/file_types/nav_file.rb +0 -1
- data/lib/epuber/compiler/file_types/opf_file.rb +0 -1
- data/lib/epuber/compiler/file_types/source_file.rb +8 -3
- data/lib/epuber/compiler/file_types/xhtml_file.rb +67 -13
- data/lib/epuber/compiler/generator.rb +1 -2
- data/lib/epuber/compiler/meta_inf_generator.rb +1 -1
- data/lib/epuber/compiler/nav_generator.rb +5 -6
- data/lib/epuber/compiler/opf_generator.rb +22 -23
- data/lib/epuber/compiler/problem.rb +12 -21
- data/lib/epuber/compiler/xhtml_processor.rb +61 -31
- data/lib/epuber/compiler.rb +66 -19
- data/lib/epuber/config.rb +13 -7
- data/lib/epuber/dsl/attribute.rb +16 -17
- data/lib/epuber/dsl/attribute_support.rb +3 -3
- data/lib/epuber/dsl/object.rb +17 -15
- data/lib/epuber/dsl/tree_object.rb +2 -3
- data/lib/epuber/epubcheck.rb +15 -0
- data/lib/epuber/helper.rb +0 -1
- data/lib/epuber/lockfile.rb +7 -9
- data/lib/epuber/plugin.rb +1 -2
- data/lib/epuber/ruby_extensions/match_data.rb +1 -1
- data/lib/epuber/ruby_extensions/thread.rb +1 -0
- data/lib/epuber/server/base.styl +0 -1
- data/lib/epuber/server/basic.styl +1 -30
- data/lib/epuber/server/handlers.rb +1 -1
- data/lib/epuber/server.rb +67 -66
- data/lib/epuber/third_party/bower.rb +5 -5
- data/lib/epuber/transformer/text_transformer.rb +4 -2
- data/lib/epuber/transformer.rb +2 -2
- data/lib/epuber/user_interface.rb +49 -38
- data/lib/epuber/vendor/hash_binding.rb +9 -2
- data/lib/epuber/vendor/ruby_templater.rb +1 -5
- data/lib/epuber/vendor/version.rb +10 -10
- data/lib/epuber/version.rb +1 -1
- metadata +67 -69
- data/lib/epuber/server/fonts/AvenirNext/AvenirNext-Bold.ttf +0 -0
- data/lib/epuber/server/fonts/AvenirNext/AvenirNext-BoldItalic.ttf +0 -0
- data/lib/epuber/server/fonts/AvenirNext/AvenirNext-Italic.ttf +0 -0
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f0fcab4dfe82bc1ae829738a62f4915f02e79bbc105ab9eafd6d2c0a664dc60
|
4
|
+
data.tar.gz: 4fcaf730a6caf5d560a1525b5a2a000d29efec2819c82e7c1fdd1bc4cd470228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fd75c5cda4801241fa762d728308c3c1ebe9d668cc8cf4f9c7be3b3df48ca4715ec2498a2a4914a0c138c21adf49ecdcc66f49e47a33d0487107dd4b05a4d1b
|
7
|
+
data.tar.gz: 14e7bb639a81535df13bde1f5f92ecb29cf2892d5692d93ee1b97b1045cd650c4480cccfc7262280e2ad135a31796cb04932993d6e0dac21f0cbfaa226544045
|
data/Gemfile
CHANGED
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):
|
data/epuber.gemspec
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
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'
|
@@ -14,22 +12,22 @@ Gem::Specification.new do |spec|
|
|
14
12
|
spec.license = 'MIT'
|
15
13
|
spec.required_ruby_version = '>= 2.5'
|
16
14
|
|
17
|
-
spec.files = Dir['bin/**/*'] + Dir['lib/**/*'] + %w
|
15
|
+
spec.files = Dir['bin/**/*'] + Dir['lib/**/*'] + %w[epuber.gemspec Gemfile LICENSE.txt README.md]
|
18
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
17
|
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'
|
29
27
|
|
30
28
|
spec.add_runtime_dependency 'sinatra', '>= 2.0', '< 4.0'
|
31
|
-
spec.add_runtime_dependency 'sinatra-websocket', '~> 0.3'
|
32
29
|
spec.add_runtime_dependency 'sinatra-contrib', '>= 2.0', '< 4.0'
|
30
|
+
spec.add_runtime_dependency 'sinatra-websocket', '~> 0.3'
|
33
31
|
spec.add_runtime_dependency 'thin', '~> 1.6'
|
34
32
|
|
35
33
|
spec.add_runtime_dependency 'rmagick', '>= 4.2', '< 6.0'
|
@@ -37,12 +35,12 @@ Gem::Specification.new do |spec|
|
|
37
35
|
|
38
36
|
spec.add_runtime_dependency 'epubcheck-ruby', '>= 4.0', '< 6.0'
|
39
37
|
|
40
|
-
spec.add_runtime_dependency 'epuber-stylus', '~> 1.1', '>= 1.1.1'
|
41
|
-
spec.add_runtime_dependency 'coffee-script', '~> 2.4'
|
42
38
|
spec.add_runtime_dependency 'bade', '~> 0.3', '>= 0.3.1'
|
39
|
+
spec.add_runtime_dependency 'coffee-script', '~> 2.4'
|
40
|
+
spec.add_runtime_dependency 'epuber-stylus', '~> 1.1', '>= 1.1.1'
|
43
41
|
|
42
|
+
spec.add_development_dependency 'fakefs', '>= 1.3', '< 3.0' # 2.0.0 is not compatible with Ruby 2.5
|
43
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
44
44
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
45
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
|
48
46
|
end
|
@@ -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
|
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
|
data/lib/epuber/book/target.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
63
|
-
|
62
|
+
attr_writer :book
|
64
63
|
|
65
64
|
# @return [Epuber::Book] reference to book
|
66
65
|
#
|
67
66
|
def book
|
68
|
-
@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 =
|
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 =
|
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
|
-
(
|
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:
|
162
|
-
inherited:
|
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:
|
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:
|
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:
|
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:
|
198
|
-
inherited:
|
199
|
-
auto_convert: { [String] =>
|
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:
|
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:
|
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
|
@@ -264,7 +262,6 @@ module Epuber
|
|
264
262
|
end
|
265
263
|
end
|
266
264
|
|
267
|
-
|
268
265
|
# @param file_paths [Array<String>]
|
269
266
|
#
|
270
267
|
# @return [void]
|
data/lib/epuber/book/toc_item.rb
CHANGED
@@ -11,7 +11,7 @@ module Epuber
|
|
11
11
|
#
|
12
12
|
attribute :file_request,
|
13
13
|
auto_convert: { String => FileRequest },
|
14
|
-
inherited:
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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.
|
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.
|
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.
|
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',
|
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,10 +156,10 @@ module Epuber
|
|
155
156
|
# @return [Array<Contributor>] authors of book
|
156
157
|
#
|
157
158
|
attribute :authors,
|
158
|
-
types:
|
159
|
-
container:
|
160
|
-
required:
|
161
|
-
singularize:
|
159
|
+
types: [Contributor, NormalContributor],
|
160
|
+
container: Array,
|
161
|
+
required: true,
|
162
|
+
singularize: true,
|
162
163
|
auto_convert: { [String, Hash] => ->(value) { Contributor.from_obj(value, 'aut') } }
|
163
164
|
|
164
165
|
|
@@ -214,7 +215,7 @@ module Epuber
|
|
214
215
|
# @return [Date] date of book was published
|
215
216
|
#
|
216
217
|
attribute :published,
|
217
|
-
types:
|
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:
|
226
|
-
types:
|
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:
|
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)
|
@@ -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
|
@@ -61,7 +61,8 @@ 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,
|
64
|
+
UI.print_processing_problem MatchProblem.new(match, message,
|
65
|
+
Config.instance.pretty_path_from_project(file_path))
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
data/lib/epuber/checker.rb
CHANGED
@@ -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
|
-
:
|
14
|
-
:
|
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
58
|
# @param type [Symbol]
|
63
59
|
#
|
64
60
|
# @return [Class]
|
65
61
|
#
|
66
62
|
def self.class_for_source_type(type)
|
67
|
-
checker_class =
|
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
|
data/lib/epuber/command/build.rb
CHANGED
@@ -4,6 +4,7 @@ require 'fileutils'
|
|
4
4
|
require 'os'
|
5
5
|
|
6
6
|
require_relative '../command'
|
7
|
+
require_relative '../epubcheck'
|
7
8
|
|
8
9
|
module Epuber
|
9
10
|
class Command
|
@@ -50,48 +51,47 @@ module Epuber
|
|
50
51
|
def run
|
51
52
|
super
|
52
53
|
|
53
|
-
puts "
|
54
|
+
UI.puts "building book `#{Config.instance.pretty_path_from_project(book.file_path)}`"
|
54
55
|
|
55
56
|
if @release_version
|
56
57
|
# Remove all previous versions of compiled files
|
57
|
-
|
58
|
-
build_path = Epuber::Config.instance.release_build_path(target)
|
59
|
-
|
60
|
-
if ::File.directory?(build_path)
|
61
|
-
FileUtils.remove_dir(build_path, true)
|
62
|
-
end
|
63
|
-
end
|
58
|
+
cleanup_build_folders
|
64
59
|
|
65
60
|
# Build all targets to always clean directory
|
66
61
|
targets.each do |target|
|
62
|
+
Epuber::Config.instance.release_build = true
|
63
|
+
|
67
64
|
compiler = Epuber::Compiler.new(book, target)
|
68
65
|
build_path = Epuber::Config.instance.release_build_path(target)
|
69
66
|
compiler.compile(build_path, check: true, write: @should_write,
|
70
|
-
|
71
|
-
|
67
|
+
release: true, verbose: verbose?,
|
68
|
+
use_cache: false)
|
72
69
|
|
73
70
|
archive_name = compiler.epub_name
|
74
71
|
|
75
|
-
if ::File.exist?(archive_name)
|
76
|
-
FileUtils.remove_file(archive_name)
|
77
|
-
end
|
72
|
+
FileUtils.remove_file(archive_name) if ::File.exist?(archive_name)
|
78
73
|
|
79
74
|
archive_path = compiler.archive(archive_name)
|
80
75
|
|
81
|
-
|
76
|
+
Epubcheck.check(archive_path)
|
77
|
+
|
78
|
+
convert_epub_to_mobi(archive_path, "#{::File.basename(archive_path, '.epub')}.mobi") if target.create_mobi
|
82
79
|
|
83
|
-
|
80
|
+
Epuber::Config.instance.release_build = false
|
84
81
|
end
|
82
|
+
|
83
|
+
# Build all targets to always clean directory
|
85
84
|
else
|
86
85
|
targets.each do |target|
|
87
86
|
compiler = Epuber::Compiler.new(book, target)
|
88
87
|
build_path = Epuber::Config.instance.build_path(target)
|
89
|
-
compiler.compile(build_path, check: @should_check, write: @should_write, verbose: verbose?,
|
88
|
+
compiler.compile(build_path, check: @should_check, write: @should_write, verbose: verbose?,
|
89
|
+
use_cache: @use_cache)
|
90
90
|
archive_path = compiler.archive(configuration_suffix: 'debug')
|
91
91
|
|
92
|
-
|
92
|
+
Epubcheck.check(archive_path) if @should_check
|
93
93
|
|
94
|
-
convert_epub_to_mobi(archive_path, ::File.basename(archive_path, '.epub')
|
94
|
+
convert_epub_to_mobi(archive_path, "#{::File.basename(archive_path, '.epub')}.mobi") if target.create_mobi
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -103,7 +103,7 @@ module Epuber
|
|
103
103
|
# @return [Array<Epuber::Book::Target>]
|
104
104
|
#
|
105
105
|
def targets
|
106
|
-
@targets ||=
|
106
|
+
@targets ||= begin
|
107
107
|
targets = @targets_names
|
108
108
|
|
109
109
|
# when the list of targets is nil pick all available targets
|
@@ -112,7 +112,7 @@ module Epuber
|
|
112
112
|
else
|
113
113
|
targets.map { |target_name| book.target_named(target_name) }
|
114
114
|
end
|
115
|
-
|
115
|
+
end
|
116
116
|
end
|
117
117
|
|
118
118
|
def verify_all_targets_exists!
|
@@ -121,9 +121,9 @@ module Epuber
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def validate_dir(path)
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
return unless ::File.directory?(path)
|
125
|
+
|
126
|
+
path
|
127
127
|
end
|
128
128
|
|
129
129
|
def find_calibre_app
|
@@ -141,7 +141,9 @@ module Epuber
|
|
141
141
|
::File.join(find_calibre_app, 'Contents/MacOS/ebook-convert')
|
142
142
|
elsif OS.linux?
|
143
143
|
script_path = '/usr/bin/ebook-convert'
|
144
|
-
|
144
|
+
unless ::File.executable?(script_path)
|
145
|
+
UI.error!("Can't find ebook-convert in folder /usr/bin to convert EPUB to MOBI.")
|
146
|
+
end
|
145
147
|
script_path
|
146
148
|
else
|
147
149
|
UI.error!('Unsupported OS to convert EPUB to MOBI.')
|
@@ -151,6 +153,14 @@ module Epuber
|
|
151
153
|
def convert_epub_to_mobi(epub_path, mobi_path)
|
152
154
|
system(find_calibre_convert_file, epub_path, mobi_path)
|
153
155
|
end
|
156
|
+
|
157
|
+
def cleanup_build_folders
|
158
|
+
targets.each do |target|
|
159
|
+
build_path = Epuber::Config.instance.release_build_path(target)
|
160
|
+
|
161
|
+
FileUtils.remove_dir(build_path, true) if ::File.directory?(build_path)
|
162
|
+
end
|
163
|
+
end
|
154
164
|
end
|
155
165
|
end
|
156
166
|
end
|