Skip to content

Instantly share code, notes, and snippets.

@nashfive
Last active August 29, 2015 14:01
Show Gist options
  • Save nashfive/7dd41b0fc3a9eaaf79a7 to your computer and use it in GitHub Desktop.
Save nashfive/7dd41b0fc3a9eaaf79a7 to your computer and use it in GitHub Desktop.
Generates an Objective-C header file based on the selection.json file generated along by an iconmoon.io font package
#!/usr/local/bin/ruby
require 'rubygems'
require 'json'
fail("Input file not specified") unless ARGV.length == 1
input = ARGV.first
fail("Input file #{input} not found") unless File.exists?(input)
result = JSON.parse (File.read input), :symbolize_names => true
icons = result[:icons]
defines = ""
puts "Processing #{icons.length} icons..."
icons.each do |elt|
props = elt[:properties]
name = "ICON-#{props[:name].upcase}"
# Will produce a define line with the following pattern: #define ICON-<name> "<unicode>"
defines << %Q<#define #{name} "\\u#{props[:code].to_s(16)}"\n>
end
fontFamily = result[:preferences][:fontPref][:metadata][:fontFamily]
File.open("IconHeader.h", "w") do |file|
file << %Q<static NSString *const kIconFamilyName = @"#{fontFamily}";\n\n>
file << defines
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment