Skip to content

Add support for extension substitution #36

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

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 15 additions & 3 deletions sassutils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


def build_directory(sass_path, css_path, output_style='nested',
_root_sass=None, _root_css=None):
substitute_extension=False, _root_sass=None, _root_css=None):
"""Compiles all SASS/SCSS files in ``path`` to CSS.

:param sass_path: the path of the directory which contains source files
Expand All @@ -38,6 +38,9 @@ def build_directory(sass_path, css_path, output_style='nested',
choose one of: ``'nested'`` (default), ``'expanded'``,
``'compact'``, ``'compressed'``
:type output_style: :class:`str`
:param substitute_extension: whether or not to substitute the matched suffix
with the .css extenstion or just append .css
:type substitute_extension: :class:`bool`
:returns: a dictionary of source filenames to compiled CSS filenames
:rtype: :class:`collections.Mapping`

Expand All @@ -57,7 +60,11 @@ def build_directory(sass_path, css_path, output_style='nested',
if name[0] == '_':
# Do not compile if it's partial
continue
css_fullname = os.path.join(css_path, name) + '.css'
css_fullname = os.path.join(css_path, name)
if substitute_extension:
css_fullname = SUFFIX_PATTERN.sub('.css', css_fullname)
else:
css_fullname += '.css'
css = compile(filename=sass_fullname,
output_style=output_style,
include_paths=[_root_sass])
Expand All @@ -69,6 +76,7 @@ def build_directory(sass_path, css_path, output_style='nested',
css_fullname = os.path.join(css_path, name)
subresult = build_directory(sass_fullname, css_fullname,
output_style=output_style,
substitute_extension=substitute_extension,
_root_sass=_root_sass,
_root_css=_root_css)
result.update(subresult)
Expand Down Expand Up @@ -151,7 +159,7 @@ def resolve_filename(self, package_dir, filename):
css_path = os.path.join(package_dir, self.css_path, css_filename)
return sass_path, css_path

def build(self, package_dir, output_style='nested'):
def build(self, package_dir, output_style='nested', substitute_extension=False):
"""Builds the SASS/SCSS files in the specified :attr:`sass_path`.
It finds :attr:`sass_path` and locates :attr:`css_path`
as relative to the given ``package_dir``.
Expand All @@ -162,6 +170,9 @@ def build(self, package_dir, output_style='nested'):
choose one of: ``'nested'`` (default),
``'expanded'``, ``'compact'``, ``'compressed'``
:type output_style: :class:`str`
:param substitute_extension: whether or not to substitute the matched suffix
with the .css extenstion or just append .css
:type substitute_extension: :class:`bool`
:returns: the set of compiled CSS filenames
:rtype: :class:`collections.Set`

Expand All @@ -174,6 +185,7 @@ def build(self, package_dir, output_style='nested'):
css_files = build_directory(
sass_path, css_path,
output_style=output_style
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed a comma.

substitute_extension=substitute_extension
).values()
return frozenset(os.path.join(self.css_path, filename)
for filename in css_files)
Expand Down