Font-Awesome/extractor/extract.rb
2012-05-04 12:02:10 -06:00

44 lines
1.3 KiB
Ruby

icons = {}
glyphs = {}
sass_lines = File.open('../sass/font-awesome.sass').readlines
svg_lines = File.open('../font/fontawesome-webfont.svg').readlines
index = 0
while index < sass_lines.length
line = sass_lines[index]
if line.start_with? '.icon'
colon_index = line.index ':'
icon_name = line[1 .. colon_index - 1]
index += 1
line = sass_lines[index]
icon_code = line[13 .. 16]
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
icon_glyph = line[start_index .. line.length - 6]
glyphs[icon_code] = icon_glyph
#puts "#{icon_code}: '#{icon_glyph}'"
end
index += 1
end
# 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) }