Last active
August 29, 2015 14:08
-
-
Save madrobby/8722dda972d2daecee59 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 'json' | |
FILENAME = "../app/helpers/icon_helper.rb" | |
JAVASCRIPT_HELPER = "../public/js/icons/icons.js" | |
puts "Generating helper #{FILENAME}" | |
File.open(FILENAME, 'w') do |helper| | |
helper.write "module IconHelper\n\n" | |
Dir.glob(File.join("..","public","images","icons","*.svg")).each do |icon| | |
svg = File.read(icon).delete("\n").delete("\r").delete("\t") | |
name = icon.split('/').last.tr('-','_').gsub(/\.svg$/,'') | |
puts "#{name}: #{svg.size} bytes" | |
helper.write " def icon_#{name}\n" | |
helper.write " '#{svg}'\n" | |
helper.write " end\n\n" | |
end | |
helper.write "end" | |
end | |
puts "Generating JavaScript helper" | |
File.open(JAVASCRIPT_HELPER, 'w') do |helper| | |
Dir.glob(File.join("..","public","images","icons","*.svg")).each do |icon| | |
svg = File.read(icon).delete("\n").delete("\r").delete("\t") | |
name = icon.split('/').last.tr('-','_').gsub(/\.svg$/,'') | |
# we only need a few specific icons in JavaScript, so skip those we don't want | |
next unless name =~ /^cursor/ || name =~ /^arrow_right/ | |
puts "(JavaScript) #{name}: #{svg.size} bytes" | |
helper.write "window.__icon_#{name} = #{svg.to_json};\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment