Skip to content

Commit 541b6aa

Browse files
committed
move from mime-types to marcel: metanorma/metanorma#473
1 parent 4b8b6eb commit 541b6aa

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

html2doc.gemspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ Gem::Specification.new do |spec|
2929
spec.add_dependency "base64"
3030
spec.add_dependency "htmlentities", "~> 4.3.4"
3131
spec.add_dependency "lutaml-model", "~> 0.7.0"
32+
spec.add_dependency "marcel"
3233
spec.add_dependency "metanorma-utils", ">= 1.9.0"
33-
spec.add_dependency "mime-types"
3434
spec.add_dependency "nokogiri", "~> 1.18.3"
3535
spec.add_dependency "plane1converter", "~> 0.0.1"
3636
spec.add_dependency "plurimath", "~> 0.9.0"
3737
spec.add_dependency "thread_safe"
3838
spec.add_dependency "uuidtools"
39-
spec.add_dependency "unitsml"
4039
spec.add_dependency "vectory", "~> 0.8"
4140

4241
spec.add_development_dependency "debug"

lib/html2doc/mime.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "uuidtools"
22
require "base64"
3-
require "mime/types"
3+
require "marcel"
44
require "fileutils"
55
require "vectory"
66

@@ -21,7 +21,7 @@ def mime_preamble(boundary, filename, result)
2121
end
2222

2323
def mime_attachment(boundary, _filename, item, dir)
24-
content_type = mime_type(item)
24+
content_type = mime_type(File.join(dir, item))
2525
text_mode = %w[text application].any? { |p| content_type.start_with? p }
2626

2727
path = File.join(dir, item)
@@ -41,9 +41,9 @@ def mime_attachment(boundary, _filename, item, dir)
4141
end
4242

4343
def mime_type(item)
44-
types = MIME::Types.type_for(item)
45-
type = types ? types.first.to_s : 'text/plain; charset="utf-8"'
46-
type = %(#{type} charset="utf-8") if /^text/.match(type) && types
44+
type = Marcel::MimeType.for Pathname.new(item) ||
45+
'text/plain; charset="utf-8"'
46+
type = %(#{type} charset="utf-8") if /^text/.match?(type)
4747
type
4848
end
4949

@@ -59,7 +59,6 @@ def mime_package(result, filename, dir)
5959
Dir.foreach(dir) do |item|
6060
next if item == "." || item == ".." || /^\./.match(item) ||
6161
item == "filelist.xml"
62-
6362
mhtml += mime_attachment(boundary, "#{filename}.htm", item, dir)
6463
end
6564
mhtml += "--#{boundary}--"

0 commit comments

Comments
 (0)