Skip to content

Commit 2674d39

Browse files
committed
Add --output-style/-s option to build_sass command
1 parent 607b141 commit 2674d39

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

docs/changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ To be released.
2424
soon.
2525
- :func:`~sassutils.builder.build_directory()` function has a new optional
2626
parameter ``output_style``.
27+
- :meth:`~sassutils.builder.Build.build()` method has a new optional
28+
parameter ``output_style``.
29+
- Added ``--output-style``/``-s`` option to
30+
:class:`~sassutils.distutils.build_sass` command.
2731

2832
__ https://github.com/sass/libsass/releases/tag/3.0
2933
.. _partial import: http://sass-lang.com/documentation/file.SASS_REFERENCE.html#partials

sasstests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,15 @@ def test_build_sass(self):
519519
f.read()
520520
)
521521

522+
def test_output_style(self):
523+
rv = self.build_sass('--output-style', 'compressed')
524+
self.assertEqual(0, rv)
525+
with open(self.css_path('a.scss.css')) as f:
526+
self.assertEqual(
527+
'p a{color:red}p b{color:blue}',
528+
f.read()
529+
)
530+
522531

523532
class SasscTestCase(unittest.TestCase):
524533

sassutils/builder.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,30 @@ def resolve_filename(self, package_dir, filename):
151151
css_path = os.path.join(package_dir, self.css_path, css_filename)
152152
return sass_path, css_path
153153

154-
def build(self, package_dir):
154+
def build(self, package_dir, output_style='nested'):
155155
"""Builds the SASS/SCSS files in the specified :attr:`sass_path`.
156156
It finds :attr:`sass_path` and locates :attr:`css_path`
157157
as relative to the given ``package_dir``.
158158
159159
:param package_dir: the path of package directory
160160
:type package_dir: :class:`str`, :class:`basestring`
161+
:param output_style: an optional coding style of the compiled result.
162+
choose one of: ``'nested'`` (default),
163+
``'expanded'``, ``'compact'``, ``'compressed'``
164+
:type output_style: :class:`str`
161165
:returns: the set of compiled CSS filenames
162166
:rtype: :class:`collections.Set`
163167
168+
.. versionadded:: 0.6.0
169+
The ``output_style`` parameter.
170+
164171
"""
165172
sass_path = os.path.join(package_dir, self.sass_path)
166173
css_path = os.path.join(package_dir, self.css_path)
167-
css_files = build_directory(sass_path, css_path).values()
174+
css_files = build_directory(
175+
sass_path, css_path,
176+
output_style=output_style
177+
).values()
168178
return frozenset(os.path.join(self.css_path, filename)
169179
for filename in css_files)
170180

sassutils/distutils.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
'package.name': ('static/scss', 'static')
5050
}
5151
52+
.. versionadded:: 0.6.0
53+
Added ``--output-style``/``-s`` option to :class:`build_sass` command.
54+
5255
"""
5356
from __future__ import absolute_import
5457

@@ -61,6 +64,7 @@
6164
from setuptools import Command
6265
from setuptools.command.sdist import sdist
6366

67+
from sass import OUTPUT_STYLES
6468
from .builder import Manifest
6569

6670
__all__ = 'build_sass', 'validate_manifests'
@@ -86,10 +90,17 @@ class build_sass(Command):
8690
"""Builds SASS/SCSS files to CSS files."""
8791

8892
descriptin = __doc__
89-
user_options = []
93+
user_options = [
94+
(
95+
'output-style=', 's',
96+
'Coding style of the compiled result. Choose one of ' +
97+
', '.join(OUTPUT_STYLES)
98+
)
99+
]
90100

91101
def initialize_options(self):
92102
self.package_dir = None
103+
self.output_style = 'nested'
93104

94105
def finalize_options(self):
95106
self.package_dir = {}
@@ -107,7 +118,10 @@ def run(self):
107118
for package_name, manifest in manifests.items():
108119
package_dir = self.get_package_dir(package_name)
109120
distutils.log.info("building '%s' sass", package_name)
110-
css_files = manifest.build(package_dir)
121+
css_files = manifest.build(
122+
package_dir,
123+
output_style=self.output_style
124+
)
111125
map(distutils.log.info, css_files)
112126
package_data.setdefault(package_name, []).extend(css_files)
113127
data_files.extend((package_dir, f) for f 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