mimetype-xml 0.1.1 → 1.1.1
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 +4 -4
- data/lib/mimetype_xml.rb +4 -1
- data/lib/mimetype_xml/generate.rb +18 -0
- data/lib/mimetype_xml/install.rb +26 -0
- data/lib/mimetype_xml/toml.rb +18 -0
- data/lib/mimetype_xml/xml.rb +75 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04043c93603866f7953f9fc63575f06dbf497131
|
4
|
+
data.tar.gz: 82188810733908e58cf7cd50051aa8480761844e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6084b5f83c3d3f667a76078b6e64ec1206c51e075744b48c661b3817792b523689a09e30011e8ca3197108510d4d52050aad9a23629112a8daa647e5c07eda4a
|
7
|
+
data.tar.gz: 2167b16e30ad942c9295f6e476740ebf3c21a0036eb93ef5f35adb56f59cc462f880ef6d78ce9d268487ecd019841706339435c27c35875e41f5f9609b70e934
|
data/lib/mimetype_xml.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'toml'
|
2
|
+
require 'pp'
|
3
|
+
require_relative 'mimetype_xml/install'
|
1
4
|
require_relative 'mimetype_xml/toml'
|
2
5
|
require_relative 'mimetype_xml/xml'
|
3
6
|
require_relative 'mimetype_xml/generate'
|
4
7
|
|
5
8
|
module MimetypeXML
|
6
|
-
VERSIONS = { :major =>
|
9
|
+
VERSIONS = { :major => 1, :minor => 1, :tiny => 1 }
|
7
10
|
|
8
11
|
def self.version *args
|
9
12
|
VERSIONS.flatten.select.with_index { |val, i| i.odd? }.join '.'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MimetypeXML
|
2
|
+
class Generate
|
3
|
+
|
4
|
+
def initialize toml
|
5
|
+
@toml_hash = ParseTOML.parse toml
|
6
|
+
end
|
7
|
+
|
8
|
+
def parser; @toml_hash; end
|
9
|
+
|
10
|
+
def self.toml_file file:, xml_dir:, icon_pack:
|
11
|
+
toml = File.read File.expand_path(file)
|
12
|
+
hash = self.new(toml).parser
|
13
|
+
|
14
|
+
XML.new :hash => hash, :dir => File.expand_path(xml_dir), :icon_pack => icon_pack
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module MimetypeXML
|
2
|
+
class Installer
|
3
|
+
|
4
|
+
def initialize icon_pack:, icons_info:, xml_dir:
|
5
|
+
@icon_pack = icon_pack
|
6
|
+
@icons = icons_info
|
7
|
+
@xml_dir = xml_dir
|
8
|
+
end
|
9
|
+
|
10
|
+
def install
|
11
|
+
### XDG-ICON-RESOURCES DOES NOT SUPPORT SVGs ###
|
12
|
+
### BUT SPEC DOES, BUG: ###
|
13
|
+
### https://bugs.freedesktop.org/show_bug.cgi?id=91759 ###
|
14
|
+
#@icons.each do |title, details|
|
15
|
+
# icon = "#{File.expand_path @icon_pack}/#{details[:icon]}"
|
16
|
+
# %x{ xdg-icon-resource install --context mimetypes --size #{details[:size]} #{icon} #{title} }
|
17
|
+
#end
|
18
|
+
|
19
|
+
Dir[@xml_dir + '/*.xml'].each do |file|
|
20
|
+
%x{ xdg-mime install #{file} }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/mimetype_xml/toml.rb
CHANGED
data/lib/mimetype_xml/xml.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
module MimetypeXML
|
2
|
+
class XML
|
3
|
+
|
4
|
+
def initialize hash:, dir:, icon_pack:
|
5
|
+
@hash = hash
|
6
|
+
@dir = dir
|
7
|
+
|
8
|
+
@icon_pack = icon_pack
|
9
|
+
@icons = Array.new
|
10
|
+
@icons_info = Hash.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def files_hash
|
14
|
+
xml_files = Hash.new
|
15
|
+
|
16
|
+
@hash.each do |heading, sub_hash|
|
17
|
+
@type = sub_hash['type']
|
18
|
+
@pattern = String.new
|
19
|
+
sub_hash['pattern'].each { |ext| @pattern << "<glob pattern=\"#{ext}\" />\n" }
|
20
|
+
|
21
|
+
@comment = sub_hash['comment']
|
22
|
+
|
23
|
+
@icons << sub_hash['icon']
|
24
|
+
@icons_info[heading] = {
|
25
|
+
:icon => sub_hash['icon'],
|
26
|
+
:size => sub_hash['size']
|
27
|
+
}
|
28
|
+
|
29
|
+
# Optional
|
30
|
+
@comment_lang = String.new
|
31
|
+
if sub_hash.key? 'comment_lang' then
|
32
|
+
sub_hash['comment_lang'].each do |lang|
|
33
|
+
code, desc = lang
|
34
|
+
@comment_lang << "<comment xml:lang=\"#{code}\">#{desc}</comment>\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Make file hash
|
39
|
+
title = sub_hash.key?('xml_file') ? sub_hash['xml_file'] : "#{heading}.xml"
|
40
|
+
xml_files[title] = document
|
41
|
+
end
|
42
|
+
|
43
|
+
xml_files
|
44
|
+
end
|
45
|
+
|
46
|
+
def write_files
|
47
|
+
files = files_hash
|
48
|
+
|
49
|
+
files.each do |file, contents|
|
50
|
+
File.open("#{@dir}/#{file}", 'w') { |f| f.write(contents) }
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# Files associated with installer for them
|
55
|
+
Installer.new(
|
56
|
+
:icon_pack => @icon_pack,
|
57
|
+
:icons_info => @icons_info,
|
58
|
+
:xml_dir => @dir
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def document
|
63
|
+
xml = <<-XML
|
64
|
+
<?xml version="1.0"?>
|
65
|
+
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
|
66
|
+
<mime-type type="#{@type}">
|
67
|
+
<comment>#{@comment}</comment>
|
68
|
+
#{@comment_lang}
|
69
|
+
#{@pattern}
|
70
|
+
</mime-type>
|
71
|
+
</mime-info>
|
72
|
+
XML
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mimetype-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Demonstrandum
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- bin/mimetype-xml
|
38
38
|
- lib/mimetype_xml.rb
|
39
39
|
- lib/mimetype_xml/generate.rb
|
40
|
+
- lib/mimetype_xml/install.rb
|
40
41
|
- lib/mimetype_xml/toml.rb
|
41
42
|
- lib/mimetype_xml/xml.rb
|
42
43
|
homepage: https://github.com/Demonstrandum/mimetype-xml
|