Skip to content

Instantly share code, notes, and snippets.

@davidtheclark
Last active July 6, 2017 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidtheclark/6005027 to your computer and use it in GitHub Desktop.
Save davidtheclark/6005027 to your computer and use it in GitHub Desktop.
A template for grunt-webfont that outputs a SCSS "icon" mixin. Also, adds a rule to hide text within a `<span>` inside the designated icon element -- for text describing the icon. (You know: accessibility, SEO, etc.) Below, `output.scss` is some example output, `scss-mixin-icon-template.css` is the template.
@font-face {
font-family:"icon";
src:url("../fonts/icon.eot");
src:url("../fonts/icon.eot?#iefix") format("embedded-opentype"),
url("../fonts/icon.woff") format("woff"),
url("../fonts/icon.ttf") format("truetype"),
url("../fonts/icon.svg?#webfont") format("svg");
font-weight:normal;
font-style:normal;
}
%icon-base {
&:before {
font-family: "icon";
-webkit-font-smoothing: antialiased;
}
b {
// hide text
height: 0;
display: block;
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
}
@mixin icon($icon) {
@extend %icon-base;
@if ($icon == "twitter") {
&:before {
content:"\f100";
}
}
}
@font-face {
font-family:"<%= fontBaseName %>";<% if (eot) { %>
src:<%= fontSrc1 %>;<% }%>
src:<%= fontSrc2 %>;
font-weight:normal;
font-style:normal;
}
%icon-base {
&:before {
font-family: "<%= fontBaseName %>";
-webkit-font-smoothing: antialiased;
}
b {
// hide text
height: 0;
display: block;
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
}
@mixin <%= fontBaseName %>($icon) {
@extend %icon-base;
<% for (var glyphIdx = 0; glyphIdx < glyphs.length; glyphIdx++) { %><% if (glyphIdx === 0) { %>@if<% } else { %>@else if<% } %> ($icon == "<%= glyphs[glyphIdx] %>") {
&:before {
content:"\<%= (61696+glyphIdx).toString(16) %>";
}
}
<% } %>
}
@gibbitz
Copy link

gibbitz commented Oct 22, 2015

whyfore are your extensions backwards? NM. Looks like the plugin only likes .css files. RTFM.

@gibbitz
Copy link

gibbitz commented Oct 22, 2015

<% if (eot) { %>
should be
<% if ("eot") { %>
For those who are looking here and get
Fatal error: Error while rendering template (.....): eot is not defined

@julkue
Copy link

julkue commented Jul 6, 2017

eot is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment