Created
April 3, 2010 12:31
-
-
Save tvandervossen/354440 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require "base64" | |
if ARGV[0].nil? | |
puts "Usage: #{$0} <name.css>" | |
exit 1 | |
end | |
lines = File.readlines(ARGV[0]) | |
font = {} | |
lines.each do |line| | |
case line | |
when "@font-face {\n" | |
font = {} | |
when /font-family: "(.*)";/ | |
font[:family] = $1 | |
when /src: url\(data:font\/(otf);base64,(.*)\);/ | |
font[:format] = $1 | |
font[:base64] = $2 | |
when /font-style: (.*);/ | |
font[:style] = $1 | |
when /font-weight: (.*);/ | |
font[:weight] = $1 | |
when "}\n" | |
name = "#{font[:family][0...-2]}-#{font[:style]}-#{font[:weight]}-#{font[:family][-1..-1]}.#{font[:format]}" | |
File.open(name, 'w') do |f| | |
f.write(Base64.decode64(font[:base64])) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment