Skip to content

Upgrade libsass to 3.5.0.beta1 #184

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

Merged
merged 1 commit into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libsass
9 changes: 7 additions & 2 deletions pysass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ static PyObject* _to_py_value(const union Sass_Value* value) {
size_t i = 0;
PyObject* items = PyTuple_New(sass_list_get_length(value));
PyObject* separator = sass_comma;
int is_bracketed = sass_list_get_is_bracketed(value);
PyObject* bracketed = PyBool_FromLong(is_bracketed);
switch (sass_list_get_separator(value)) {
case SASS_COMMA:
separator = sass_comma;
Expand All @@ -96,7 +98,7 @@ static PyObject* _to_py_value(const union Sass_Value* value) {
);
}
retv = PyObject_CallMethod(
types_mod, "SassList", "OO", items, separator
types_mod, "SassList", "OOO", items, separator, bracketed
);
break;
}
Expand Down Expand Up @@ -160,6 +162,7 @@ static union Sass_Value* _list_to_sass_value(PyObject* value) {
Py_ssize_t i = 0;
PyObject* items = PyObject_GetAttrString(value, "items");
PyObject* separator = PyObject_GetAttrString(value, "separator");
PyObject* bracketed = PyObject_GetAttrString(value, "bracketed");
Sass_Separator sep = SASS_COMMA;
if (separator == sass_comma) {
sep = SASS_COMMA;
Expand All @@ -168,7 +171,8 @@ static union Sass_Value* _list_to_sass_value(PyObject* value) {
} else {
assert(0);
}
retv = sass_make_list(PyTuple_Size(items), sep);
int is_bracketed = bracketed == Py_True;
retv = sass_make_list(PyTuple_Size(items), sep, is_bracketed);
for (i = 0; i < PyTuple_Size(items); i += 1) {
sass_list_set_value(
retv, i, _to_sass_value(PyTuple_GET_ITEM(items, i))
Expand All @@ -179,6 +183,7 @@ static union Sass_Value* _list_to_sass_value(PyObject* value) {
Py_DECREF(sass_space);
Py_DECREF(items);
Py_DECREF(separator);
Py_DECREF(bracketed);
return retv;
}

Expand Down
11 changes: 7 additions & 4 deletions sass.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,15 @@ def __new__(cls, r, g, b, a):
SEPARATORS = frozenset((SASS_SEPARATOR_COMMA, SASS_SEPARATOR_SPACE))


class SassList(collections.namedtuple('SassList', ('items', 'separator'))):
class SassList(collections.namedtuple(
'SassList', ('items', 'separator', 'bracketed'),
)):

def __new__(cls, items, separator):
def __new__(cls, items, separator, bracketed=False):
items = tuple(items)
assert separator in SEPARATORS
return super(SassList, cls).__new__(cls, items, separator)
assert separator in SEPARATORS, separator
assert isinstance(bracketed, bool), bracketed
return super(SassList, cls).__new__(cls, items, separator, bracketed)


class SassError(collections.namedtuple('SassError', ('msg',))):
Expand Down
31 changes: 25 additions & 6 deletions sasstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,16 +942,12 @@ def test_color_conversion(self):
assert type(color.a) is float, type(color.a)

def test_sass_list_no_conversion(self):
lst = sass.SassList(
('foo', 'bar'), sass.SASS_SEPARATOR_COMMA,
)
lst = sass.SassList(('foo', 'bar'), sass.SASS_SEPARATOR_COMMA)
assert type(lst.items) is tuple, type(lst.items)
assert lst.separator is sass.SASS_SEPARATOR_COMMA, lst.separator

def test_sass_list_conversion(self):
lst = sass.SassList(
['foo', 'bar'], sass.SASS_SEPARATOR_SPACE,
)
lst = sass.SassList(['foo', 'bar'], sass.SASS_SEPARATOR_SPACE)
assert type(lst.items) is tuple, type(lst.items)
assert lst.separator is sass.SASS_SEPARATOR_SPACE, lst.separator

Expand Down Expand Up @@ -1025,6 +1021,12 @@ def returns_space_list():
return sass.SassList(('medium', 'none'), sass.SASS_SEPARATOR_SPACE)


def returns_bracketed_list():
return sass.SassList(
('hello', 'ohai'), sass.SASS_SEPARATOR_SPACE, bracketed=True,
)


def returns_py_dict():
return {'foo': 'bar'}

Expand Down Expand Up @@ -1056,6 +1058,7 @@ def identity(x):
sass.SassFunction('returns_color', (), returns_color),
sass.SassFunction('returns_comma_list', (), returns_comma_list),
sass.SassFunction('returns_space_list', (), returns_space_list),
sass.SassFunction('returns_bracketed_list', (), returns_bracketed_list),
sass.SassFunction('returns_py_dict', (), returns_py_dict),
sass.SassFunction('returns_map', (), returns_map),
sass.SassFunction('identity', ('$x',), identity),
Expand All @@ -1075,6 +1078,7 @@ def identity(x):
'returns_color': returns_color,
'returns_comma_list': returns_comma_list,
'returns_space_list': returns_space_list,
'returns_bracketed_list': returns_bracketed_list,
'returns_py_dict': returns_py_dict,
'returns_map': returns_map,
'identity': identity,
Expand All @@ -1094,6 +1098,7 @@ def identity(x):
returns_color,
returns_comma_list,
returns_space_list,
returns_bracketed_list,
returns_py_dict,
returns_map,
identity,
Expand Down Expand Up @@ -1258,6 +1263,12 @@ def test_space_list(self):
'a{border-right:medium none}\n',
)

def test_bracketed_list(self):
self.assertEqual(
compile_with_func('a { content: returns_bracketed_list(); }'),
'a{content:[hello ohai]}\n'
)

def test_py_dict(self):
self.assertEqual(
compile_with_func(
Expand Down Expand Up @@ -1328,6 +1339,14 @@ def test_identity_space_list(self):
'a{border-right:medium none}\n',
)

def test_identity_bracketed_list(self):
self.assertEqual(
compile_with_func(
'a { content: identity(returns_bracketed_list()); }',
),
'a{content:[hello ohai]}\n',
)

def test_identity_py_dict(self):
self.assertEqual(
compile_with_func(
Expand Down