mimetype-xml 0.1.1 → 1.1.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
  SHA1:
3
- metadata.gz: 6d88671579c45d04a9f5b5eae1333d14c8df36e5
4
- data.tar.gz: 364c3297701a763bcad5f0b87fc0d1ac242aef03
3
+ metadata.gz: 04043c93603866f7953f9fc63575f06dbf497131
4
+ data.tar.gz: 82188810733908e58cf7cd50051aa8480761844e
5
5
  SHA512:
6
- metadata.gz: 188301516e411be40125d0bd7185d3633e05c46ddb141ed77a960c9d9a1ab5ffa1cdaa878e06679c2382b51089a25de77cd4dbc30cbf4eef86984b8b8b875b07
7
- data.tar.gz: 50038c7257382cf7aed66324e3d49e22770d9cd88c1f15debe1e5cfb42f167208e95d889fe35bd3f535945c2cfa34dc69816a8ea5685a846cfb0ed7d94bade19
6
+ metadata.gz: 6084b5f83c3d3f667a76078b6e64ec1206c51e075744b48c661b3817792b523689a09e30011e8ca3197108510d4d52050aad9a23629112a8daa647e5c07eda4a
7
+ data.tar.gz: 2167b16e30ad942c9295f6e476740ebf3c21a0036eb93ef5f35adb56f59cc462f880ef6d78ce9d268487ecd019841706339435c27c35875e41f5f9609b70e934
@@ -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 => 0, :minor => 1, :tiny => 1 }
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
@@ -0,0 +1,18 @@
1
+ module MimetypeXML
2
+ class ParseTOML
3
+
4
+ def initialize toml_string
5
+ @toml = toml_string
6
+ end
7
+
8
+ def to_h
9
+ TOML::Parser.new(@toml).parsed
10
+ end
11
+
12
+ def self.parse string
13
+ parser = self.new string
14
+ parser.to_h
15
+ end
16
+ end
17
+ end
18
+
@@ -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: 0.1.1
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