26
26
27
27
28
28
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 ):
30
30
"""Compiles all SASS/SCSS files in ``path`` to CSS.
31
31
32
32
: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',
38
38
choose one of: ``'nested'`` (default), ``'expanded'``,
39
39
``'compact'``, ``'compressed'``
40
40
: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`
41
44
:returns: a dictionary of source filenames to compiled CSS filenames
42
45
:rtype: :class:`collections.Mapping`
43
46
@@ -57,7 +60,11 @@ def build_directory(sass_path, css_path, output_style='nested',
57
60
if name [0 ] == '_' :
58
61
# Do not compile if it's partial
59
62
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'
61
68
css = compile (filename = sass_fullname ,
62
69
output_style = output_style ,
63
70
include_paths = [_root_sass ])
@@ -69,6 +76,7 @@ def build_directory(sass_path, css_path, output_style='nested',
69
76
css_fullname = os .path .join (css_path , name )
70
77
subresult = build_directory (sass_fullname , css_fullname ,
71
78
output_style = output_style ,
79
+ substitute_extension = substitute_extension ,
72
80
_root_sass = _root_sass ,
73
81
_root_css = _root_css )
74
82
result .update (subresult )
@@ -151,7 +159,7 @@ def resolve_filename(self, package_dir, filename):
151
159
css_path = os .path .join (package_dir , self .css_path , css_filename )
152
160
return sass_path , css_path
153
161
154
- def build (self , package_dir , output_style = 'nested' ):
162
+ def build (self , package_dir , output_style = 'nested' , substitute_extension = False ):
155
163
"""Builds the SASS/SCSS files in the specified :attr:`sass_path`.
156
164
It finds :attr:`sass_path` and locates :attr:`css_path`
157
165
as relative to the given ``package_dir``.
@@ -162,6 +170,9 @@ def build(self, package_dir, output_style='nested'):
162
170
choose one of: ``'nested'`` (default),
163
171
``'expanded'``, ``'compact'``, ``'compressed'``
164
172
: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`
165
176
:returns: the set of compiled CSS filenames
166
177
:rtype: :class:`collections.Set`
167
178
@@ -174,6 +185,7 @@ def build(self, package_dir, output_style='nested'):
174
185
css_files = build_directory (
175
186
sass_path , css_path ,
176
187
output_style = output_style
188
+ substitute_extension = substitute_extension
177
189
).values ()
178
190
return frozenset (os .path .join (self .css_path , filename )
179
191
for filename in css_files )
0 commit comments