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
@@ -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
@@ -25,7 +26,12 @@ module Epuber
25
26
  ].concat(super)
26
27
  end
27
28
 
28
- # @param argv [CLAide::ARGV]
29
+ # To resolve problem with `compile` treating as subcommand
30
+ def self.subcommands
31
+ []
32
+ end
33
+
34
+ # @param [CLAide::ARGV] argv
29
35
  #
30
36
  def initialize(argv)
31
37
  @targets_names = argv.arguments!
@@ -50,48 +56,47 @@ module Epuber
50
56
  def run
51
57
  super
52
58
 
53
- puts "compiling book `#{Config.instance.pretty_path_from_project(book.file_path)}`"
59
+ UI.puts "building book `#{Config.instance.pretty_path_from_project(book.file_path)}`"
54
60
 
55
61
  if @release_version
56
62
  # Remove all previous versions of compiled files
57
- targets.each do |target|
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
63
+ cleanup_build_folders
64
64
 
65
65
  # Build all targets to always clean directory
66
66
  targets.each do |target|
67
+ Epuber::Config.instance.release_build = true
68
+
67
69
  compiler = Epuber::Compiler.new(book, target)
68
70
  build_path = Epuber::Config.instance.release_build_path(target)
69
71
  compiler.compile(build_path, check: true, write: @should_write,
70
- release: true, verbose: verbose?,
71
- use_cache: false)
72
+ release: true, verbose: verbose?,
73
+ use_cache: false)
72
74
 
73
75
  archive_name = compiler.epub_name
74
76
 
75
- if ::File.exist?(archive_name)
76
- FileUtils.remove_file(archive_name)
77
- end
77
+ FileUtils.remove_file(archive_name) if ::File.exist?(archive_name)
78
78
 
79
79
  archive_path = compiler.archive(archive_name)
80
80
 
81
- system(%(epubcheck "#{archive_path}"))
81
+ Epubcheck.check(archive_path)
82
82
 
83
- convert_epub_to_mobi(archive_path, ::File.basename(archive_path, '.epub') + '.mobi') if target.create_mobi
83
+ convert_epub_to_mobi(archive_path, "#{::File.basename(archive_path, '.epub')}.mobi") if target.create_mobi
84
+
85
+ Epuber::Config.instance.release_build = false
84
86
  end
87
+
88
+ # Build all targets to always clean directory
85
89
  else
86
90
  targets.each do |target|
87
91
  compiler = Epuber::Compiler.new(book, target)
88
92
  build_path = Epuber::Config.instance.build_path(target)
89
- compiler.compile(build_path, check: @should_check, write: @should_write, verbose: verbose?, use_cache: @use_cache)
93
+ compiler.compile(build_path, check: @should_check, write: @should_write, verbose: verbose?,
94
+ use_cache: @use_cache)
90
95
  archive_path = compiler.archive(configuration_suffix: 'debug')
91
96
 
92
- system(%(epubcheck "#{archive_path}")) if @should_check
97
+ Epubcheck.check(archive_path) if @should_check
93
98
 
94
- convert_epub_to_mobi(archive_path, ::File.basename(archive_path, '.epub') + '.mobi') if target.create_mobi
99
+ convert_epub_to_mobi(archive_path, "#{::File.basename(archive_path, '.epub')}.mobi") if target.create_mobi
95
100
  end
96
101
  end
97
102
 
@@ -103,7 +108,7 @@ module Epuber
103
108
  # @return [Array<Epuber::Book::Target>]
104
109
  #
105
110
  def targets
106
- @targets ||= (
111
+ @targets ||= begin
107
112
  targets = @targets_names
108
113
 
109
114
  # when the list of targets is nil pick all available targets
@@ -112,7 +117,7 @@ module Epuber
112
117
  else
113
118
  targets.map { |target_name| book.target_named(target_name) }
114
119
  end
115
- )
120
+ end
116
121
  end
117
122
 
118
123
  def verify_all_targets_exists!
@@ -121,9 +126,9 @@ module Epuber
121
126
  end
122
127
 
123
128
  def validate_dir(path)
124
- if ::File.directory?(path)
125
- path
126
- end
129
+ return unless ::File.directory?(path)
130
+
131
+ path
127
132
  end
128
133
 
129
134
  def find_calibre_app
@@ -141,7 +146,9 @@ module Epuber
141
146
  ::File.join(find_calibre_app, 'Contents/MacOS/ebook-convert')
142
147
  elsif OS.linux?
143
148
  script_path = '/usr/bin/ebook-convert'
144
- UI.error!("Can't find ebook-convert in folder /usr/bin to convert EPUB to MOBI.") unless ::File.executable?(script_path)
149
+ unless ::File.executable?(script_path)
150
+ UI.error!("Can't find ebook-convert in folder /usr/bin to convert EPUB to MOBI.")
151
+ end
145
152
  script_path
146
153
  else
147
154
  UI.error!('Unsupported OS to convert EPUB to MOBI.')
@@ -151,6 +158,14 @@ module Epuber
151
158
  def convert_epub_to_mobi(epub_path, mobi_path)
152
159
  system(find_calibre_convert_file, epub_path, mobi_path)
153
160
  end
161
+
162
+ def cleanup_build_folders
163
+ targets.each do |target|
164
+ build_path = Epuber::Config.instance.release_build_path(target)
165
+
166
+ FileUtils.remove_dir(build_path, true) if ::File.directory?(build_path)
167
+ end
168
+ end
154
169
  end
155
170
  end
156
171
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../command'
4
+ require_relative '../from_file/from_file_executor'
5
+
6
+ module Epuber
7
+ class Command
8
+ class FromFile < Command
9
+ self.summary = 'Initialize current folder to use it as Epuber project from existing EPUB file'
10
+ self.arguments = [
11
+ CLAide::Argument.new('EPUB_FILE', true),
12
+ ]
13
+
14
+ # @param [CLAide::ARGV] argv
15
+ #
16
+ def initialize(argv)
17
+ @filepath = argv.arguments!.first
18
+
19
+ super(argv)
20
+ end
21
+
22
+ def validate!
23
+ super
24
+
25
+ help! 'You must specify path to existing EPUB file' if @filepath.nil?
26
+ help! "File #{@filepath} doesn't exists" unless File.exist?(@filepath)
27
+
28
+ existing = Dir.glob('*.bookspec')
29
+ help! "Can't reinit this folder, #{existing.first} already exists." unless existing.empty?
30
+ end
31
+
32
+ def run
33
+ super
34
+
35
+ FromFileExecutor.new(@filepath).run
36
+ end
37
+ end
38
+ end
39
+ end
@@ -11,10 +11,10 @@ module Epuber
11
11
  class Init < Command
12
12
  self.summary = 'Initialize current folder to use it as Epuber project'
13
13
  self.arguments = [
14
- CLAide::Argument.new('PROJECT_NAME', false, true),
14
+ CLAide::Argument.new('PROJECT_NAME', false),
15
15
  ]
16
16
 
17
- # @param argv [CLAide::ARGV]
17
+ # @param [CLAide::ARGV] argv
18
18
  #
19
19
  def initialize(argv)
20
20
  @book_name = argv.arguments!.first
@@ -23,6 +23,8 @@ module Epuber
23
23
  end
24
24
 
25
25
  def validate!
26
+ super
27
+
26
28
  help! 'You must specify identifier-like name of the book as first argument' if @book_name.nil?
27
29
 
28
30
  existing = Dir.glob('*.bookspec')
@@ -50,14 +52,14 @@ module Epuber
50
52
  private
51
53
 
52
54
  def print_good_bye(book_id)
53
- puts <<-END.ansi.green
54
- Project initialized, please review #{book_id}.bookspec file, remove comments and fill some attributes like book title.
55
- END
55
+ UI.puts <<~TEXT.ansi.green
56
+ Project initialized, please review #{book_id}.bookspec file, remove comments and fill some attributes like book title.
57
+ TEXT
56
58
  end
57
59
 
58
60
  # Creates <book-id>.bookspec file from template
59
61
  #
60
- # @param book_id [String]
62
+ # @param [String] book_id
61
63
  #
62
64
  # @return [void]
63
65
  #
@@ -71,21 +73,23 @@ END
71
73
 
72
74
  # Creates <book-id>.sublime-project
73
75
  #
74
- # @param book_id [String]
76
+ # @param [String] book_id
75
77
  #
76
78
  # @return [void]
77
79
  #
78
80
  def write_sublime_project(book_id)
79
- text = '{
80
- "folders": [
81
- {
82
- "follow_symlinks": true,
83
- "path": ".",
84
- "folder_exclude_patterns": [".epuber"],
85
- "file_exclude_patterns": ["*.epub"]
86
- }
87
- ]
88
- }'
81
+ text = <<~JSON
82
+ {
83
+ "folders": [
84
+ {
85
+ "follow_symlinks": true,
86
+ "path": ".",
87
+ "folder_exclude_patterns": [".epuber"],
88
+ "file_exclude_patterns": ["*.epub"]
89
+ }
90
+ ]
91
+ }
92
+ JSON
89
93
 
90
94
  write("#{book_id}.sublime-project", text)
91
95
  end
@@ -95,7 +99,7 @@ END
95
99
  # @return [void]
96
100
  #
97
101
  def write_gitignore
98
- append_new_lines('.gitignore', <<~END
102
+ append_new_lines('.gitignore', <<~TEXT)
99
103
  # This is generated with `epuber init`
100
104
  *.epub
101
105
  *.mobi
@@ -104,29 +108,27 @@ END
104
108
  .epuber/release_build/
105
109
  .epuber/build_cache/
106
110
  .epuber/metadata/
107
- END
108
- )
111
+ TEXT
109
112
  end
110
113
 
111
114
  def write_default_style(book_id)
112
- write("styles/#{book_id}.styl", <<~END
115
+ write("styles/#{book_id}.styl", <<~STYLUS)
113
116
  // This is generated with `epuber init` script.
114
- END
115
- )
117
+ STYLUS
116
118
  end
117
119
 
118
- # @param string [String] text to file
119
- # @param file_path [String] path to file
120
+ # @param [String] string text to file
121
+ # @param [String] file_path path to file
120
122
  #
121
123
  # @return [void]
122
124
  #
123
125
  def write(file_path, string)
124
126
  File.write(file_path, string)
125
- puts " #{'create'.ansi.green} #{file_path}"
127
+ UI.puts " #{'create'.ansi.green} #{file_path}"
126
128
  end
127
129
 
128
- # @param string [String] text to file
129
- # @param file_path [String] path to file
130
+ # @param [String] string text to file
131
+ # @param [String] file_path path to file
130
132
  #
131
133
  # @return [void]
132
134
  #
@@ -146,7 +148,7 @@ END
146
148
  existing_content << "\n"
147
149
 
148
150
  File.write(file_path, existing_content)
149
- puts " #{'update'.ansi.green} #{file_path}"
151
+ UI.puts " #{'update'.ansi.green} #{file_path}"
150
152
  end
151
153
 
152
154
  # @param [String] dir_path path to dir
@@ -155,10 +157,10 @@ END
155
157
  #
156
158
  def create_folder(dir_path)
157
159
  FileUtils.mkdir_p(dir_path)
158
- puts " #{'create'.ansi.green} #{dir_path}/"
160
+ UI.puts " #{'create'.ansi.green} #{dir_path}/"
159
161
  end
160
162
 
161
- # @param text [String]
163
+ # @param [String] text
162
164
  #
163
165
  # @return [String] returned text without new line
164
166
  #
@@ -167,7 +169,7 @@ END
167
169
  result = $stdin.gets.chomp
168
170
 
169
171
  while result.empty?
170
- puts 'Value cannot be empty, please fill it!'.ansi.red
172
+ UI.puts 'Value cannot be empty, please fill it!'.ansi.red
171
173
  print text
172
174
  result = $stdin.gets.chomp
173
175
  end
@@ -13,11 +13,11 @@ module Epuber
13
13
 
14
14
  def self.options
15
15
  [
16
- ['--open', 'Opens the web page in default web browser, working only on OS X'],
16
+ ['--open', 'Opens the web page in default web browser, working only on OS X'],
17
17
  ].concat(super)
18
18
  end
19
19
 
20
- # @param args [CLAide::ARGV]
20
+ # @param [CLAide::ARGV] args
21
21
  #
22
22
  def initialize(args)
23
23
  super
@@ -51,7 +51,7 @@ module Epuber
51
51
  if @open_web_browser
52
52
  system "open #{uri}"
53
53
  else
54
- puts 'Web browser can be automatically opened by adding --open flag, see --help'
54
+ UI.puts 'Web browser can be automatically opened by adding --open flag, see --help'
55
55
  end
56
56
  end
57
57
  end
@@ -16,26 +16,24 @@ module Epuber
16
16
  require_relative 'command/compile'
17
17
  require_relative 'command/init'
18
18
  require_relative 'command/server'
19
+ require_relative 'command/from_file'
19
20
 
20
21
  self.abstract_command = true
21
22
  self.command = 'epuber'
22
23
  self.version = VERSION
23
24
  self.description = 'Epuber, easy creating and maintaining e-book.'
24
- self.plugin_prefixes = plugin_prefixes + %w(epuber)
25
+ self.plugin_prefixes = plugin_prefixes + %w[epuber]
25
26
 
26
27
  def self.run(argv = [])
27
- begin
28
- UI.current_command = self
29
- super
30
- UI.current_command = nil
31
-
32
- rescue Interrupt
33
- UI.error('[!] Cancelled')
34
- rescue => e
35
- UI.error!(e)
36
-
37
- UI.current_command = nil
38
- end
28
+ UI.current_command = self
29
+ super
30
+ UI.current_command = nil
31
+ rescue Interrupt
32
+ UI.error('[!] Cancelled')
33
+ rescue StandardError => e
34
+ UI.error!(e)
35
+
36
+ UI.current_command = nil
39
37
  end
40
38
 
41
39
  def validate!
@@ -70,18 +68,18 @@ module Epuber
70
68
  end
71
69
 
72
70
  def write_lockfile
73
- unless Epuber::Config.test?
74
- Epuber::Config.instance.save_lockfile
75
- end
71
+ return if Epuber::Config.test?
72
+
73
+ Epuber::Config.instance.save_lockfile
76
74
  end
77
75
 
78
76
  def pre_build_checks
79
77
  Config.instance.warn_for_outdated_versions!
80
78
 
81
- if !Config.instance.same_version_as_last_run? && File.exist?(Config.instance.working_path)
82
- UI.warning('Using different version of Epuber or Bade, removing all build caches')
83
- Config.instance.remove_build_caches
84
- end
79
+ return unless !Config.instance.same_version_as_last_run? && File.exist?(Config.instance.working_path)
80
+
81
+ UI.warning('Using different version of Epuber or Bade, removing all build caches')
82
+ Config.instance.remove_build_caches
85
83
  end
86
84
  end
87
85
  end
@@ -32,15 +32,13 @@ module Epuber
32
32
  #
33
33
  def plugins
34
34
  @plugins ||= @target.plugins.map do |path|
35
- begin
36
- plugin = Plugin.new(path)
37
- plugin.files.each do |file|
38
- file_resolver.add_file(file)
39
- end
40
- plugin
41
- rescue LoadError
42
- UI.error "Can't find plugin at path #{path}"
35
+ plugin = Plugin.new(path)
36
+ plugin.files.each do |file|
37
+ file_resolver.add_file(file)
43
38
  end
39
+ plugin
40
+ rescue LoadError
41
+ UI.error "Can't find plugin at path #{path}"
44
42
  end.compact
45
43
  end
46
44
 
@@ -100,6 +98,10 @@ module Epuber
100
98
  use_cache
101
99
  end
102
100
 
101
+ def release_build?
102
+ release_build
103
+ end
104
+
103
105
  def initialize(book, target)
104
106
  @book = book
105
107
  @target = target
@@ -7,7 +7,6 @@ module Epuber
7
7
  require_relative 'file_stat'
8
8
 
9
9
  class FileDatabase
10
-
11
10
  # @return [Hash<String, Epuber::Compiler::FileStat>]
12
11
  #
13
12
  attr_accessor :all_files
@@ -66,7 +65,7 @@ module Epuber
66
65
  end
67
66
 
68
67
  def update_all_metadata
69
- @all_files.each do |file_path, _|
68
+ @all_files.each_key do |file_path|
70
69
  update_metadata(file_path)
71
70
  end
72
71
  end
@@ -99,7 +98,7 @@ module Epuber
99
98
  to_remove = @all_files.keys - file_paths
100
99
  to_remove.each { |key| @all_files.delete(key) }
101
100
 
102
- @all_files.each do |_, stat|
101
+ @all_files.each_value do |stat|
103
102
  _cleanup_stat_dependency_list(file_paths, stat)
104
103
  end
105
104
  end
@@ -130,7 +129,6 @@ module Epuber
130
129
  _cleanup_stat_dependency_list(file_paths, next_stat)
131
130
  end
132
131
  end
133
-
134
132
  end
135
133
  end
136
134
  end
@@ -16,6 +16,8 @@ module Epuber
16
16
  # @param [String] context_path
17
17
  #
18
18
  def initialize(pattern, context_path)
19
+ super()
20
+
19
21
  @pattern = pattern
20
22
  @context_path = context_path
21
23
  end
@@ -48,6 +50,8 @@ module Epuber
48
50
  # @param [Array<String>] files_paths list of founded files
49
51
  #
50
52
  def initialize(pattern, groups, context_path, files_paths)
53
+ super()
54
+
51
55
  @pattern = pattern
52
56
  @groups = Array(groups)
53
57
  @context_path = context_path
@@ -61,16 +65,16 @@ module Epuber
61
65
  end
62
66
  end
63
67
 
64
- BINARY_EXTENSIONS = %w(.png .jpeg .jpg .otf .ttf)
65
- STATIC_EXTENSIONS = BINARY_EXTENSIONS + %w(.css .js)
68
+ BINARY_EXTENSIONS = %w[.png .jpeg .jpg .otf .ttf].freeze
69
+ STATIC_EXTENSIONS = BINARY_EXTENSIONS + %w[.css .js]
66
70
 
67
71
  GROUP_EXTENSIONS = {
68
- text: %w(.xhtml .html .bade),
69
- image: %w(.png .jpg .jpeg),
70
- font: %w(.otf .ttf),
71
- style: %w(.css .styl),
72
- script: %w(.js .coffee),
73
- }
72
+ text: %w[.xhtml .html .bade],
73
+ image: %w[.png .jpg .jpeg],
74
+ font: %w[.otf .ttf],
75
+ style: %w[.css .styl],
76
+ script: %w[.js .coffee],
77
+ }.freeze
74
78
 
75
79
  EXTENSIONS_RENAME = {
76
80
  '.styl' => '.css',
@@ -78,10 +82,9 @@ module Epuber
78
82
  '.bade' => '.xhtml',
79
83
 
80
84
  '.coffee' => '.js',
81
- }
85
+ }.freeze
82
86
 
83
87
  class Abstract
84
-
85
88
  # @return [String] path where should look for source files
86
89
  #
87
90
  attr_reader :source_path
@@ -99,7 +102,6 @@ module Epuber
99
102
  @ignored_patterns = []
100
103
  end
101
104
 
102
-
103
105
  # @param [Array<Symbol> | Symbol] groups
104
106
  #
105
107
  def assert_one_file(files, pattern: nil, groups: nil, context_path: nil)
@@ -113,7 +115,8 @@ module Epuber
113
115
  # When it founds too many (more than two) it will raise MultipleFilesFoundError
114
116
  #
115
117
  # @param [String] pattern pattern of the desired files
116
- # @param [Array<Symbol> | Symbol] groups list of group names, nil or empty array for all groups, for valid values see GROUP_EXTENSIONS
118
+ # @param [Array<Symbol> | Symbol] groups list of group names, nil or empty array for all groups, for valid
119
+ # values see GROUP_EXTENSIONS
117
120
  # @param [String] context_path path for root of searching, it is also defines start folder of relative path
118
121
  #
119
122
  # @return [Array<String>] list of founded files
@@ -128,7 +131,8 @@ module Epuber
128
131
  # #source_path and after that it tries to search recursively from #source_path.
129
132
  #
130
133
  # @param [String] pattern pattern of the desired files
131
- # @param [Array<Symbol>] groups list of group names, nil or empty array for all groups, for valid values see GROUP_EXTENSIONS
134
+ # @param [Array<Symbol>] groups list of group names, nil or empty array for all groups, for valid values see
135
+ # GROUP_EXTENSIONS
132
136
  # @param [String] context_path path for root of searching, it is also defines start folder of relative path
133
137
  #
134
138
  # @return [Array<String>] list of founded files
@@ -141,7 +145,9 @@ module Epuber
141
145
  searching_path = ::File.expand_path(context_path, @source_path_abs)
142
146
 
143
147
  unless searching_path.start_with?(@source_path_abs)
144
- raise "You can't search from folder (#{searching_path}) that is not sub folder of the source_path (#{source_path}) expanded to (#{@source_path_abs})."
148
+ raise <<~ERROR
149
+ You can't search from folder (#{searching_path}) that is not sub folder of the source_path (#{source_path}) expanded to (#{@source_path_abs}).
150
+ ERROR
145
151
  end
146
152
 
147
153
  files = __find_files(pattern, groups, searching_path)
@@ -152,7 +158,7 @@ module Epuber
152
158
  end
153
159
 
154
160
  if files.empty? && search_everywhere && !pattern.start_with?('**')
155
- files = __find_files('**/' + pattern, groups, @source_path_abs, searching_path || @source_path_abs)
161
+ files = __find_files("**/#{pattern}", groups, @source_path_abs, searching_path || @source_path_abs)
156
162
  end
157
163
 
158
164
  files
@@ -161,13 +167,14 @@ module Epuber
161
167
  # Looks for all files from #source_path recursively
162
168
  #
163
169
  # @param [String] pattern pattern of the desired files
164
- # @param [Array<Symbol>] groups list of group names, nil or empty array for all groups, for valid values see GROUP_EXTENSIONS
170
+ # @param [Array<Symbol>] groups list of group names, nil or empty array for all groups, for valid values see
171
+ # GROUP_EXTENSIONS
165
172
  # @param [String] context_path path for root of searching, it is also defines start folder of relative path
166
173
  #
167
174
  # @return [Array<String>] list of founded files
168
175
  #
169
176
  def find_all(pattern, groups: nil, context_path: @source_path_abs)
170
- __find_files('**/' + pattern, groups, context_path)
177
+ __find_files("**/#{pattern}", groups, context_path)
171
178
  end
172
179
 
173
180
  # @param [Array<String>] paths list of file paths
@@ -187,7 +194,7 @@ module Epuber
187
194
  end.flatten
188
195
 
189
196
  paths.select do |file_path|
190
- valid_extensions.include?(::File.extname(file_path))
197
+ valid_extensions.include?(::File.extname(file_path).downcase)
191
198
  end
192
199
  end
193
200
  end
@@ -209,7 +216,8 @@ module Epuber
209
216
  # Looks for files at given context path, if there is no file, it will try again with pattern for any extension
210
217
  #
211
218
  # @param [String] pattern pattern of the desired files
212
- # @param [Array<Symbol>] groups list of group names, nil or empty array for all groups, for valid values see GROUP_EXTENSIONS
219
+ # @param [Array<Symbol>] groups list of group names, nil or empty array for all groups, for valid values see
220
+ # GROUP_EXTENSIONS
213
221
  # @param [String] context_path path for root of searching, it is also defines start folder of relative path
214
222
  # @param [String] orig_context_path original context path, wo it will work nicely with iterative searching
215
223
  #
@@ -222,23 +230,25 @@ module Epuber
222
230
  files = __core_find_files(pattern, groups, context_path, orig_context_path)
223
231
 
224
232
  # try to find files with any extension
225
- files = __core_find_files(pattern + '.*', groups, context_path, orig_context_path) if files.empty?
233
+ files = __core_find_files("#{pattern}.*", groups, context_path, orig_context_path) if files.empty?
226
234
 
227
235
  files
228
236
  end
229
237
 
230
- # Core method for finding files, it only search for files, filter by input groups and map the final paths to pretty relative paths from context_path
238
+ # Core method for finding files, it only search for files, filter by input groups and map the final paths to
239
+ # pretty relative paths from context_path
231
240
  #
232
241
  # @param [String] pattern pattern of the desired files
233
- # @param [Array<Symbol>] groups list of group names, nil or empty array for all groups, for valid values see GROUP_EXTENSIONS
242
+ # @param [Array<Symbol>] groups list of group names, nil or empty array for all groups, for valid values see
243
+ # GROUP_EXTENSIONS
234
244
  # @param [String] context_path path for root of searching, it is also defines start folder of relative path
235
245
  # @param [String] orig_context_path original context path, wo it will work nicely with iterative searching
236
246
  #
237
247
  # @return [Array<String>] list of founded files
238
248
  #
239
249
  def __core_find_files(pattern, groups, context_path, orig_context_path = context_path)
240
- context_path = __core_file?(context_path) ? File.dirname(context_path) : context_path
241
- orig_context_path = __core_file?(orig_context_path) ? File.dirname(orig_context_path) : orig_context_path
250
+ context_path = File.dirname(context_path) if __core_file?(context_path)
251
+ orig_context_path = File.dirname(orig_context_path) if __core_file?(orig_context_path)
242
252
 
243
253
  full_pattern = File.expand_path(pattern, context_path)
244
254
  file_paths = __core_find_files_from_pattern(full_pattern).map(&:unicode_normalize)
@@ -258,11 +268,11 @@ module Epuber
258
268
  self.class.relative_paths_from(file_paths, orig_context_path)
259
269
  end
260
270
 
261
- def __core_find_files_from_pattern(pattern)
271
+ def __core_find_files_from_pattern(_pattern)
262
272
  raise 'Implement this in subclass'
263
273
  end
264
274
 
265
- def __core_file?(path)
275
+ def __core_file?(_path)
266
276
  raise 'Implement this in subclass'
267
277
  end
268
278
  end