Skip to content

Support for string compilation using indented (SASS) string syntax. #102

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 3 commits into from
Nov 24, 2015
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
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