Skip to content

Instantly share code, notes, and snippets.

@tvandervossen
Created April 3, 2010 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvandervossen/354440 to your computer and use it in GitHub Desktop.
Save tvandervossen/354440 to your computer and use it in GitHub Desktop.
#!/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