mojotech / sass2stylus

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

Can't Convert #71

Closed VinSpee closed 10 years ago

VinSpee commented 10 years ago

I'd like to do a direct conversion of team-sass/modular-scale. The following code will not convert:

// Outputs a list of values instead of a single value
@function ms-list($Start: 0, $End: 0, $Bases: $ms-base, $Ratios: $ms-ratio) {

  // Seed results
  $Positive-return: ();
  $Negitive-return: ();
  $Return: ();

  @if $End >= 0 {
    // Generate a list of all possible values
    $Positive-return: ms-generate-list($End, $Bases, $Ratios);

    // Sort the generated lists
    $Positive-return: ms-sort-list($Positive-return);

    // Trim list
    $Trim-list: ();
    // If the starting value is a positive number
    // trim the positive return from that
    @if $Start >= 0 {
      @for $i from ($Start + 1) through $End + 1 {
        $Trim-list: join($Trim-list, nth($Positive-return, $i));
      }
    }
    // If not, then include everything up to the end.
    @else {
      @for $i from 1 through $End + 1 {
        $Trim-list: join($Trim-list, nth($Positive-return, $i));
      }
    }
    $Positive-return: $Trim-list;
  }

  // Generate a negitive list
  @if $Start < 0 {
    // Generate a list of all possible values
    $Negitive-return: ms-generate-list($Start, $Bases, $Ratios);

    // Sort the generated lists
    $Negitive-return: ms-sort-list($Negitive-return);

    // Reverse negitive list results.
    $MS-new-return: ();
    @each $i in $Negitive-return {
      $MS-new-return: join($i, $MS-new-return);
    }
    $Negitive-return: $MS-new-return;

    // Trim list
    $Trim-list: ();
    @if $End < 0 {
      @for $i from abs($End) through (abs($Start) + 2) {
        $Trim-list: join(nth($Negitive-return, $i), $Trim-list);
      }
    }
    @else {
      @for $i from 2 through (abs($Start) + 1) {
        $Trim-list: join(nth($Negitive-return, $i), $Trim-list);
      }
    }
    $Negitive-return: $Trim-list;
  }

  // Join both positive and negitive possibilities.
  $Return: join($Negitive-return, $Positive-return);

  @return $Return;
}
VinSpee commented 10 years ago

actually many of the files in the repo can't be converted

samccone commented 10 years ago

thanks @VinSpee we will take a look. There is a possibility that a 1:1 conversion will be impossible

see https://github.com/mojotech/sass2stylus/blob/master/functions.yml#L1

but we will see what we can do.

VinSpee commented 10 years ago

is there an alternative to nth?

--  Vince Speelman Sent with Airmail

On April 23, 2014 at 5:09:00 PM, Sam Saccone (notifications@github.com) wrote:

thanks @VinSpee we will take a look. There is a possibility that a 1:1 conversion will be impossible

see https://github.com/mojotech/sass2stylus/blob/master/functions.yml#L1

but we will see what we can do.

— Reply to this email directly or view it on GitHub.

samccone commented 10 years ago

Not that I know of. You can always file an issue asking here https://github.com/LearnBoost/stylus/issues

kizu commented 10 years ago

is there an alternative to nth?

I'd say nth($list, $n) from Sass could be converted to $list[$n - 1] in Stylus if $list is a list. If $list is a map, it becomes a little more complicated, but still possible.

However, for such cases it would be nice to write Stylus functions that would polyfill absent functions from Sass, so code like this: nth((width: 10px, length: 20px), 2) would be replaced with nth({width: 10px, length: 20px}, 2) plus a Stylus' nth function definition at the start.

samccone commented 10 years ago

thanks for the insight @kizu hopefully someone will pick this up and we can get it in.