Skip to content

Commit 7062fe7

Browse files
author
Andrey Fedoseev
committed
Add source maps support for Stylus
1 parent 7ef3d57 commit 7062fe7

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Dev
88
- Add source maps support for SASS/SCSS
99
- Add source maps support for LESS
1010
- Add source maps support for CoffeeScript
11+
- Add source maps support for Stylus
1112

1213

1314
1.0.1

README.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,13 @@ Stylus
241241
``executable``
242242
Path to Stylus compiler executable. Default: ``"stylus"``.
243243

244+
``sourcemap_enabled``
245+
Boolean. Set to ``True`` to enable source maps. Default: ``False``
246+
244247
Example::
245248

246249
STATIC_PRECOMPILER_COMPILERS = (
247-
('static_precompiler.compilers.Stylus', {"executable": "/usr/bin/stylus"),
250+
('static_precompiler.compilers.Stylus', {"executable": "/usr/bin/stylus", "sourcemap_enabled": True),
248251
)
249252

250253

static_precompiler/compilers/stylus.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ class Stylus(base.BaseCompiler):
1919

2020
IMPORT_RE = re.compile(r"@(?:import|require)\s+(.+?)\s*$", re.MULTILINE)
2121

22-
def __init__(self, executable="stylus"):
22+
def __init__(self, executable="stylus", sourcemap_enabled=False):
2323
self.executable = executable
24+
self.is_sourcemap_enabled = sourcemap_enabled
2425
super(Stylus, self).__init__()
2526

2627
def compile_source(self, source):
@@ -40,9 +41,13 @@ def compile_file(self, source_path):
4041
full_output_path = self.get_full_output_path(source_path)
4142
args = [
4243
self.executable,
44+
]
45+
if self.is_sourcemap_enabled:
46+
args.append("-m")
47+
args.extend([
4348
full_source_path,
4449
"-o", os.path.dirname(full_output_path),
45-
]
50+
])
4651

4752
full_output_dirname = os.path.dirname(full_output_path)
4853
if not os.path.exists(full_output_dirname):

static_precompiler/tests/test_stylus.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ def test_compile_file(monkeypatch, tmpdir):
2828
"""
2929

3030

31+
def test_sourcemap(monkeypatch, tmpdir):
32+
33+
monkeypatch.setattr("static_precompiler.settings.ROOT", tmpdir.strpath)
34+
monkeypatch.setattr("static_precompiler.utils.convert_urls", lambda *args: None)
35+
36+
compiler = compilers.Stylus(sourcemap_enabled=False)
37+
compiler.compile_file("styles/stylus/A.styl")
38+
full_output_path = compiler.get_full_output_path("styles/stylus/A.styl")
39+
assert not os.path.exists(full_output_path + ".map")
40+
41+
compiler = compilers.Stylus(sourcemap_enabled=True)
42+
compiler.compile_file("styles/stylus/A.styl")
43+
full_output_path = compiler.get_full_output_path("styles/stylus/A.styl")
44+
assert os.path.exists(full_output_path + ".map")
45+
46+
3147
def test_compile_source():
3248
compiler = compilers.Stylus()
3349

0 commit comments

Comments
 (0)