epuber 0.8.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +2 -2
  5. data/epuber.gemspec +3 -6
  6. data/lib/epuber/book/contributor.rb +10 -6
  7. data/lib/epuber/book/file_request.rb +2 -2
  8. data/lib/epuber/book/target.rb +10 -10
  9. data/lib/epuber/book.rb +2 -2
  10. data/lib/epuber/checker/text_checker.rb +14 -6
  11. data/lib/epuber/checker_transformer_base.rb +1 -1
  12. data/lib/epuber/command/build.rb +6 -1
  13. data/lib/epuber/command/from_file.rb +39 -0
  14. data/lib/epuber/command/init.rb +11 -9
  15. data/lib/epuber/command/server.rb +1 -1
  16. data/lib/epuber/command.rb +1 -0
  17. data/lib/epuber/compiler/file_database.rb +2 -2
  18. data/lib/epuber/compiler/file_finders/abstract.rb +3 -3
  19. data/lib/epuber/compiler/file_resolver.rb +3 -2
  20. data/lib/epuber/compiler/file_types/abstract_file.rb +1 -3
  21. data/lib/epuber/compiler/file_types/bade_file.rb +9 -9
  22. data/lib/epuber/compiler/file_types/css_file.rb +84 -0
  23. data/lib/epuber/compiler/file_types/source_file.rb +31 -0
  24. data/lib/epuber/compiler/file_types/stylus_file.rb +4 -3
  25. data/lib/epuber/compiler/nav_generator.rb +5 -5
  26. data/lib/epuber/compiler/opf_generator.rb +4 -4
  27. data/lib/epuber/compiler/xhtml_processor.rb +7 -25
  28. data/lib/epuber/compiler.rb +12 -7
  29. data/lib/epuber/config.rb +3 -3
  30. data/lib/epuber/dsl/attribute.rb +1 -1
  31. data/lib/epuber/dsl/attribute_support.rb +4 -4
  32. data/lib/epuber/dsl/object.rb +2 -2
  33. data/lib/epuber/from_file/bookspec_generator.rb +371 -0
  34. data/lib/epuber/from_file/encryption_handler.rb +146 -0
  35. data/lib/epuber/from_file/from_file_executor.rb +140 -0
  36. data/lib/epuber/from_file/nav_file.rb +163 -0
  37. data/lib/epuber/from_file/opf_file.rb +219 -0
  38. data/lib/epuber/plugin.rb +1 -1
  39. data/lib/epuber/server.rb +17 -17
  40. data/lib/epuber/transformer/book_transformer.rb +108 -0
  41. data/lib/epuber/transformer.rb +2 -0
  42. data/lib/epuber/user_interface.rb +2 -2
  43. data/lib/epuber/vendor/ruby_templater.rb +3 -3
  44. data/lib/epuber/vendor/version.rb +3 -3
  45. data/lib/epuber/version.rb +1 -1
  46. metadata +40 -59
data/lib/epuber/server.rb CHANGED
@@ -179,8 +179,8 @@ module Epuber
179
179
  self.class.build_path
180
180
  end
181
181
 
182
- # @param level [Symbol]
183
- # @param message [String]
182
+ # @param [Symbol] level
183
+ # @param [String] message
184
184
  #
185
185
  # @return nil
186
186
  #
@@ -208,7 +208,7 @@ module Epuber
208
208
 
209
209
  # @!group Helpers
210
210
 
211
- # @param pattern [String]
211
+ # @param [String] pattern
212
212
  #
213
213
  # @return [String] path to file
214
214
  #
@@ -217,7 +217,7 @@ module Epuber
217
217
  finder.find_files(pattern).first
218
218
  end
219
219
 
220
- # @param index [Fixnum]
220
+ # @param [Fixnum] index
221
221
  # @return [Epuber::Book::File, nil]
222
222
  #
223
223
  def spine_file_at(index)
@@ -257,8 +257,8 @@ module Epuber
257
257
  add_script_to_head(html_doc, source)
258
258
  end
259
259
 
260
- # @param html_doc [Nokogiri::HTML::Document]
261
- # @param script_text [String]
260
+ # @param [Nokogiri::HTML::Document] html_doc
261
+ # @param [String] script_text
262
262
  #
263
263
  def add_script_to_head(html_doc, script_text)
264
264
  script_node = html_doc.create_element('script', script_text, type: 'text/javascript')
@@ -272,7 +272,7 @@ module Epuber
272
272
  head.add_child(script_node)
273
273
  end
274
274
 
275
- # @param html_doc [Nokogiri::HTML::Document]
275
+ # @param [Nokogiri::HTML::Document] html_doc
276
276
  #
277
277
  def add_auto_refresh_script(html_doc)
278
278
  add_file_to_head(:js, html_doc, 'auto_refresh/reloader.coffee')
@@ -282,7 +282,7 @@ module Epuber
282
282
  add_script_to_head(html_doc, 'var auto_refresh = new AutoRefresh(window, console);')
283
283
  end
284
284
 
285
- # @param html_doc [Nokogiri::HTML::Document]
285
+ # @param [Nokogiri::HTML::Document] html_doc
286
286
  #
287
287
  def add_keyboard_control_script(html_doc, previous_path, next_path)
288
288
  add_script_file_to_head(html_doc, 'keyboard_control.coffee',
@@ -290,7 +290,7 @@ module Epuber
290
290
  '$next_path' => next_path)
291
291
  end
292
292
 
293
- # @param html_doc [Nokogiri::HTML::Document]
293
+ # @param [Nokogiri::HTML::Document] html_doc
294
294
  #
295
295
  def add_file_to_head(type, html_doc, file_path)
296
296
  head = html_doc.at_css('head')
@@ -310,9 +310,9 @@ module Epuber
310
310
  head.add_child(node)
311
311
  end
312
312
 
313
- # @param html_doc [Nokogiri::HTML::Document]
314
- # @param key [String]
315
- # @param value [String]
313
+ # @param [Nokogiri::HTML::Document] html_doc
314
+ # @param [String] key
315
+ # @param [String] value
316
316
  #
317
317
  def add_meta_to_head(name, content, html_doc, force: false)
318
318
  head = html_doc.at_css('head')
@@ -368,7 +368,7 @@ module Epuber
368
368
  @compilation_thread.join
369
369
  end
370
370
 
371
- # @param message [String]
371
+ # @param [String] message
372
372
  #
373
373
  def self.send_to_clients(message)
374
374
  _log :info, "sending message to clients #{message.inspect}"
@@ -378,7 +378,7 @@ module Epuber
378
378
  end
379
379
  end
380
380
 
381
- # @param type [Symbol]
381
+ # @param [Symbol] type
382
382
  def self.notify_clients(type, data = nil)
383
383
  _log :info, "Notifying clients with type #{type.inspect}"
384
384
  raise "Not known type `#{type}`" unless %i[styles reload compile_start compile_end].include?(type)
@@ -401,9 +401,9 @@ module Epuber
401
401
  files_paths.select { |file| file_resolver.file_with_source_path(file) || book.file_path == file }
402
402
  end
403
403
 
404
- # @param modified [Array<String>]
405
- # @param added [Array<String>]
406
- # @param removed [Array<String>]
404
+ # @param [Array<String>] modified
405
+ # @param [Array<String>] added
406
+ # @param [Array<String>] removed
407
407
  #
408
408
  def self.changes_detected(modified, added, removed)
409
409
  all_changed = (modified + added + removed).uniq.map(&:unicode_normalize)
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../transformer'
4
+
5
+ module Epuber
6
+ class Transformer
7
+ class BookTransformer < Transformer
8
+ # @return [Book]
9
+ #
10
+ attr_accessor :book
11
+
12
+ # @return [CompilationContext]
13
+ #
14
+ attr_accessor :compilation_context
15
+
16
+ # @param [Epuber::Book] book
17
+ # @param [Epuber::Compiler::CompilationContext] compilation_context
18
+ #
19
+ def call(book, compilation_context)
20
+ @book = book
21
+ @compilation_context = compilation_context
22
+
23
+ @block.call(self, @book, @compilation_context)
24
+
25
+ @book = nil
26
+ @compilation_context = nil
27
+ end
28
+
29
+ # Find file in source or destination paths
30
+ #
31
+ # @param [String] pattern
32
+ # @param [Thread::Backtrace::Location] location
33
+ #
34
+ # @return [Epuber::Compiler::FileTypes::AbstractFile, nil]
35
+ #
36
+ def find_file(pattern, location: caller_locations.first)
37
+ return pattern if pattern.is_a?(Compiler::FileTypes::AbstractFile)
38
+
39
+ UI.error!("Pattern for finding file can't be nil", location: location) if pattern.nil?
40
+
41
+ begin
42
+ path = @compilation_context.file_resolver.source_finder.find_file(pattern)
43
+ @compilation_context.file_resolver.file_with_source_path(path)
44
+ rescue Compiler::FileFinders::FileNotFoundError
45
+ begin
46
+ path = @compilation_context.file_resolver.dest_finder.find_file(pattern)
47
+ @compilation_context.file_resolver.file_with_destination_path(path)
48
+ rescue Compiler::FileFinders::FileNotFoundError
49
+ nil
50
+ end
51
+ end
52
+ end
53
+
54
+ # Find files destination paths
55
+ #
56
+ # @param [String] pattern
57
+ # @param [Thread::Backtrace::Location] location
58
+ #
59
+ # @return [Array<Epuber::Compiler::FileTypes::AbstractFile>]
60
+ #
61
+ def find_destination_files(pattern, location: caller_locations.first)
62
+ UI.error!("Pattern for finding file can't be nil", location: location) if pattern.nil?
63
+
64
+ paths = @compilation_context.file_resolver.dest_finder.find_files(pattern)
65
+ paths.map { |path| @compilation_context.file_resolver.file_with_destination_path(path) }
66
+ end
67
+
68
+ # Find file and raise exception if not found
69
+ #
70
+ # @param [String] pattern
71
+ # @param [Thread::Backtrace::Location] location
72
+ #
73
+ # @return [Epuber::Compiler::FileTypes::AbstractFile]
74
+ #
75
+ def get_file(pattern, location: caller_locations.first)
76
+ file = find_file(pattern, location: location)
77
+ UI.error!("File with pattern #{pattern} not found", location: location) unless file
78
+
79
+ file
80
+ end
81
+
82
+ # Read file from destination path (raises exception if not found)
83
+ #
84
+ # @param [String] pattern
85
+ # @param [Thread::Backtrace::Location] location
86
+ #
87
+ # @return [String]
88
+ #
89
+ def read_destination_file(pattern, location: caller_locations.first)
90
+ file = get_file(pattern, location: location)
91
+ File.read(file.final_destination_path)
92
+ end
93
+
94
+ # Write file to destination path (raises exception if not found)
95
+ #
96
+ # @param [String] pattern
97
+ # @param [String] content
98
+ # @param [Thread::Backtrace::Location] location
99
+ #
100
+ # @return [void]
101
+ #
102
+ def write_destination_file(pattern, content, location: caller_locations.first)
103
+ file = get_file(pattern, location: location)
104
+ Compiler::FileTypes::AbstractFile.write_to_file(content, file.final_destination_path)
105
+ end
106
+ end
107
+ end
108
+ end
@@ -5,6 +5,7 @@ require_relative 'checker_transformer_base'
5
5
  module Epuber
6
6
  class Transformer < CheckerTransformerBase
7
7
  require_relative 'transformer/text_transformer'
8
+ require_relative 'transformer/book_transformer'
8
9
 
9
10
  # @return [Hash<Symbol, Class>]
10
11
  #
@@ -12,6 +13,7 @@ module Epuber
12
13
  {
13
14
  result_text_xhtml_string: TextTransformer,
14
15
  source_text_file: TextTransformer,
16
+ after_all_text_files: BookTransformer,
15
17
  }.merge(super)
16
18
  end
17
19
  end
@@ -192,9 +192,9 @@ module Epuber
192
192
 
193
193
  comps = []
194
194
  comps << message.to_s
195
- message_already_formatted = (
195
+ message_already_formatted =
196
196
  message.is_a?(Epuber::Compiler::Problem) || message.is_a?(Epuber::Checker::TextChecker::MatchProblem)
197
- )
197
+
198
198
  if !location.nil? && !message_already_formatted
199
199
  path = location.path
200
200
 
@@ -16,7 +16,7 @@ module Epuber
16
16
  #
17
17
  attr_accessor :locals
18
18
 
19
- # @param source [String]
19
+ # @param [String] source
20
20
  #
21
21
  # @return [self]
22
22
  #
@@ -27,7 +27,7 @@ module Epuber
27
27
  inst
28
28
  end
29
29
 
30
- # @param file [String, File]
30
+ # @param [String, File] file
31
31
  #
32
32
  # @return [self]
33
33
  #
@@ -46,7 +46,7 @@ module Epuber
46
46
  # DSL methods
47
47
 
48
48
 
49
- # @param locals [Hash]
49
+ # @param [Hash] locals
50
50
  #
51
51
  # @return [self]
52
52
  #
@@ -10,7 +10,7 @@ module Epuber
10
10
  class Version
11
11
  include Comparable
12
12
 
13
- VERSION_RE ||= /\A[0-9]+(\.[0-9a-zA-Z]+)*\z/.freeze
13
+ VERSION_RE = /\A[0-9]+(\.[0-9a-zA-Z]+)*\z/.freeze
14
14
 
15
15
  # True if the +version+ string matches RubyGems' requirements.
16
16
  #
@@ -52,7 +52,7 @@ module Epuber
52
52
  def <=>(other)
53
53
  return unless other.is_a?(Version) || other.is_a?(String) || other.is_a?(Float) || other.is_a?(Integer)
54
54
 
55
- other = other.is_a?(Version) ? other : Version.new(other)
55
+ other = Version.new(other) unless other.is_a?(Version)
56
56
 
57
57
  return 0 if @version == other.version
58
58
 
@@ -61,7 +61,7 @@ module Epuber
61
61
 
62
62
  lhsize = lhsegments.size
63
63
  rhsize = rhsegments.size
64
- limit = (lhsize > rhsize ? lhsize : rhsize) - 1
64
+ limit = [lhsize, rhsize].max - 1
65
65
 
66
66
  i = 0
67
67
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Epuber
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.1'
5
5
 
6
6
  HOME_URL = 'https://github.com/epuber-io/epuber'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epuber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Kříž
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-19 00:00:00.000000000 Z
11
+ date: 2023-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -120,6 +120,20 @@ dependencies:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
122
  version: '1.0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: uuidtools
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '2.1'
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '2.1'
123
137
  - !ruby/object:Gem::Dependency
124
138
  name: sinatra
125
139
  requirement: !ruby/object:Gem::Requirement
@@ -277,87 +291,45 @@ dependencies:
277
291
  - !ruby/object:Gem::Version
278
292
  version: '2.4'
279
293
  - !ruby/object:Gem::Dependency
280
- name: epuber-stylus
281
- requirement: !ruby/object:Gem::Requirement
282
- requirements:
283
- - - "~>"
284
- - !ruby/object:Gem::Version
285
- version: '1.1'
286
- - - ">="
287
- - !ruby/object:Gem::Version
288
- version: 1.1.1
289
- type: :runtime
290
- prerelease: false
291
- version_requirements: !ruby/object:Gem::Requirement
292
- requirements:
293
- - - "~>"
294
- - !ruby/object:Gem::Version
295
- version: '1.1'
296
- - - ">="
297
- - !ruby/object:Gem::Version
298
- version: 1.1.1
299
- - !ruby/object:Gem::Dependency
300
- name: fakefs
294
+ name: css_parser
301
295
  requirement: !ruby/object:Gem::Requirement
302
296
  requirements:
303
297
  - - ">="
304
298
  - !ruby/object:Gem::Version
305
- version: '1.3'
299
+ version: '0.8'
306
300
  - - "<"
307
301
  - !ruby/object:Gem::Version
308
- version: '3.0'
309
- type: :development
302
+ version: '2.0'
303
+ type: :runtime
310
304
  prerelease: false
311
305
  version_requirements: !ruby/object:Gem::Requirement
312
306
  requirements:
313
307
  - - ">="
314
308
  - !ruby/object:Gem::Version
315
- version: '1.3'
309
+ version: '0.8'
316
310
  - - "<"
317
311
  - !ruby/object:Gem::Version
318
- version: '3.0'
312
+ version: '2.0'
319
313
  - !ruby/object:Gem::Dependency
320
- name: rake
314
+ name: epuber-stylus
321
315
  requirement: !ruby/object:Gem::Requirement
322
316
  requirements:
323
317
  - - "~>"
324
318
  - !ruby/object:Gem::Version
325
- version: '13.0'
326
- type: :development
327
- prerelease: false
328
- version_requirements: !ruby/object:Gem::Requirement
329
- requirements:
330
- - - "~>"
331
- - !ruby/object:Gem::Version
332
- version: '13.0'
333
- - !ruby/object:Gem::Dependency
334
- name: rspec
335
- requirement: !ruby/object:Gem::Requirement
336
- requirements:
337
- - - "~>"
319
+ version: '1.1'
320
+ - - ">="
338
321
  - !ruby/object:Gem::Version
339
- version: '3.2'
340
- type: :development
322
+ version: 1.1.1
323
+ type: :runtime
341
324
  prerelease: false
342
325
  version_requirements: !ruby/object:Gem::Requirement
343
326
  requirements:
344
327
  - - "~>"
345
328
  - !ruby/object:Gem::Version
346
- version: '3.2'
347
- - !ruby/object:Gem::Dependency
348
- name: rubocop
349
- requirement: !ruby/object:Gem::Requirement
350
- requirements:
351
- - - "~>"
352
- - !ruby/object:Gem::Version
353
- version: '1.14'
354
- type: :development
355
- prerelease: false
356
- version_requirements: !ruby/object:Gem::Requirement
357
- requirements:
358
- - - "~>"
329
+ version: '1.1'
330
+ - - ">="
359
331
  - !ruby/object:Gem::Version
360
- version: '1.14'
332
+ version: 1.1.1
361
333
  description:
362
334
  email:
363
335
  - samnung@gmail.com
@@ -384,6 +356,7 @@ files:
384
356
  - lib/epuber/command.rb
385
357
  - lib/epuber/command/build.rb
386
358
  - lib/epuber/command/compile.rb
359
+ - lib/epuber/command/from_file.rb
387
360
  - lib/epuber/command/init.rb
388
361
  - lib/epuber/command/server.rb
389
362
  - lib/epuber/compiler.rb
@@ -398,6 +371,7 @@ files:
398
371
  - lib/epuber/compiler/file_types/bade_file.rb
399
372
  - lib/epuber/compiler/file_types/coffee_script_file.rb
400
373
  - lib/epuber/compiler/file_types/container_xml_file.rb
374
+ - lib/epuber/compiler/file_types/css_file.rb
401
375
  - lib/epuber/compiler/file_types/generated_file.rb
402
376
  - lib/epuber/compiler/file_types/ibooks_display_options_file.rb
403
377
  - lib/epuber/compiler/file_types/image_file.rb
@@ -420,6 +394,11 @@ files:
420
394
  - lib/epuber/dsl/object.rb
421
395
  - lib/epuber/dsl/tree_object.rb
422
396
  - lib/epuber/epubcheck.rb
397
+ - lib/epuber/from_file/bookspec_generator.rb
398
+ - lib/epuber/from_file/encryption_handler.rb
399
+ - lib/epuber/from_file/from_file_executor.rb
400
+ - lib/epuber/from_file/nav_file.rb
401
+ - lib/epuber/from_file/opf_file.rb
423
402
  - lib/epuber/helper.rb
424
403
  - lib/epuber/lockfile.rb
425
404
  - lib/epuber/plugin.rb
@@ -586,6 +565,7 @@ files:
586
565
  - lib/epuber/third_party/bower/bower_components/uri.js/src/jquery.URI.min.js
587
566
  - lib/epuber/third_party/bower/bower_components/uri.js/src/punycode.js
588
567
  - lib/epuber/transformer.rb
568
+ - lib/epuber/transformer/book_transformer.rb
589
569
  - lib/epuber/transformer/text_transformer.rb
590
570
  - lib/epuber/user_interface.rb
591
571
  - lib/epuber/vendor/hash_binding.rb
@@ -597,7 +577,8 @@ files:
597
577
  homepage: https://github.com/epuber-io/epuber
598
578
  licenses:
599
579
  - MIT
600
- metadata: {}
580
+ metadata:
581
+ rubygems_mfa_required: 'true'
601
582
  post_install_message:
602
583
  rdoc_options: []
603
584
  require_paths: