Skip to content

Commit e3d3380

Browse files
committed
Merge pull request #102 from illico/feature/41-indented-strings
Support for string compilation using indented (SASS) string syntax.
2 parents a7524d8 + 5902c07 commit e3d3380

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

pysass.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,15 @@ PySass_compile_string(PyObject *self, PyObject *args) {
412412
char *string, *include_paths;
413413
const char *error_message, *output_string;
414414
Sass_Output_Style output_style;
415-
int source_comments, error_status, precision;
415+
int source_comments, error_status, precision, indented;
416416
PyObject *custom_functions;
417417
PyObject *result;
418418

419419
if (!PyArg_ParseTuple(args,
420-
PySass_IF_PY3("yiiyiO", "siisiO"),
420+
PySass_IF_PY3("yiiyiOi", "siisiOi"),
421421
&string, &output_style, &source_comments,
422422
&include_paths, &precision,
423-
&custom_functions)) {
423+
&custom_functions, &indented)) {
424424
return NULL;
425425
}
426426

@@ -430,6 +430,7 @@ PySass_compile_string(PyObject *self, PyObject *args) {
430430
sass_option_set_source_comments(options, source_comments);
431431
sass_option_set_include_path(options, include_paths);
432432
sass_option_set_precision(options, precision);
433+
sass_option_set_is_indented_syntax_src(options, indented);
433434
_add_custom_functions(options, custom_functions);
434435

435436
sass_compile_data_context(context);

sass.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ def compile(**kwargs):
205205
:type custom_functions: :class:`collections.Set`,
206206
:class:`collections.Sequence`,
207207
:class:`collections.Mapping`
208+
:param indented: optional declaration that the string is SASS, not SCSS
209+
formatted. :const:`False` by default
210+
:type indented: :class:`bool`
208211
:returns: the compiled CSS string
209212
:rtype: :class:`str`
210213
:raises sass.CompileError: when it fails for any reason
@@ -449,9 +452,13 @@ def func_name(a, b):
449452
string = kwargs.pop('string')
450453
if isinstance(string, text_type):
451454
string = string.encode('utf-8')
455+
indented = kwargs.pop('indented', False)
456+
if not isinstance(indented, bool):
457+
raise TypeError('indented must be bool, not ' +
458+
repr(source_comments))
452459
s, v = compile_string(
453460
string, output_style, source_comments, include_paths, precision,
454-
custom_functions,
461+
custom_functions, indented
455462
)
456463
if s:
457464
return v.decode('utf-8')

sasstests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ def test_compile_string(self):
256256
self.assertRaises(TypeError, sass.compile, string=1234)
257257
self.assertRaises(TypeError, sass.compile, string=[])
258258

259+
def test_compile_string_sass_style(self):
260+
actual = sass.compile(string='a\n\tb\n\t\tcolor: blue;',
261+
indented=True)
262+
assert actual == 'a b {\n color: blue; }\n'
263+
259264
def test_compile_string_deprecated_source_comments_line_numbers(self):
260265
source = '''a {
261266
b { color: blue; }

0 commit comments

Comments
 (0)