Created
December 9, 2013 15:54
-
-
Save zetter/7874395 to your computer and use it in GitHub Desktop.
Parse the icon file from icomoon and print out a ruby hash of character names to characters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# run the file with the dev.svg from icomoon (not the plain svg) | |
# ruby parse_icons_from_icomoon.rb /path/to/iconfont.dev.svg | |
require 'nokogiri' | |
file = ARGV[0] | |
svg = File.open(file) | |
document = Nokogiri::XML(svg) | |
glyphs = document.css('glyph') | |
name_and_chars = glyphs.map do |glyph| | |
name = glyph['data-tags'].to_s.downcase.gsub(/[- \_]/, '_').gsub(/[^a-z0-9\_]/, '') | |
char = glyph['unicode'].to_s | |
[name, char] | |
end | |
name_and_chars = name_and_chars.reject {|name, char| name == '' || char == ''} | |
name_and_chars = name_and_chars.sort | |
string = name_and_chars.map{|name, char| | |
" #{name}: '#{char}'" | |
}.join(",\n") | |
puts "{\n#{string}\n}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment