_font-source-declaration.scss 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Used for creating the source string for fonts using @font-face
  2. // Reference: http://goo.gl/Ru1bKP
  3. @function font-url-prefixer($asset-pipeline) {
  4. @if $asset-pipeline == true {
  5. @return font-url;
  6. } @else {
  7. @return url;
  8. }
  9. }
  10. @function font-source-declaration(
  11. $font-family,
  12. $file-path,
  13. $asset-pipeline,
  14. $file-formats,
  15. $font-url) {
  16. $src: null;
  17. $formats-map: (
  18. eot: "#{$file-path}.eot?#iefix" format("embedded-opentype"),
  19. woff2: "#{$file-path}.woff2" format("woff2"),
  20. woff: "#{$file-path}.woff" format("woff"),
  21. ttf: "#{$file-path}.ttf" format("truetype"),
  22. svg: "#{$file-path}.svg##{$font-family}" format("svg")
  23. );
  24. @each $key, $values in $formats-map {
  25. @if contains($file-formats, $key) {
  26. $file-path: nth($values, 1);
  27. $font-format: nth($values, 2);
  28. @if $asset-pipeline == true {
  29. $src: append($src, font-url($file-path) $font-format, comma);
  30. } @else {
  31. $src: append($src, url($file-path) $font-format, comma);
  32. }
  33. }
  34. }
  35. @return $src;
  36. }