mojotech / sass2stylus

Kewl
http://sass2stylus.com/
79 stars 18 forks source link

[Convert] Some function not support #98

Open claudchan opened 7 years ago

claudchan commented 7 years ago

Hi, I am trying to convert these sass code:

@function font-files($font-name, $formats...) {
  $full: '';
  @for $i from 1 through length($formats) {
    $full: $full + 'url("#{$font-name}.' + nth($formats, $i);
    @if nth($formats, $i) == 'ttf' {
      $full: $full + '") format("truetype")';
    }
    @else if nth($formats, $i) == 'svg' {
      $full: $full + '") format("svg")';
    }
    @else {
      $full: $full + '") format("' + nth($formats, $i) + '")';
    }
    @if $i != length($formats) {
      $full: $full + ', ';
    }
  }
  @return unquote($full);
}
@mixin font-face($name, $font-files, $eot: false, $weight: false, $style: false) {
  $iefont: unquote("#{$eot}?#iefix");
  @font-face {
    font-family: quote($name);
    @if $eot {
      src: url($eot);
      $font-files: url(quote($iefont)) unquote("format('embedded-opentype')"), $font-files;
    }
    src: $font-files;
    @if $weight {
      font-weight: $weight;
    }
    @if $style {
      font-style: $style;
    }
  }
}

End result:

//Below is a list of the Sass rules that could not be converted to Stylus
//quote: line 18 in your Sass file
//quote: line 21 in your Sass file
//quote: line 23 in your Sass file

font-files($font-name, $formats...)
  $full = ""
  for $i in (1)..(length($formats))
    $full = $full + "url(\"#{$font-name}." + nth($formats, $i)
    if nth($formats, $i) == "ttf"
      $full = $full + '") format("truetype")'
    else if nth($formats, $i) == "svg"
      $full = $full + '") format("svg")'
    else
      $full = $full + '") format("' + nth($formats, $i) + '")'
    if $i != length($formats)
      $full = $full + ", "
  //Function quote is not supported in Stylus
  //unquote($full)
font-face($name, $font-files, $eot = false, $weight = false, $style = false)
  //Function quote is not supported in Stylus
  //$iefont = unquote("#{$eot}?#iefix")
  @font-face
    //Function quote is not supported in Stylus
    //font-family: quote($name)
    if $eot
      src: url($eot)
      $font-files = url(quote($iefont)) unquote("format('embedded-opentype')"), $font-files
    src: $font-files
    if $weight
      font-weight: $weight
    if $style
      font-style: $style

Anyone could help how to make something same result using the sass above? Thanks in advance.

claudchan commented 7 years ago

My current fixes:

font-files(font-name, formats...)
  full = ""
  for $i in 0..length(formats)
    if formats[$i] != null
      full = full + 'url("' + font-name + "." + formats[$i]
      if formats[$i] == "ttf"
        full = full + '") format("truetype")'
      else if formats[$i] == "svg"
        full = full + '") format("svg")'
      else
        full = full + '") format("' + formats[$i] + '")'
      if $i+1 != length(formats)
        full = full + ", "
  return unquote(full)
font-face(name, font-files, eot = null, weight = normal, style = normal)
  iefont = unquote(eot+'?#iefix')
  @font-face
    font-family name
    if eot != false
      src url(eot)
      font-files = url(iefont) format('embedded-opentype'), font-files
    src font-files
    if weight
      font-weight weight
    if style
      font-style style