Skip to content

Instantly share code, notes, and snippets.

@plasticine
Created May 31, 2013 04:18
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 plasticine/5682917 to your computer and use it in GitHub Desktop.
Save plasticine/5682917 to your computer and use it in GitHub Desktop.
<% @grouped_glyphs = @data[:glyphs].map{|name|
group = /^[\w-]*_([\d]+px)$/.match(name)
[(group) ? ["_size_#{group.captures.first}".to_sym, group.captures.first] : [nil], name]
}
@sizing_groups = @grouped_glyphs.map{|i| i.first }.uniq.reject{|m| m.first == nil }
-%>
@font-face {
font-family: "<%= @opts[:font_name] %>";
src: url("<%= @data[:file_name] %>.eot");
src: url("<%= @data[:file_name] %>.eot?#iefix") format("embedded-opentype"),
url("<%= @data[:file_name] %>.woff") format("woff"),
url("<%= @data[:file_name] %>.ttf") format("truetype"),
url("<%= @data[:file_name] %>.svg#<%= @opts[:font_name] %>") format("svg");
font-weight: normal;
font-style: normal;
}
<%# Write grouped sizing helper functions -%>
@function _size_default() { @return 22px; }
<% @sizing_groups.each do |group, size| -%>
@function <%= group %>() { @return <%= size %>; }
<% end -%>
<%# Write out unicode character code and size helper functions for each glyph -%>
<% @grouped_glyphs.each_with_index do |icon, index| -%>
@function _<%= @opts[:css_prefix] + icon.last %>_glyph() { @return "\<%= (61696+index).to_s(16) %>"; }
@function _<%= @opts[:css_prefix] + icon.last %>_size() { @return <%= icon[0].first ? "#{icon[0].first}()" : "_size_default()" %>; }
<% end -%>
@mixin ico-base {
font-family: "<%= @opts[:font_name] %>";
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
-webkit-font-smoothing: antialiased;
display: inline-block;
text-decoration: inherit;
font-size: _size_default();
}
<% @grouped_glyphs.each_with_index do |icon, index| -%>
@mixin <%= @opts[:css_prefix] + icon.last %> {
font-size: <%= "_#{@opts[:css_prefix]}#{icon.last}_size()" %>;
content: <%= "_#{@opts[:css_prefix]}#{icon.last}_glyph()" %>;
}
<% end -%>
<%# Base styles for icons -%>
<%= @data[:glyphs].map{|name| ".#{@opts[:css_prefix] + name}"}.join(",\n") -%> {
&:before {
@include ico-base;
}
}
<% @grouped_glyphs.each_with_index do |icon, index| -%>
.<%= @opts[:css_prefix] + icon.last %>:before { @include <%= "#{@opts[:css_prefix]}#{icon.last}" %>; }
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment