iftoc 0.1.6 → 0.1.7

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/iftoc +31 -4
  3. data/lib/iftoc/version.rb +1 -1
  4. data/lib/iftoc.rb +25 -5
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2981d9a06306f97891bda4a514202be3eae19331
4
- data.tar.gz: 6f5ee1705b18b4e0ab35ff53813ad15d89f13394
3
+ metadata.gz: cf822a6256da6acb77f5c84bdd8d53efda8c4764
4
+ data.tar.gz: 17b36c9e573710759363801a786ed1863d82f9d8
5
5
  SHA512:
6
- metadata.gz: f3227ed4d8a0cce8c7207062d2d64de244378b4bc9ea446d247ce3c9d17136fa8a7fb1388b2baaeb43e9e4752dc73a9a53229a91c12ce494f2bd4d00d63e3499
7
- data.tar.gz: 9c3fde7b223c6d56cc0d4084f41d59c67383934dccdcfb152b0ce1ca0f1513713cad184855877c8c40aa8c41fafee4145782184d915a673e0dcbdcb22b62ca70
6
+ metadata.gz: e0120563af7e446f4ab222df09366277809cf0840a56389b7bef0ec19fb47e76379134bf6affc3b9d099e0cd8546731bace142b28768c3484e434afcc180f6ac
7
+ data.tar.gz: c1f06e040331580b74c0dddbe0970d74d78fd6bccd32620d7b929a5666515ae3433edeb37c7ecdf7c822133bdfebdbf234481bfd7cd962a285ea58c03e95eb60
data/bin/iftoc CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
+ require 'rexml/document'
4
5
  require 'iftoc'
5
6
 
6
7
  $inpath = ARGV[0]
7
8
  $outpath = Dir::pwd
8
9
 
9
10
  $helpString = <<-EOB
10
- Usage: iftoc <cssfile> [--out <outpath>]
11
+ Usage: iftoc <svgfile | cssfile> [--out <outpath>]
11
12
  EOB
12
13
 
13
14
  def paramCheck
@@ -36,17 +37,43 @@ def paramCheck
36
37
 
37
38
  end
38
39
 
40
+ def parseSVGFontName(xmlContext)
41
+ fontelement = xmlContext.root.elements["defs"].elements["font"]
42
+ return fontelement.elements["font-face"].attributes["font-family"]
43
+ end
44
+
45
+ def parseSVGIconFont(xmlContext)
46
+ iconfonts = Hash.new
47
+ fontelement = xmlContext.root.elements["defs"].elements["font"]
48
+ fontelement.get_elements("glyph").each { |font|
49
+ name = font.attributes["glyph-name"]
50
+ unicode = font.attributes["unicode"].to_s.delete("#x;")
51
+ if unicode.length == 4 then
52
+ iconfonts[name] = unicode
53
+ end
54
+ }
55
+ return iconfonts
56
+ end
57
+
39
58
  # main
40
59
  paramCheck
41
60
 
42
61
  io = File.open($inpath)
43
- iconfontName = Iftoc.parseFontName(io)
44
- iconfontMap = Iftoc.parseIconFont(io)
62
+ doc = REXML::Document.new(io.read.to_s.delete("&"))
63
+ if doc.root then
64
+ iconfontName = parseSVGFontName(doc)
65
+ iconfontMap = parseSVGIconFont(doc)
66
+ else
67
+ io.close
68
+ io = File.open($inpath)
69
+ iconfontName = Iftoc.parseCSSFontName(io)
70
+ iconfontMap = Iftoc.parseCSSIconFont(io)
71
+ end
45
72
  io.close
46
73
 
47
74
  # exception
48
75
  if !iconfontName || iconfontMap.count < 1 then
49
- print("parse error!")
76
+ print("parse error! ")
50
77
  exit(1)
51
78
  end
52
79
 
data/lib/iftoc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Iftoc
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/iftoc.rb CHANGED
@@ -5,8 +5,26 @@ module Iftoc
5
5
 
6
6
  $fontNameRegexpStr = /font-family: "(.*)"/
7
7
  $iconRegexpStr = /.icon-(.*):before { content: "\\(.*)"/
8
-
9
- def parseFontName(file)
8
+
9
+ def parseSVGFontName(xmlContext)
10
+ fontelement = xmlContext.root.elements["defs"].elements["font"]
11
+ return fontelement.elements["font-face"].attributes["font-family"]
12
+ end
13
+
14
+ def parseSVGIconFont(xmlContext)
15
+ iconfonts = Hash.new
16
+ fontelement = xmlContext.root.elements["defs"].elements["font"]
17
+ fontelement.get_elements("glyph").each { |font|
18
+ name = font.attributes["glyph-name"]
19
+ unicode = font.attributes["unicode"].to_s.delete("#x;")
20
+ if unicode.length == 4 then
21
+ iconfonts[name] = unicode
22
+ end
23
+ }
24
+ return iconfonts
25
+ end
26
+
27
+ def parseCSSFontName(file)
10
28
  file.each_line do |line|
11
29
  line.chomp!
12
30
  $fontNameRegexpStr =~ line
@@ -18,7 +36,7 @@ module Iftoc
18
36
  return nil
19
37
  end
20
38
 
21
- def parseIconFont(file)
39
+ def parseCSSIconFont(file)
22
40
  iconfonts = Hash.new
23
41
  file.each_line do |line|
24
42
  line.chomp!
@@ -113,8 +131,10 @@ module Iftoc
113
131
  hio.close
114
132
  end
115
133
 
116
- module_function :parseFontName
117
- module_function :parseIconFont
134
+ module_function :parseSVGFontName
135
+ module_function :parseSVGIconFont
136
+ module_function :parseCSSFontName
137
+ module_function :parseCSSIconFont
118
138
  module_function :generateHFile
119
139
  module_function :generateMFile
120
140
  module_function :putStringToFile
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iftoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - 庞海礁