Kronuz / pyScss

pyScss, a Scss compiler for Python
MIT License
582 stars 140 forks source link

append does not work correctly #335

Closed PhilipGarnero closed 8 years ago

PhilipGarnero commented 9 years ago

Hello ! I just came across a small issue about the append function. By default pyscss append will separate using commas when it should separate using spaces.

I've set a small example for you to reproduce: First, you'll need to install sass along pyscss (sass is a python bindings library using libsass) pip install pyscss sass Now, a small test script:

import os
import sass
import scss

def save_file(path, content):
    with open(path, 'w') as f:
        f.write(content)

def libsass_compile_file(infile, outfile):
    save_file(outfile, sass.compile_file(str(infile), os.path.dirname(os.path.abspath(__file__))))

def pyscss_compile_file(infile, outfile):
    scss.config.LOAD_PATHS = os.path.dirname(os.path.abspath(__file__))
    save_file(outfile, scss.Scss(scss_opts={'compress': False, 'style': "legacy"}).compile(None, infile))

if __name__ == '__main__':
    libsass_compile_file("test.scss", "libsass_test.css")
    pyscss_compile_file("test.scss", "pyscss_test.css")

And then the scss file:

@function test-append($values) {
  $max: length($values);
  $remValues: ();
  @for $i from 1 through $max {
    $remValues: append($remValues, nth($values, $i));
  }
  @return $remValues;
}

@function test-append-comma($values) {
  $max: length($values);
  $remValues: ();
  @for $i from 1 through $max {
    $remValues: append($remValues, nth($values, $i), comma);
  }
  @return $remValues;
}

a {
  padding: test-append(10 20 30 40);
  margin: test-append-comma((10, 20, 30, 40));
}

The output we get:

# libsass_test.css
a {
  padding: 10 20 30 40;
  margin: 10, 20, 30, 40; }
# pyscss_test.css
a {
  padding: 10, 20, 30, 40;
  margin: 10, 20, 30, 40;
}
PhilipGarnero commented 9 years ago

Changing this to def append(lst, val, separator="space"): fixed it for me.

Kronuz commented 9 years ago

Unfortunately, this breaks the append() function (tested in tests/files/kronuz/selectors-append-nest.scss).

Kronuz commented 9 years ago

...or maybe that test in selectors-append-nest.scss is wrong?

PhilipGarnero commented 9 years ago

I think the test is wrong. When I try to compile it using libsass python bindings or sass gem I get these errors : libsass : selectors-append-nest.scss:7: error: unterminated argument to nest(...) sass : Syntax error: Invalid CSS after "nest": expected selector, was "("&, &:hover", ..." on line 7 of selectors-append-nest.scss

href commented 9 years ago

I had the same issue and I can confirm that the fix above works.

eevee commented 8 years ago

Fixed in 1.3.5 (though the above fix was not actually correct).