epuber 0.3.7 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fe25adb1dac4b43021c459313ae9f98e1c4ac0e
4
- data.tar.gz: 7148acde09046a3b21e3c16fc5ad28cbc9964574
3
+ metadata.gz: aeafa25a224668d8a2921e09e38b2cccf3ef5304
4
+ data.tar.gz: ace5b8bd2c4433cc0f3e1332bf908643c8d2e64d
5
5
  SHA512:
6
- metadata.gz: b6164ca50abb2a098b27ab32dc71b0476f2bfbf297f07a5b63a2853f6a9d40659677c950f01ed93c74cc97125147e01a1de8d36f9d509bf2083e567069b99757
7
- data.tar.gz: 9a9d083ce64cfd677c471adf6138f3a4a9f6a784a69f981228df89ef1ac1a8fa40f63da7332bd21b43980ec49d97cf0793e6c77ff4478e1ef560ee01a7b55d98
6
+ metadata.gz: 8ff682097d6ca7ff9a2a92a98d9c47aacfaf7ab9666a3ab2257a5f0cd86c99fa8670e806f9e88a93419a4b624306039e383df9a2a791458db57e57960ff40f53
7
+ data.tar.gz: e66dda4964520cd025f27c9f3140186df77d9d68a08b14313bb1ffc778125764eabe9ac0d496e4810b2af87ea8ea0f6dc0ae377a6362077e8bc9926aec49c6ed
data/epuber.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.summary = 'Epuber is simple tool to compile and pack source files into EPUB format.'
15
15
  spec.homepage = 'https://github.com/epuber-io/epuber'
16
16
  spec.license = 'MIT'
17
+ spec.required_ruby_version = '>= 2.0'
17
18
 
18
19
  spec.files = Dir['bin/**/*'] + Dir['lib/**/*'] + %w(epuber.gemspec Gemfile LICENSE.txt README.md)
19
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -82,6 +82,8 @@ module Epuber
82
82
  convert_epub_to_mobi(archive_path, ::File.basename(archive_path, '.epub') + '.mobi') if target.create_mobi
83
83
  end
84
84
  end
85
+
86
+ write_lockfile
85
87
  end
86
88
 
87
89
  private
@@ -44,14 +44,19 @@ module Epuber
44
44
 
45
45
  help!('Not existing target') if target.nil?
46
46
 
47
- Epuber::Server.run!(book, target, verbose: verbose?) do |uri|
48
- if OS.osx?
49
- if @open_web_browser
50
- system "open #{uri}"
51
- else
52
- puts 'Web browser can be automatically opened by adding --open flag, see --help'
47
+ begin
48
+ Epuber::Server.run!(book, target, verbose: verbose?) do |uri|
49
+ if OS.osx?
50
+ if @open_web_browser
51
+ system "open #{uri}"
52
+ else
53
+ puts 'Web browser can be automatically opened by adding --open flag, see --help'
54
+ end
53
55
  end
54
56
  end
57
+ rescue Interrupt
58
+ write_lockfile
59
+ raise
55
60
  end
56
61
  end
57
62
  end
@@ -28,6 +28,8 @@ module Epuber
28
28
  super
29
29
  UI.current_command = nil
30
30
 
31
+ rescue Interrupt
32
+ UI.error('[!] Cancelled')
31
33
  rescue => e
32
34
  UI.error!(e)
33
35
 
@@ -61,5 +63,11 @@ module Epuber
61
63
  raise PlainInformative, "No `.bookspec' found in the project directory." if bookspec_files.empty?
62
64
  raise PlainInformative, "Multiple `.bookspec' found in current directory" if bookspec_files.count > 1
63
65
  end
66
+
67
+ def write_lockfile
68
+ unless Epuber::Config.test?
69
+ Epuber::Config.instance.save_lockfile
70
+ end
71
+ end
64
72
  end
65
73
  end
@@ -43,20 +43,20 @@ module Epuber
43
43
  attr_reader :context_path
44
44
 
45
45
  # @param [String] pattern original pattern for searching
46
- # @param [Symbol] groups list of groups
46
+ # @param [Array<Symbol> | Symbol] groups list of groups
47
47
  # @param [String] context_path context path of current searching
48
48
  # @param [Array<String>] files_paths list of founded files
49
49
  #
50
50
  def initialize(pattern, groups, context_path, files_paths)
51
51
  @pattern = pattern
52
- @groups = groups
52
+ @groups = Array(groups)
53
53
  @context_path = context_path
54
54
  @files_paths = files_paths
55
55
  end
56
56
 
57
57
  def to_s
58
58
  str = "Found too many files for pattern `#{pattern}` from context path #{context_path}"
59
- str += ", file groups #{groups.map(:inspect)}" unless groups.nil?
59
+ str += ", file groups #{groups.map(&:inspect)}" if !groups.nil? && !groups.empty?
60
60
  str + ", founded files #{files_paths}"
61
61
  end
62
62
  end
@@ -98,6 +98,8 @@ module Epuber
98
98
  end
99
99
 
100
100
 
101
+ # @param [Array<Symbol> | Symbol] groups
102
+ #
101
103
  def assert_one_file(files, pattern: nil, groups: nil, context_path: nil)
102
104
  raise FileNotFoundError.new(pattern, context_path) if files.empty?
103
105
  raise MultipleFilesFoundError.new(pattern, groups, context_path, files) if files.count >= 2
@@ -109,7 +111,7 @@ module Epuber
109
111
  # When it founds too many (more than two) it will raise MultipleFilesFoundError
110
112
  #
111
113
  # @param [String] pattern pattern of the desired files
112
- # @param [Symbol] groups list of group names, nil or empty array for all groups, for valid values see GROUP_EXTENSIONS
114
+ # @param [Array<Symbol> | Symbol] groups list of group names, nil or empty array for all groups, for valid values see GROUP_EXTENSIONS
113
115
  # @param [String] context_path path for root of searching, it is also defines start folder of relative path
114
116
  #
115
117
  # @return [Array<String>] list of founded files
@@ -86,7 +86,9 @@ module Epuber
86
86
 
87
87
  def __core_find_files_from_pattern(pattern)
88
88
  parts = self.class.path_parts(pattern)
89
- find_recurser(root, parts).flatten.map do |item|
89
+ found_entries = find_recurser(root, parts).flatten
90
+ file_entries = found_entries.reject { |entry| entry.is_a?(DirEntry) }
91
+ file_entries.map do |item|
90
92
  item.absolute_path
91
93
  end
92
94
  end
@@ -112,6 +114,8 @@ module Epuber
112
114
  return [] unless dir.respond_to? :[]
113
115
 
114
116
  pattern, *parts = parts
117
+ return [] if pattern.nil?
118
+
115
119
  matches = case pattern
116
120
  when '**'
117
121
  case parts
@@ -125,20 +129,12 @@ module Epuber
125
129
  end.flatten.uniq
126
130
  when []
127
131
  parts = [] # end recursion
128
- dir.entries.flatten.uniq
132
+ dir.entries.values.flatten.uniq
129
133
  else
130
134
  directories_under(dir)
131
135
  end
132
136
  else
133
- regex_body = pattern.gsub('.', '\.')
134
- .gsub('?', '.')
135
- .gsub('*', '.*')
136
- .gsub('(', '\(')
137
- .gsub(')', '\)')
138
- .gsub(/\{(.*?)\}/) do
139
- "(#{Regexp.last_match[1].gsub(',', '|')})"
140
- end
141
- .gsub(/\A\./, '(?!\.).')
137
+ regex_body = pattern_to_regex(pattern)
142
138
  dir.entries.reject { |k, _v| /\A#{regex_body}\Z/ !~ k }.values
143
139
  end
144
140
 
@@ -151,12 +147,24 @@ module Epuber
151
147
 
152
148
  # @param [DirEntry] dir
153
149
  #
154
- # @return [Hash<String, DirEntry>]
150
+ # @return [Array<DirEntry>]
155
151
  #
156
152
  def directories_under(dir)
157
153
  children = dir.entries.values.select { |f| f.is_a?(DirEntry) }
158
154
  (Array(dir) + children + children.map { |c| directories_under(c) }).flatten.uniq
159
155
  end
156
+
157
+ def pattern_to_regex(pattern)
158
+ pattern.gsub('.', '\.')
159
+ .gsub('?', '.')
160
+ .gsub('*', '.*')
161
+ .gsub('(', '\(')
162
+ .gsub(')', '\)')
163
+ .gsub(/\{(.*?)\}/) do
164
+ "(#{Regexp.last_match[1].gsub(',', '|')})"
165
+ end
166
+ .gsub(/\A\./, '(?!\.).')
167
+ end
160
168
  end
161
169
  end
162
170
  end
@@ -70,6 +70,7 @@ module Epuber
70
70
 
71
71
  XHTMLProcessor.add_viewport(xhtml_doc, target.default_viewport) unless target.default_viewport.nil?
72
72
  self.properties << :scripted if XHTMLProcessor.using_javascript?(xhtml_doc)
73
+ self.properties << :remote_resources if XHTMLProcessor.using_remote_resources?(xhtml_doc)
73
74
 
74
75
  XHTMLProcessor.resolve_links(xhtml_doc, destination_path, file_resolver.dest_finder)
75
76
  XHTMLProcessor.resolve_images(xhtml_doc, destination_path, file_resolver)
@@ -58,6 +58,7 @@ module Epuber
58
58
  cover_image: 'cover-image',
59
59
  navigation: 'nav',
60
60
  scripted: 'scripted',
61
+ remote_resources: 'remote-resources',
61
62
  }.freeze
62
63
 
63
64
  OPF_UNIQUE_ID = 'bookid'
@@ -213,6 +213,15 @@ module Epuber
213
213
  !xhtml_doc.at_css('script').nil?
214
214
  end
215
215
 
216
+ def self.using_remote_resources?(xhtml_doc)
217
+ regexp = %r{^[^:/?#]+://.*}
218
+
219
+ result = false
220
+ result ||= xhtml_doc.css('[src]').any? { |node| node['src'] =~ regexp }
221
+ result ||= xhtml_doc.css('link[href]').any? { |node| node['href'] =~ regexp }
222
+ result
223
+ end
224
+
216
225
  # @param [Nokogiri::XML::Document] xhtml_doc
217
226
  # @param [String] file_path path of referring file
218
227
  # @param [FileResolver] file_resolver
data/lib/epuber/config.rb CHANGED
@@ -124,11 +124,3 @@ module Epuber
124
124
  self.test = false
125
125
  end
126
126
  end
127
-
128
- # HACK: this should be done with nicer way
129
- #
130
- at_exit do
131
- unless Epuber::Config.test?
132
- Epuber::Config.instance.save_lockfile
133
- end
134
- end
@@ -36,7 +36,7 @@ module Epuber
36
36
  $stdout.puts unless @last_processing_file_line.nil?
37
37
 
38
38
  $stdout.puts(_format_message(:error, message, location: location))
39
- _print_backtrace(location.try(:backtrace_locations) || message.try(:backtrace_locations) || caller_locations, location: location) if current_command.verbose?
39
+ _print_backtrace(location.try(:backtrace_locations) || message.try(:backtrace_locations) || caller_locations, location: location) if current_command && current_command.verbose?
40
40
  end
41
41
 
42
42
  # @param [String] message message of the error
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Epuber
3
- VERSION = '0.3.7'
3
+ VERSION = '0.3.9'
4
4
  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.3.7
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Kříž
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-31 00:00:00.000000000 Z
11
+ date: 2015-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -541,7 +541,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
541
541
  requirements:
542
542
  - - ">="
543
543
  - !ruby/object:Gem::Version
544
- version: '0'
544
+ version: '2.0'
545
545
  required_rubygems_version: !ruby/object:Gem::Requirement
546
546
  requirements:
547
547
  - - ">="