Skip to content

Commit 2cea7bd

Browse files
committed
Add support for extension substitution
It would be nice to go from `foo.scss` to `foo.css` instead of always defaulting to `foo.scss.css`.
1 parent 69fb373 commit 2cea7bd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

sassutils/builder.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
def build_directory(sass_path, css_path, output_style='nested',
29-
_root_sass=None, _root_css=None):
29+
substitute_extension=False, _root_sass=None, _root_css=None):
3030
"""Compiles all SASS/SCSS files in ``path`` to CSS.
3131
3232
:param sass_path: the path of the directory which contains source files
@@ -38,6 +38,9 @@ def build_directory(sass_path, css_path, output_style='nested',
3838
choose one of: ``'nested'`` (default), ``'expanded'``,
3939
``'compact'``, ``'compressed'``
4040
:type output_style: :class:`str`
41+
:param substitute_extension: whether or not to substitute the matched suffix
42+
with the .css extenstion or just append .css
43+
:type substitute_extension: :class:`bool`
4144
:returns: a dictionary of source filenames to compiled CSS filenames
4245
:rtype: :class:`collections.Mapping`
4346
@@ -57,7 +60,11 @@ def build_directory(sass_path, css_path, output_style='nested',
5760
if name[0] == '_':
5861
# Do not compile if it's partial
5962
continue
60-
css_fullname = os.path.join(css_path, name) + '.css'
63+
css_fullname = os.path.join(css_path, name)
64+
if substitute_extension:
65+
css_fullname = SUFFIX_PATTERN.sub('.css', css_fullname)
66+
else:
67+
css_fullname += '.css'
6168
css = compile(filename=sass_fullname,
6269
output_style=output_style,
6370
include_paths=[_root_sass])
@@ -69,6 +76,7 @@ def build_directory(sass_path, css_path, output_style='nested',
6976
css_fullname = os.path.join(css_path, name)
7077
subresult = build_directory(sass_fullname, css_fullname,
7178
output_style=output_style,
79+
substitute_extension=substitute_extension,
7280
_root_sass=_root_sass,
7381
_root_css=_root_css)
7482
result.update(subresult)
@@ -151,7 +159,7 @@ def resolve_filename(self, package_dir, filename):
151159
css_path = os.path.join(package_dir, self.css_path, css_filename)
152160
return sass_path, css_path
153161

154-
def build(self, package_dir, output_style='nested'):
162+
def build(self, package_dir, output_style='nested', substitute_extension=False):
155163
"""Builds the SASS/SCSS files in the specified :attr:`sass_path`.
156164
It finds :attr:`sass_path` and locates :attr:`css_path`
157165
as relative to the given ``package_dir``.
@@ -162,6 +170,9 @@ def build(self, package_dir, output_style='nested'):
162170
choose one of: ``'nested'`` (default),
163171
``'expanded'``, ``'compact'``, ``'compressed'``
164172
:type output_style: :class:`str`
173+
:param substitute_extension: whether or not to substitute the matched suffix
174+
with the .css extenstion or just append .css
175+
:type substitute_extension: :class:`bool`
165176
:returns: the set of compiled CSS filenames
166177
:rtype: :class:`collections.Set`
167178
@@ -174,6 +185,7 @@ def build(self, package_dir, output_style='nested'):
174185
css_files = build_directory(
175186
sass_path, css_path,
176187
output_style=output_style
188+
substitute_extension=substitute_extension
177189
).values()
178190
return frozenset(os.path.join(self.css_path, filename)
179191
for filename in css_files)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy