Skip to content

Commit

Permalink
Add --source-comments option to sassc (help, etc. from node-sass)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Mar 8, 2016
1 parent f9fe779 commit 793bc16
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
7 changes: 4 additions & 3 deletions sass.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,6 @@ def compile(**kwargs):
:param source_map_filename: use source maps and indicate the source map
output filename. :const:`None` means not
using source maps. :const:`None` by default.
note that it implies ``source_comments``
is also :const:`True`
:type source_map_filename: :class:`str`
:param include_paths: an optional list of paths to find ``@import``\ ed
SASS/CSS source files
Expand All @@ -327,7 +325,7 @@ def compile(**kwargs):
<importer-callbacks>`_ description
:type importers: :class:`collections.Callable`
:returns: the compiled CSS string, or a pair of the compiled CSS string
and the source map string if ``source_comments='map'``
and the source map string if ``source_map_filename`` is set
:rtype: :class:`str`, :class:`tuple`
:raises sass.CompileError: when it fails for any reason
(for example the given SASS has broken syntax)
Expand Down Expand Up @@ -480,6 +478,9 @@ def my_importer(path):
.. versionadded:: 0.7.0
Added ``custom_functions`` parameter.
.. versionadded:: 0.11.0
``source_map_filename`` no longer implies ``source_comments``.
"""
modes = set()
for mode_name in MODES:
Expand Down
12 changes: 12 additions & 0 deletions sassc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
.. versionadded:: 0.7.0
.. option:: --source-comments
Include debug info in output.
.. versionadded:: 0.11.0
.. option:: -v, --version
Prints the program version.
Expand Down Expand Up @@ -101,6 +107,10 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
'-p', '--precision', action='store', type='int', default=5,
help='Set the precision for numbers. [default: %default]'
)
parser.add_option(
'--source-comments', action='store_true', default=False,
help='Include debug info in output',
)
options, args = parser.parse_args(argv[1:])
error = functools.partial(print,
parser.get_prog_name() + ': error:',
Expand Down Expand Up @@ -134,6 +144,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
css, source_map = compile(
filename=filename,
output_style=options.style,
source_comments=options.source_comments,
source_map_filename=source_map_filename,
include_paths=options.include_paths,
precision=options.precision
Expand All @@ -144,6 +155,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
css = compile(
filename=filename,
output_style=options.style,
source_comments=options.source_comments,
include_paths=options.include_paths,
precision=options.precision
)
Expand Down
20 changes: 11 additions & 9 deletions sasstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def setUp(self):
self.err = StringIO()

def test_no_args(self):
exit_code = sassc.main(['sassc', ], self.out, self.err)
exit_code = sassc.main(['sassc'], self.out, self.err)
self.assertEqual(2, exit_code)
err = self.err.getvalue()
assert err.strip().endswith('error: too few arguments'), \
Expand Down Expand Up @@ -794,12 +794,11 @@ def test_sassc_source_map_without_css_filename(self):
self.assertEqual('', self.out.getvalue())

def test_sassc_sourcemap(self):
tmp_dir = tempfile.mkdtemp()
src_dir = os.path.join(tmp_dir, 'test')
shutil.copytree('test', src_dir)
src_filename = os.path.join(src_dir, 'a.scss')
out_filename = os.path.join(tmp_dir, 'a.scss.css')
try:
with tempdir() as tmp_dir:
src_dir = os.path.join(tmp_dir, 'test')
shutil.copytree('test', src_dir)
src_filename = os.path.join(src_dir, 'a.scss')
out_filename = os.path.join(tmp_dir, 'a.scss.css')
exit_code = sassc.main(
['sassc', '-m', src_filename, out_filename],
self.out, self.err
Expand All @@ -817,8 +816,6 @@ def test_sassc_sourcemap(self):
dict(A_EXPECTED_MAP, sources=None),
dict(json.load(f), sources=None)
)
finally:
shutil.rmtree(tmp_dir)


@contextlib.contextmanager
Expand Down Expand Up @@ -1421,3 +1418,8 @@ def test_stack_trace_formatting():
'>> a{☃\n'
' --^\n\n'
)


def test_source_comments():
out = sass.compile(string='a{color: red}', source_comments=True)
assert out == '/* line 1, stdin */\na {\n color: red; }\n'

0 comments on commit 793bc16

Please sign in to comment.