epuber 0.9.0 → 0.9.2

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: b94e989f6c4461b34fe954d6d60a7b09c573f1c53281bcab8ce0014b2311a47f
4
+ data.tar.gz: 12c22458537652c184dd1fdc054faa2cbb26d161cfbd6ed4ec45fe2ecd49c430
5
5
  SHA512:
6
- metadata.gz: 5f04920782210213a3c5fb8e424d8b22e3a316d83187dae331057759d4bda04b61b81c163215086fa4cad4abd736de37db43c428b56b51472f8d93c9bbadb5e3
7
- data.tar.gz: a683e1930bf8c58b8b9f64529ac55c50dbe0895af5acbb4d4820cf1f5d0559349e87cd3f02c0bf7a90c77b04d4a9a07acee849cb867f8f81a658484e74514e35
6
+ metadata.gz: ee04850fd4bcc3d2ce2ed97f4c9f14356b7dfffa25bac2decb4cf079ed8eeefc797cacb5ca891930d7da97c910d714bc1074e259b3afc4452b3af74b5753adbc
7
+ data.tar.gz: da0f454494fbe9964f71f0a3ca74aca9c586c4132846b6980c1f58f3499b0f7183164c31bda542698ff6ac1db1e7daa9b8077be83114c5f0bf10b6de1a062892
@@ -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
@@ -218,6 +218,8 @@ module Epuber
218
218
  end
219
219
  end
220
220
 
221
+ return uri if path == '#'
222
+
221
223
  # skip uri with scheme (links to web pages)
222
224
  return uri unless uri.scheme.nil?
223
225
 
@@ -342,34 +344,15 @@ module Epuber
342
344
  end
343
345
 
344
346
  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
347
  xhtml_doc.css(node_css_query).each do |img|
348
348
  path = img[attribute_name]
349
349
  next if path.nil?
350
350
 
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
351
+ new_path = Compiler::FileTypes::SourceFile.resolve_relative_file(file_path,
352
+ path,
353
+ file_resolver,
354
+ group: resource_group)
355
+ img[attribute_name] = new_path if new_path
373
356
  end
374
357
  end
375
358
 
@@ -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.2'
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.9.0
4
+ version: 0.9.2
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-12-19 00:00:00.000000000 Z
11
+ date: 2024-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -594,7 +594,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
594
594
  - !ruby/object:Gem::Version
595
595
  version: '0'
596
596
  requirements: []
597
- rubygems_version: 3.4.22
597
+ rubygems_version: 3.5.6
598
598
  signing_key:
599
599
  specification_version: 4
600
600
  summary: Epuber is simple tool to compile and pack source files into EPUB format.