epuber 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 603ed8123e624a5756c2e66ef8e2561f76f60b7c2ba386040e62cc1bace24c52
4
- data.tar.gz: bc9fd362419d5fd05444398221f8d0e9bbfa4675273635b893c3a160a3330048
3
+ metadata.gz: e7acd7fcb74da144389521daa83a8fb681015b82d5cc8a1da35de6058d26fec3
4
+ data.tar.gz: d61a1ac243fc871f6bf2a114d24936b123ed5a28666057b76fb3fc0da6109265
5
5
  SHA512:
6
- metadata.gz: 5f04920782210213a3c5fb8e424d8b22e3a316d83187dae331057759d4bda04b61b81c163215086fa4cad4abd736de37db43c428b56b51472f8d93c9bbadb5e3
7
- data.tar.gz: a683e1930bf8c58b8b9f64529ac55c50dbe0895af5acbb4d4820cf1f5d0559349e87cd3f02c0bf7a90c77b04d4a9a07acee849cb867f8f81a658484e74514e35
6
+ metadata.gz: 85a24b75e370556e3a028e0c118b4f4bc36395c4140472ddfde4be4c46fd95549fecf3d18c28d72bf545b13f9850d82394ea509b8a97d9e3f1078f678d28647e
7
+ data.tar.gz: 62483b8f634b572336cbede86754baa95d3627ac0c69d4f47e44ca701e57b201b53e0b9568a22fd7d4c3ebee6f345c1b132012be303f0ab73ed4db26d332deb3
@@ -40,8 +40,6 @@ module Epuber
40
40
  # @return [String]
41
41
  #
42
42
  def process_css(content, compilation_context)
43
- file_resolver = compilation_context.file_resolver
44
-
45
43
  parser = UI.print_step_processing_time('css parsing') do
46
44
  parser = CssParser::Parser.new
47
45
  parser.load_string!(content)
@@ -69,27 +67,10 @@ module Epuber
69
67
  next if path.start_with?('data:') || path.start_with?('http://') || path.start_with?('https://')
70
68
 
71
69
  resource_group = DECLARATION_TO_FILE_GROUP_MAP[property]
72
- dirname = File.dirname(destination_path)
73
-
74
- begin
75
- new_path = file_resolver.dest_finder.find_file(path, groups: resource_group, context_path: dirname)
76
- rescue FileFinders::FileNotFoundError, FileFinders::MultipleFilesFoundError
77
- new_path = XHTMLProcessor.resolved_link_to_file(path,
78
- resource_group,
79
- dirname,
80
- file_resolver.source_finder).to_s
81
- pkg_abs_path = File.expand_path(new_path, dirname).unicode_normalize
82
- pkg_new_path = Pathname.new(pkg_abs_path)
83
- .relative_path_from(Pathname.new(file_resolver.source_path))
84
- .to_s
85
-
86
- file_class = FileResolver.file_class_for(File.extname(new_path))
87
- file = file_class.new(pkg_new_path)
88
- file.path_type = :manifest
89
- file_resolver.add_file(file)
90
- end
91
-
92
- new_url = FileResolver.renamed_file_with_path(new_path)
70
+ new_url = SourceFile.resolve_relative_file(destination_path,
71
+ path,
72
+ compilation_context.file_resolver,
73
+ group: resource_group)
93
74
  content = content.gsub(value, "url(#{quote}#{new_url}#{quote})")
94
75
  end
95
76
  end
@@ -112,6 +112,37 @@ module Epuber
112
112
  MSG
113
113
  end
114
114
  end
115
+
116
+ def self.resolve_relative_file(destination_path, pattern, file_resolver, group: nil)
117
+ dirname = File.dirname(destination_path)
118
+
119
+ begin
120
+ new_path = file_resolver.dest_finder.find_file(pattern, groups: group, context_path: dirname)
121
+ rescue FileFinders::FileNotFoundError, FileFinders::MultipleFilesFoundError
122
+ begin
123
+ new_path = XHTMLProcessor.resolved_link_to_file(pattern,
124
+ group,
125
+ dirname,
126
+ file_resolver.source_finder).to_s
127
+ rescue XHTMLProcessor::UnparseableLinkError,
128
+ FileFinders::FileNotFoundError,
129
+ FileFinders::MultipleFilesFoundError => e
130
+ UI.warning(e.to_s, location: img)
131
+ end
132
+ end
133
+
134
+ pkg_abs_path = File.expand_path(new_path, dirname).unicode_normalize
135
+ pkg_new_path = Pathname.new(pkg_abs_path)
136
+ .relative_path_from(Pathname.new(file_resolver.source_path))
137
+ .to_s
138
+
139
+ file_class = FileResolver.file_class_for(File.extname(new_path))
140
+ file = file_class.new(pkg_new_path)
141
+ file.path_type = :manifest
142
+ file_resolver.add_file(file)
143
+
144
+ FileResolver.renamed_file_with_path(new_path)
145
+ end
115
146
  end
116
147
  end
117
148
  end
@@ -342,34 +342,15 @@ module Epuber
342
342
  end
343
343
 
344
344
  def self.resolve_resources_in(node_css_query, attribute_name, resource_group, xhtml_doc, file_path, file_resolver)
345
- dirname = File.dirname(file_path)
346
-
347
345
  xhtml_doc.css(node_css_query).each do |img|
348
346
  path = img[attribute_name]
349
347
  next if path.nil?
350
348
 
351
- begin
352
- new_path = file_resolver.dest_finder.find_file(path, groups: resource_group, context_path: dirname)
353
- rescue UnparseableLinkError, FileFinders::FileNotFoundError, FileFinders::MultipleFilesFoundError
354
- begin
355
- new_path = resolved_link_to_file(path, resource_group, dirname, file_resolver.source_finder).to_s
356
- pkg_abs_path = File.expand_path(new_path, dirname).unicode_normalize
357
- pkg_new_path = Pathname.new(pkg_abs_path).relative_path_from(Pathname.new(file_resolver.source_path)).to_s
358
-
359
- file_class = FileResolver.file_class_for(File.extname(new_path))
360
- file = file_class.new(pkg_new_path)
361
- file.path_type = :manifest
362
- file_resolver.add_file(file)
363
-
364
- new_path = FileResolver.renamed_file_with_path(new_path)
365
- rescue UnparseableLinkError, FileFinders::FileNotFoundError, FileFinders::MultipleFilesFoundError => e
366
- UI.warning(e.to_s, location: img)
367
-
368
- next
369
- end
370
- end
371
-
372
- img[attribute_name] = new_path
349
+ new_path = Compiler::FileTypes::SourceFile.resolve_relative_file(file_path,
350
+ path,
351
+ file_resolver,
352
+ group: resource_group)
353
+ img[attribute_name] = new_path if new_path
373
354
  end
374
355
  end
375
356
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Epuber
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.1'
5
5
 
6
6
  HOME_URL = 'https://github.com/epuber-io/epuber'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epuber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Kříž