Skip to content

Commit 560ebbb

Browse files
committed
Add more cli opts and source map config args
1 parent 889f0ba commit 560ebbb

File tree

4 files changed

+213
-20
lines changed

4 files changed

+213
-20
lines changed

pysass.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -512,19 +512,24 @@ PySass_compile_string(PyObject *self, PyObject *args) {
512512
struct Sass_Context *ctx;
513513
struct Sass_Data_Context *context;
514514
struct Sass_Options *options;
515-
char *string, *include_paths;
515+
char *string, *include_paths, *source_map_file;
516516
const char *error_message, *output_string;
517517
Sass_Output_Style output_style;
518-
int source_comments, error_status, precision, indented;
518+
int source_comments, error_status, precision, indented,
519+
source_map_embed, source_map_contents, source_map_file_urls,
520+
omit_source_map_url;
519521
PyObject *custom_functions;
520522
PyObject *custom_importers;
523+
PyObject *source_map_root;
521524
PyObject *result;
522525

523526
if (!PyArg_ParseTuple(args,
524-
PySass_IF_PY3("yiiyiOiO", "siisiOiO"),
527+
PySass_IF_PY3("yiiyiiOO|iiiO", "siisiiOO|iiiO"),
525528
&string, &output_style, &source_comments,
526-
&include_paths, &precision,
527-
&custom_functions, &indented, &custom_importers)) {
529+
&include_paths, &precision, &indented,
530+
&custom_functions, &custom_importers,
531+
&source_map_contents, &source_map_embed,
532+
&omit_source_map_url, &source_map_root)) {
528533
return NULL;
529534
}
530535

@@ -535,6 +540,18 @@ PySass_compile_string(PyObject *self, PyObject *args) {
535540
sass_option_set_include_path(options, include_paths);
536541
sass_option_set_precision(options, precision);
537542
sass_option_set_is_indented_syntax_src(options, indented);
543+
sass_option_set_source_map_contents(options, source_map_contents);
544+
sass_option_set_source_map_embed(options, source_map_embed);
545+
sass_option_set_omit_source_map_url(options, omit_source_map_url);
546+
547+
if (PyBytes_Check(source_map_root)) {
548+
if (PyBytes_GET_SIZE(source_map_root)) {
549+
sass_option_set_source_map_root(
550+
options, PyBytes_AS_STRING(source_map_root)
551+
);
552+
}
553+
}
554+
538555
_add_custom_functions(options, custom_functions);
539556
_add_custom_importers(options, custom_importers);
540557
sass_compile_data_context(context);
@@ -560,16 +577,19 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
560577
char *filename, *include_paths;
561578
const char *error_message, *output_string, *source_map_string;
562579
Sass_Output_Style output_style;
563-
int source_comments, error_status, precision;
580+
int source_comments, error_status, precision, source_map_embed, indented,
581+
source_map_contents, source_map_file_urls, omit_source_map_url;
564582
PyObject *source_map_filename, *custom_functions, *custom_importers,
565-
*result, *output_filename_hint;
583+
*result, *output_filename_hint, *source_map_root;
566584

567585
if (!PyArg_ParseTuple(args,
568-
PySass_IF_PY3("yiiyiOOOO", "siisiOOOO"),
586+
PySass_IF_PY3("yiiyiiOOOO|iiiO", "siisiiOOOO|iiiO"),
569587
&filename, &output_style, &source_comments,
570-
&include_paths, &precision,
588+
&include_paths, &precision, &indented,
571589
&source_map_filename, &custom_functions,
572-
&custom_importers, &output_filename_hint)) {
590+
&custom_importers, &output_filename_hint,
591+
&source_map_contents, &source_map_embed,
592+
&omit_source_map_url, &source_map_root)) {
573593
return NULL;
574594
}
575595

@@ -590,10 +610,23 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
590610
);
591611
}
592612
}
613+
614+
if (PyBytes_Check(source_map_root)) {
615+
if (PyBytes_GET_SIZE(source_map_root)) {
616+
sass_option_set_source_map_root(
617+
options, PyBytes_AS_STRING(source_map_root)
618+
);
619+
}
620+
}
621+
593622
sass_option_set_output_style(options, output_style);
594623
sass_option_set_source_comments(options, source_comments);
595624
sass_option_set_include_path(options, include_paths);
596625
sass_option_set_precision(options, precision);
626+
sass_option_set_is_indented_syntax_src(options, indented);
627+
sass_option_set_source_map_contents(options, source_map_contents);
628+
sass_option_set_source_map_embed(options, source_map_embed);
629+
sass_option_set_omit_source_map_url(options, omit_source_map_url);
597630
_add_custom_functions(options, custom_functions);
598631
_add_custom_importers(options, custom_importers);
599632
sass_compile_file_context(context);

pysassc.py

100644100755
Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,42 @@
4747
4848
.. versionadded:: 0.11.0
4949
50+
.. option:: --sourcemap-file
51+
52+
Output file for source map
53+
54+
.. versionadded:: 0.17.0
55+
56+
.. option:: --sourcemap-contents
57+
58+
Embed sourcesContent in source map.
59+
60+
.. versionadded:: 0.17.0
61+
62+
.. option:: --sourcemap-embed
63+
64+
Embed sourceMappingUrl as data URI
65+
66+
.. versionadded:: 0.17.0
67+
68+
.. option:: --omit-sourcemap-url
69+
70+
Omit source map URL comment from output
71+
72+
.. versionadded:: 0.17.0
73+
74+
.. option:: --sourcemap-root
75+
76+
Base path, will be emitted to sourceRoot in source-map as is
77+
78+
.. versionadded:: 0.17.0
79+
80+
.. option:: -i, --indented-syntax
81+
82+
Treat input as sass code (versus scss).
83+
84+
.. versionadded:: 0.17.0
85+
5086
.. option:: -v, --version
5187
5288
Prints the program version.
@@ -86,12 +122,42 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
86122
output_styles + '. [default: %default]'
87123
),
88124
)
125+
parser.add_option(
126+
'-i', '--indented-syntax', dest='indented', default=False,
127+
help='Treat data from stdin as sass code (versus scss).',
128+
)
89129
parser.add_option(
90130
'-m', '-g', '--sourcemap', dest='source_map',
91131
action='store_true', default=False,
92132
help='Emit source map. Requires the second argument '
93133
'(output css filename).',
94134
)
135+
parser.add_option(
136+
'--sourcemap-file', dest='source_map_file', metavar='FILE',
137+
action='store', default=None,
138+
help='Output file for source map. If omitted, source map is based on '
139+
'the output css filename',
140+
)
141+
parser.add_option(
142+
'--sourcemap-contents', dest='source_map_contents',
143+
action='store_true', default=False,
144+
help='Embed sourcesContent in source map',
145+
)
146+
parser.add_option(
147+
'--sourcemap-embed', dest='source_map_embed',
148+
action='store_true', default=False,
149+
help='Embed sourceMappingUrl as data URI',
150+
)
151+
parser.add_option(
152+
'--omit-sourcemap-url', dest='omit_source_map_url',
153+
action='store_true', default=False,
154+
help='Omit source map URL comment from output',
155+
)
156+
parser.add_option(
157+
'--sourcemap-root', metavar='DIR',
158+
dest='source_map_root', action='store', default=None,
159+
help='Base path, will be emitted to sourceRoot in source-map as is',
160+
)
95161
parser.add_option(
96162
'-I', '--include-path', metavar='DIR',
97163
dest='include_paths', action='append',
@@ -139,15 +205,19 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
139205

140206
try:
141207
if options.source_map:
142-
source_map_filename = args[1] + '.map' # FIXME
208+
source_map_filename = options.source_map_file or args[1] + '.map'
143209
css, source_map = sass.compile(
144210
filename=filename,
145211
output_style=options.style,
146212
source_comments=options.source_comments,
147213
source_map_filename=source_map_filename,
214+
source_map_contents=options.source_map_contents,
215+
source_map_embed=options.source_map_embed,
216+
source_map_root=options.source_map_root,
148217
output_filename_hint=args[1],
149218
include_paths=options.include_paths,
150219
precision=options.precision,
220+
indented=options.indented,
151221
)
152222
else:
153223
source_map_filename = None
@@ -158,6 +228,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
158228
source_comments=options.source_comments,
159229
include_paths=options.include_paths,
160230
precision=options.precision,
231+
indented=options.indented,
161232
)
162233
except (IOError, OSError) as e:
163234
error(e)

sass.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ def _raise(e):
225225

226226
def compile_dirname(
227227
search_path, output_path, output_style, source_comments, include_paths,
228-
precision, custom_functions, importers,
228+
precision, indented, custom_functions, importers,
229+
source_map_contents=False, source_map_embed=False,
230+
omit_source_map_url=False, source_map_root=None,
229231
):
230232
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
231233
for dirpath, _, filenames in os.walk(search_path, onerror=_raise):
@@ -242,7 +244,9 @@ def compile_dirname(
242244
input_filename = input_filename.encode(fs_encoding)
243245
s, v, _ = _sass.compile_filename(
244246
input_filename, output_style, source_comments, include_paths,
245-
precision, None, custom_functions, importers, None,
247+
precision, indented, None, custom_functions, importers, None,
248+
source_map_contents, source_map_embed, omit_source_map_url,
249+
source_map_root,
246250
)
247251
if s:
248252
v = v.decode('UTF-8')
@@ -325,6 +329,14 @@ def compile(**kwargs):
325329
output filename. :const:`None` means not
326330
using source maps. :const:`None` by default.
327331
:type source_map_filename: :class:`str`
332+
:param source_map_contents: embed include contents in map
333+
:type source_map_contents: :class:`bool`
334+
:param source_map_embed: embed sourceMappingUrl as data URI
335+
:type source_map_embed: :class:`bool`
336+
:param omit_source_map_url: omit source map URL comment from output
337+
:type omit_source_map_url: :class:`bool`
338+
:param source_map_root: base path, will be emitted in source map as is
339+
:type source_map_root: :class:`str`
328340
:param include_paths: an optional list of paths to find ``@import``\ ed
329341
Sass/CSS source files
330342
:type include_paths: :class:`collections.abc.Sequence`
@@ -568,6 +580,14 @@ def _get_file_arg(key):
568580
source_map_filename = _get_file_arg('source_map_filename')
569581
output_filename_hint = _get_file_arg('output_filename_hint')
570582

583+
source_map_contents = kwargs.pop('source_map_contents', False)
584+
source_map_embed = kwargs.pop('source_map_embed', False)
585+
omit_source_map_url = kwargs.pop('omit_source_map_url', False)
586+
source_map_root = kwargs.pop('source_map_root', None)
587+
588+
if isinstance(source_map_root, text_type):
589+
source_map_root = source_map_root.encode('utf-8')
590+
571591
# #208: cwd is always included in include paths
572592
include_paths = (os.getcwd(),)
573593
include_paths += tuple(kwargs.pop('include_paths', ()) or ())
@@ -608,18 +628,21 @@ def _get_file_arg(key):
608628

609629
importers = _validate_importers(kwargs.pop('importers', None))
610630

631+
indented = kwargs.pop('indented', False)
632+
if not isinstance(indented, bool):
633+
raise TypeError('indented must be bool, not ' +
634+
repr(source_comments))
635+
611636
if 'string' in modes:
612637
string = kwargs.pop('string')
613638
if isinstance(string, text_type):
614639
string = string.encode('utf-8')
615-
indented = kwargs.pop('indented', False)
616-
if not isinstance(indented, bool):
617-
raise TypeError('indented must be bool, not ' +
618-
repr(source_comments))
619640
_check_no_remaining_kwargs(compile, kwargs)
620641
s, v = _sass.compile_string(
621642
string, output_style, source_comments, include_paths, precision,
622-
custom_functions, indented, importers,
643+
indented, custom_functions, importers,
644+
source_map_contents, source_map_embed, omit_source_map_url,
645+
source_map_root,
623646
)
624647
if s:
625648
return v.decode('utf-8')
@@ -634,8 +657,10 @@ def _get_file_arg(key):
634657
_check_no_remaining_kwargs(compile, kwargs)
635658
s, v, source_map = _sass.compile_filename(
636659
filename, output_style, source_comments, include_paths, precision,
637-
source_map_filename, custom_functions, importers,
660+
indented, source_map_filename, custom_functions, importers,
638661
output_filename_hint,
662+
source_map_contents, source_map_embed, omit_source_map_url,
663+
source_map_root,
639664
)
640665
if s:
641666
v = v.decode('utf-8')
@@ -654,7 +679,9 @@ def _get_file_arg(key):
654679
_check_no_remaining_kwargs(compile, kwargs)
655680
s, v = compile_dirname(
656681
search_path, output_path, output_style, source_comments,
657-
include_paths, precision, custom_functions, importers,
682+
include_paths, precision, indented, custom_functions, importers,
683+
source_map_contents, source_map_embed, omit_source_map_url,
684+
source_map_root,
658685
)
659686
if s:
660687
return

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