Font-Awesome/extractor/extract.rb

44 lines
1.3 KiB
Ruby
Raw Normal View History

2012-05-05 01:00:57 +08:00
icons = {}
2012-05-05 01:33:54 +08:00
glyphs = {}
2012-05-05 01:00:57 +08:00
2012-05-05 02:02:10 +08:00
sass_lines = File.open('../sass/font-awesome.sass').readlines
svg_lines = File.open('../font/fontawesome-webfont.svg').readlines
2012-05-05 01:00:57 +08:00
index = 0
2012-05-05 01:33:54 +08:00
while index < sass_lines.length
line = sass_lines[index]
2012-05-05 01:00:57 +08:00
if line.start_with? '.icon'
colon_index = line.index ':'
icon_name = line[1 .. colon_index - 1]
index += 1
2012-05-05 01:33:54 +08:00
line = sass_lines[index]
2012-05-05 01:00:57 +08:00
icon_code = line[13 .. 16]
2012-05-05 01:33:54 +08:00
icons[icon_name] = icon_code
#puts "#{icon_name}: #{icon_code}"
end
index += 1
end
index = 0
while index < svg_lines.length
line = svg_lines[index]
d_index = line.index 'd="'
if line.start_with? '<glyph unicode="&#x' and d_index != nil
icon_code = line[19.. 22]
start_index = d_index + 3
2012-05-05 02:02:10 +08:00
icon_glyph = line[start_index .. line.length - 6]
2012-05-05 01:33:54 +08:00
glyphs[icon_code] = icon_glyph
2012-05-05 02:02:10 +08:00
#puts "#{icon_code}: '#{icon_glyph}'"
2012-05-05 01:00:57 +08:00
end
index += 1
2012-05-05 01:33:54 +08:00
end
2012-05-05 02:02:10 +08:00
# icons.each_pair do |icon_name, icon_code|
# puts "#{icon_name}: #{glyphs[icon_code]}"
# end
requested_icon = ARGV[0]
requested_glyph = glyphs[icons[requested_icon]]
blank_svg_content = File.open('empty.svg').read
output_svg = blank_svg_content.sub '###INSERTGLYPH###', requested_glyph
File.open("#{requested_icon}.svg", 'w') {|out_svg| out_svg.write(output_svg) }