Skip to content

Instantly share code, notes, and snippets.

@andreasisaak
Created November 1, 2015 18:02
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 andreasisaak/8d972f7100b4f7308ee2 to your computer and use it in GitHub Desktop.
Save andreasisaak/8d972f7100b4f7308ee2 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
// Functions we need
@function str-replace($string, $search, $replace: "") {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
@function contains($list, $values...) {
@each $value in $values {
@if type-of(index($list, $value)) != "number" {
@return false;
}
}
@return true;
}
@function font-src($font-family, $file-path, $file-formats, $version) {
$src: ();
$replaced-font-family: str_replace($font-family, " ", "-");
$formats-map: (
eot: "#{$file-path}.eot?#iefix&v=#{$version}" format("embedded-opentype"),
woff2: "#{$file-path}.woff2?v=#{$version}" format("woff2"),
woff: "#{$file-path}.woff?v=#{$version}" format("woff"),
ttf: "#{$file-path}.ttf?v=#{$version}" format("truetype"),
otf: "#{$file-path}.ttf?v=#{$version}" format("opentype"),
svg: "#{$file-path}.svg?v=#{$version}##{$replaced-font-family}" format("svg")
);
@each $key, $values in $formats-map {
@if contains($file-formats, $key) {
$file-path: nth($values, 1);
$font-format: nth($values, 2);
$src: append($src, url($file-path) $font-format, comma);
}
}
@return $src;
}
@mixin font-face($family, $path, $weight: null, $style: null, $file-formats: eot woff2 woff ttf svg, $version: uN2iAj0, $local...) {
$src: null;
@font-face {
font-family: quote($family);
font-style: $style;
font-weight: $weight;
src: url("#{$path}.eot?v=#{$version}");
src: font-src($family, $path, $file-formats, $version);
}
}
@include font-face("Din", "testpath/din-regular", normal);
@include font-face("Din", "testpath/din-bold", bold);
@font-face {
font-family: "Din";
font-weight: normal;
src: url("testpath/din-regular.eot?v=uN2iAj0");
src: url("testpath/din-regular.eot?#iefix&v=uN2iAj0") format("embedded-opentype"), url("testpath/din-regular.woff2?v=uN2iAj0") format("woff2"), url("testpath/din-regular.woff?v=uN2iAj0") format("woff"), url("testpath/din-regular.ttf?v=uN2iAj0") format("truetype"), url("testpath/din-regular.svg?v=uN2iAj0#Din") format("svg");
}
@font-face {
font-family: "Din";
font-weight: bold;
src: url("testpath/din-bold.eot?v=uN2iAj0");
src: url("testpath/din-bold.eot?#iefix&v=uN2iAj0") format("embedded-opentype"), url("testpath/din-bold.woff2?v=uN2iAj0") format("woff2"), url("testpath/din-bold.woff?v=uN2iAj0") format("woff"), url("testpath/din-bold.ttf?v=uN2iAj0") format("truetype"), url("testpath/din-bold.svg?v=uN2iAj0#Din") format("svg");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment