Skip to content

Commit

Permalink
Merge pull request #102 from illico/feature/41-indented-strings
Browse files Browse the repository at this point in the history
Support for string compilation using indented (SASS) string syntax.
  • Loading branch information
asottile committed Nov 24, 2015
2 parents a7524d8 + 5902c07 commit e3d3380
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pysass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,15 @@ PySass_compile_string(PyObject *self, PyObject *args) {
char *string, *include_paths;
const char *error_message, *output_string;
Sass_Output_Style output_style;
int source_comments, error_status, precision;
int source_comments, error_status, precision, indented;
PyObject *custom_functions;
PyObject *result;

if (!PyArg_ParseTuple(args,
PySass_IF_PY3("yiiyiO", "siisiO"),
PySass_IF_PY3("yiiyiOi", "siisiOi"),
&string, &output_style, &source_comments,
&include_paths, &precision,
&custom_functions)) {
&custom_functions, &indented)) {
return NULL;
}

Expand All @@ -430,6 +430,7 @@ PySass_compile_string(PyObject *self, PyObject *args) {
sass_option_set_source_comments(options, source_comments);
sass_option_set_include_path(options, include_paths);
sass_option_set_precision(options, precision);
sass_option_set_is_indented_syntax_src(options, indented);
_add_custom_functions(options, custom_functions);

sass_compile_data_context(context);
Expand Down
9 changes: 8 additions & 1 deletion sass.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ def compile(**kwargs):
:type custom_functions: :class:`collections.Set`,
:class:`collections.Sequence`,
:class:`collections.Mapping`
:param indented: optional declaration that the string is SASS, not SCSS
formatted. :const:`False` by default
:type indented: :class:`bool`
:returns: the compiled CSS string
:rtype: :class:`str`
:raises sass.CompileError: when it fails for any reason
Expand Down Expand Up @@ -449,9 +452,13 @@ def func_name(a, b):
string = kwargs.pop('string')
if isinstance(string, text_type):
string = string.encode('utf-8')
indented = kwargs.pop('indented', False)
if not isinstance(indented, bool):
raise TypeError('indented must be bool, not ' +
repr(source_comments))
s, v = compile_string(
string, output_style, source_comments, include_paths, precision,
custom_functions,
custom_functions, indented
)
if s:
return v.decode('utf-8')
Expand Down
5 changes: 5 additions & 0 deletions sasstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ def test_compile_string(self):
self.assertRaises(TypeError, sass.compile, string=1234)
self.assertRaises(TypeError, sass.compile, string=[])

def test_compile_string_sass_style(self):
actual = sass.compile(string='a\n\tb\n\t\tcolor: blue;',
indented=True)
assert actual == 'a b {\n color: blue; }\n'

def test_compile_string_deprecated_source_comments_line_numbers(self):
source = '''a {
b { color: blue; }
Expand Down

0 comments on commit e3d3380

Please sign in to comment.