Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 10ee082

Browse files
committed
Add precision parameter
1 parent 5e924e6 commit 10ee082

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

pysass.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ static PyObject *
3939
PySass_compile_string(PyObject *self, PyObject *args) {
4040
struct sass_context *context;
4141
char *string, *include_paths, *image_path;
42-
int output_style, source_comments;
42+
int output_style, source_comments, precision;
4343
PyObject *result;
4444

4545
if (!PyArg_ParseTuple(args,
46-
PySass_IF_PY3("yiiyy", "siiss"),
46+
PySass_IF_PY3("yiiyyi", "siissi"),
4747
&string, &output_style, &source_comments,
48-
&include_paths, &image_path)) {
48+
&include_paths, &image_path, &precision)) {
4949
return NULL;
5050
}
5151

@@ -55,6 +55,7 @@ PySass_compile_string(PyObject *self, PyObject *args) {
5555
context->options.source_comments = source_comments;
5656
context->options.include_paths = include_paths;
5757
context->options.image_path = image_path;
58+
context->options.precision = precision;
5859

5960
sass_compile(context);
6061

@@ -71,13 +72,13 @@ static PyObject *
7172
PySass_compile_filename(PyObject *self, PyObject *args) {
7273
struct sass_file_context *context;
7374
char *filename, *include_paths, *image_path;
74-
int output_style, source_comments, error_status;
75+
int output_style, source_comments, error_status, precision;
7576
PyObject *source_map_filename, *result;
7677

7778
if (!PyArg_ParseTuple(args,
78-
PySass_IF_PY3("yiiyyO", "siissO"),
79+
PySass_IF_PY3("yiiyyiO", "siissiO"),
7980
&filename, &output_style, &source_comments,
80-
&include_paths, &image_path, &source_map_filename)) {
81+
&include_paths, &image_path, &precision, &source_map_filename)) {
8182
return NULL;
8283
}
8384

@@ -99,6 +100,7 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
99100
context->options.source_comments = source_comments;
100101
context->options.include_paths = include_paths;
101102
context->options.image_path = image_path;
103+
context->options.precision = precision;
102104

103105
sass_compile_file(context);
104106

@@ -119,14 +121,14 @@ static PyObject *
119121
PySass_compile_dirname(PyObject *self, PyObject *args) {
120122
struct sass_folder_context *context;
121123
char *search_path, *output_path, *include_paths, *image_path;
122-
int output_style, source_comments;
124+
int output_style, source_comments, precision;
123125
PyObject *result;
124126

125127
if (!PyArg_ParseTuple(args,
126-
PySass_IF_PY3("yyiyy", "ssiss"),
128+
PySass_IF_PY3("yyiiyyi", "ssiissi"),
127129
&search_path, &output_path,
128130
&output_style, &source_comments,
129-
&include_paths, &image_path)) {
131+
&include_paths, &image_path, precision)) {
130132
return NULL;
131133
}
132134

@@ -137,6 +139,7 @@ PySass_compile_dirname(PyObject *self, PyObject *args) {
137139
context->options.source_comments = source_comments;
138140
context->options.include_paths = include_paths;
139141
context->options.image_path = image_path;
142+
context->options.precision = precision;
140143

141144
sass_compile_folder(context);
142145

sass.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def compile(**kwargs):
158158
elif len(modes) > 1:
159159
raise TypeError(and_join(modes) + ' are exclusive each other; '
160160
'cannot be used at a time')
161+
precision = kwargs.pop('precision', 5)
161162
output_style = kwargs.pop('output_style', 'nested')
162163
if not isinstance(output_style, string_types):
163164
raise TypeError('output_style must be a string, not ' +
@@ -235,7 +236,7 @@ def compile(**kwargs):
235236
string = string.encode('utf-8')
236237
s, v = compile_string(string,
237238
output_style, source_comments,
238-
include_paths, image_path)
239+
include_paths, image_path, precision)
239240
if s:
240241
return v.decode('utf-8')
241242
elif 'filename' in modes:
@@ -249,7 +250,7 @@ def compile(**kwargs):
249250
s, v, source_map = compile_filename(
250251
filename,
251252
output_style, source_comments,
252-
include_paths, image_path, source_map_filename
253+
include_paths, image_path, precision, source_map_filename
253254
)
254255
if s:
255256
v = v.decode('utf-8')
@@ -299,7 +300,7 @@ def compile(**kwargs):
299300
output_path = output_path.encode(fs_encoding)
300301
s, v = compile_dirname(search_path, output_path,
301302
output_style, source_comments,
302-
include_paths, image_path)
303+
include_paths, image_path, precision)
303304
if s:
304305
return
305306
else:

sassc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
8787
parser.add_option('-w', '--watch', action='store_true',
8888
help='Watch file for changes. Requires the second '
8989
'argument (output css filename).')
90+
parser.add_option('-p', '--precision', action='store', type="int", default=5,
91+
help='Set number of decimal places. [default: %default]')
9092
options, args = parser.parse_args(argv[1:])
9193
error = functools.partial(print,
9294
parser.get_prog_name() + ': error:',
@@ -122,7 +124,8 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
122124
output_style=options.output_style,
123125
source_map_filename=source_map_filename,
124126
include_paths=options.include_paths,
125-
image_path=options.image_path
127+
image_path=options.image_path,
128+
precision=options.precision
126129
)
127130
else:
128131
source_map_filename = None
@@ -131,7 +134,8 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
131134
filename=filename,
132135
output_style=options.output_style,
133136
include_paths=options.include_paths,
134-
image_path=options.image_path
137+
image_path=options.image_path,
138+
precision=options.precision
135139
)
136140
except (IOError, OSError) as e:
137141
error(e)

0 commit comments

Comments
 (0)