Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Convert] Some function not support #98

Open
claudchan opened this issue Sep 6, 2017 · 1 comment
Open

[Convert] Some function not support #98

claudchan opened this issue Sep 6, 2017 · 1 comment

Comments

@claudchan
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant