//
// Font Face Mixin
// Source from: https://gist.github.com/jonathantneal/d0460e5c2d5d7f9bc5e6
// --------------------------------------------------
@mixin font-face($name, $path, $weight: null, $style: null, $display: auto, $exts: eot woff2 woff ttf svg) {
  $src: null;

  $extmods: (
    eot: "?",
    svg: "#" + str-replace($name, " ", "_")
  );

  $formats: (
    otf: "opentype",
    ttf: "truetype"
  );

  @each $ext in $exts {
    $extmod: if(map-has-key($extmods, $ext), $ext + map-get($extmods, $ext), $ext);
    $format: if(map-has-key($formats, $ext), map-get($formats, $ext), $ext);
    $src: append($src, url(quote($path + "." + $extmod)) format(quote($format)), comma);
  }

  @font-face {
    font-family: quote($name);
    font-style: $style;
    font-weight: $weight;
    src: $src;
    font-display: $display;
  }
}

@mixin font-face-stack($font-stack) {

  //Generate font face stack
  @each $name, $font in $font-stack {

    $path: map-get($font, path);
    $ext: map-get($font, ext);
    $display: map-get($font, display);
    $font-style: map-get($font, font-style);
    $font-weight: map-get($font, font-weight);
    $font-family: map-get($font, font-family);
    $font-family-name: nth($font-family, 1);

    @if not $path {
      $path: "../fonts/#{$name}";
    }

    @include font-face(#{$font-family-name}, "#{$path}/#{$name}-webfont", $font-weight, $font-style, $display, $ext);
  }
}
