Skip to content

Instantly share code, notes, and snippets.

@kdiogenes
Created January 29, 2015 18:11
Show Gist options
  • Save kdiogenes/233fecc5db6b73012ada to your computer and use it in GitHub Desktop.
Save kdiogenes/233fecc5db6b73012ada to your computer and use it in GitHub Desktop.
fontcustom: patch to make symbolic links be understood as alias
diff --git a/lib/fontcustom/generator/font.rb b/lib/fontcustom/generator/font.rb
index d9ffd21..402516f 100644
--- a/lib/fontcustom/generator/font.rb
+++ b/lib/fontcustom/generator/font.rb
@@ -50,6 +50,7 @@ module Fontcustom
files = Dir.glob File.join(@options[:input][:vectors], "*.svg")
glyphs = {}
files.each do |file|
+ next if File.symlink?(file)
name = File.basename file, ".svg"
name = name.strip.gsub(/\W/, "-")
glyphs[name.to_sym] = { :source => file }
@@ -58,6 +59,17 @@ module Fontcustom
end
end
+ files.each do |file|
+ next unless File.symlink?(file)
+ linked_name = File.readlink(file)
+ linked_name = File.basename linked_name, ".svg"
+ linked_name = linked_name.strip.gsub(/\W/, "-")
+ glyphs[linked_name.to_sym][:aliases] ||= []
+ alias_name = File.basename file, ".svg"
+ alias_name = alias_name.strip.gsub(/\W/, "-")
+ glyphs[linked_name.to_sym][:aliases] << alias_name
+ end
+
# Dir.glob returns a different order depending on ruby
# version/platform, so we have to sort it first
glyphs = Hash[glyphs.sort_by { |key, val| key.to_s }]
diff --git a/lib/fontcustom/generator/template.rb b/lib/fontcustom/generator/template.rb
index 0e39c17..4c31035 100644
--- a/lib/fontcustom/generator/template.rb
+++ b/lib/fontcustom/generator/template.rb
@@ -183,7 +183,11 @@ module Fontcustom
def glyph_selectors
output = @glyphs.map do |name, value|
- @options[:css_selector].sub("{{glyph}}", name.to_s) + ":before"
+ aliases = []
+ aliases = @glyphs[name][:aliases].map do |alias_name|
+ @options[:css_selector].sub("{{glyph}}", alias_name.to_s) + ":before,\n"
+ end if @glyphs[name][:aliases]
+ aliases.join + @options[:css_selector].sub("{{glyph}}", name.to_s) + ":before"
end
output.join ",\n"
end
@@ -205,7 +209,11 @@ module Fontcustom
def glyphs
output = @glyphs.map do |name, value|
- %Q|#{@options[:css_selector].sub('{{glyph}}', name.to_s)}:before { content: "\\#{value[:codepoint].to_s(16)}"; }|
+ aliases = []
+ aliases = @glyphs[name][:aliases].map do |alias_name|
+ %Q|#{@options[:css_selector].sub('{{glyph}}', alias_name.to_s)}:before, |
+ end if @glyphs[name][:aliases]
+ aliases.join + %Q|#{@options[:css_selector].sub('{{glyph}}', name.to_s)}:before { content: "\\#{value[:codepoint].to_s(16)}"; }|
end
output.join "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment