@@ -405,23 +405,18 @@ static struct SassValue* _call_py_f(
405
405
406
406
407
407
static void _add_custom_functions (
408
- struct Sass_Options * options , PyObject * custom_functions
408
+ struct SassCompiler * compiler , PyObject * custom_functions
409
409
) {
410
- Py_ssize_t i ;
411
- Sass_Function_List fn_list = sass_make_function_list (
412
- PyList_Size (custom_functions )
413
- );
414
- for (i = 0 ; i < PyList_Size (custom_functions ); i += 1 ) {
410
+ for (Py_ssize_t i = 0 ; i < PyList_Size (custom_functions ); i += 1 ) {
415
411
PyObject * sass_function = PyList_GetItem (custom_functions , i );
416
412
PyObject * signature = PySass_Object_Bytes (sass_function );
417
413
Sass_Function_Entry fn = sass_make_function (
418
414
PyBytes_AsString (signature ),
419
415
_call_py_f ,
420
416
sass_function
421
417
);
422
- sass_function_set_list_entry ( fn_list , i , fn );
418
+ sass_compiler_add_custom_function ( compiler , fn );
423
419
}
424
- sass_option_set_c_functions (options , fn_list );
425
420
}
426
421
427
422
static struct SassImportList * _call_py_importer_f (
@@ -430,7 +425,7 @@ static struct SassImportList* _call_py_importer_f(
430
425
PyObject * pyfunc = (PyObject * )sass_importer_get_cookie (cb );
431
426
PyObject * py_result = NULL ;
432
427
struct SassImportList * sass_imports = NULL ;
433
- struct Sass_Import * previous ;
428
+ struct SassImport * previous ;
434
429
const char * prev_path ;
435
430
Py_ssize_t i ;
436
431
@@ -450,8 +445,9 @@ static struct SassImportList* _call_py_importer_f(
450
445
451
446
/* Otherwise, we know our importer is well formed (because we wrap it)
452
447
* The return value will be a tuple of 1, 2, or 3 tuples */
453
- sass_imports = sass_make_import_list (PyTuple_Size ( py_result ) );
448
+ sass_imports = sass_make_import_list ();
454
449
for (i = 0 ; i < PyTuple_Size (py_result ); i += 1 ) {
450
+ struct SassImport * import = NULL ;
455
451
char * path_str = NULL ; /* XXX: Memory leak? */
456
452
char * source_str = NULL ;
457
453
char * sourcemap_str = NULL ;
@@ -477,9 +473,9 @@ static struct SassImportList* _call_py_importer_f(
477
473
if (source_str ) source_str = sass_copy_c_string (source_str );
478
474
if (sourcemap_str ) sourcemap_str = sass_copy_c_string (sourcemap_str );
479
475
480
- sass_imports [ i ] = sass_make_import_entry (
481
- path_str , source_str , sourcemap_str
482
- );
476
+ /* XXX: is this correct? source_map_str is gone? */
477
+ import = sass_make_content_import ( source_str , path_str );
478
+ sass_import_list_push ( sass_imports , import );
483
479
}
484
480
485
481
done :
@@ -493,40 +489,36 @@ static struct SassImportList* _call_py_importer_f(
493
489
}
494
490
495
491
static void _add_custom_importers (
496
- struct Sass_Options * options , PyObject * custom_importers
492
+ struct SassCompiler * compiler , PyObject * custom_importers
497
493
) {
498
- Py_ssize_t i ;
499
- Sass_Importer_List importer_list ;
500
-
501
494
if (custom_importers == Py_None ) {
502
495
return ;
503
496
}
504
497
505
- importer_list = sass_make_importer_list (PyTuple_Size (custom_importers ));
506
-
507
- for (i = 0 ; i < PyTuple_Size (custom_importers ); i += 1 ) {
498
+ for (Py_ssize_t i = 0 ; i < PyTuple_Size (custom_importers ); i += 1 ) {
499
+ struct SassImporter * importer ;
508
500
PyObject * item = PyTuple_GetItem (custom_importers , i );
509
501
int priority = 0 ;
510
502
PyObject * import_function = NULL ;
511
503
512
504
PyArg_ParseTuple (item , "iO" , & priority , & import_function );
513
505
514
- importer_list [ i ] = sass_make_importer (
506
+ importer = sass_make_importer (
515
507
_call_py_importer_f , priority , import_function
516
508
);
509
+ sass_compiler_add_custom_importer (compiler , importer );
517
510
}
518
-
519
- sass_option_set_c_importers (options , importer_list );
520
511
}
521
512
522
513
static PyObject *
523
514
PySass_compile_string (PyObject * self , PyObject * args ) {
524
- struct Sass_Context * ctx ;
525
- struct Sass_Data_Context * context ;
526
- struct Sass_Options * options ;
515
+ struct SassCompiler * compiler ;
516
+ struct SassImport * entry ;
517
+ const struct SassError * error ;
527
518
char * string , * include_paths ;
528
519
const char * error_message , * output_string ;
529
- enum Sass_Output_Style output_style ;
520
+ enum SassSrcMapMode srcmap_mode ;
521
+ enum SassOutputStyle output_style ;
530
522
int source_comments , error_status , precision , indented ,
531
523
source_map_embed , source_map_contents ,
532
524
omit_source_map_url ;
@@ -545,48 +537,67 @@ PySass_compile_string(PyObject *self, PyObject *args) {
545
537
return NULL ;
546
538
}
547
539
548
- context = sass_make_data_context (sass_copy_c_string (string ));
549
- options = sass_data_context_get_options (context );
550
- sass_option_set_output_style (options , output_style );
551
- sass_option_set_source_comments (options , source_comments );
552
- sass_option_set_include_path (options , include_paths );
553
- sass_option_set_precision (options , precision );
554
- sass_option_set_is_indented_syntax_src (options , indented );
555
- sass_option_set_source_map_contents (options , source_map_contents );
556
- sass_option_set_source_map_embed (options , source_map_embed );
557
- sass_option_set_omit_source_map_url (options , omit_source_map_url );
540
+ compiler = sass_make_compiler ();
541
+ sass_compiler_set_output_style (compiler , output_style );
542
+ sass_compiler_set_source_comments (compiler , source_comments );
543
+ sass_compiler_add_include_paths (compiler , include_paths );
544
+ sass_compiler_set_precision (compiler , precision );
545
+ /* XXX: this is probably wrong */
546
+ srcmap_mode = SASS_SRCMAP_NONE ;
547
+ if (source_map_contents ) {
548
+ srcmap_mode = SASS_SRCMAP_EMBED_LINK ;
549
+ }
550
+ if (source_map_embed ) {
551
+ srcmap_mode = SASS_SRCMAP_EMBED_JSON ;
552
+ }
553
+ if (srcmap_mode != SASS_SRCMAP_NONE ) {
554
+ sass_compiler_set_srcmap_embed_contents (compiler , !omit_source_map_url );
555
+ }
556
+ sass_compiler_set_srcmap_mode (compiler , srcmap_mode );
558
557
559
558
if (PyBytes_Check (source_map_root ) && PyBytes_Size (source_map_root )) {
560
- sass_option_set_source_map_root (
561
- options , PyBytes_AsString (source_map_root )
559
+ sass_compiler_set_srcmap_root (
560
+ compiler , PyBytes_AsString (source_map_root )
562
561
);
563
562
}
564
563
565
- _add_custom_functions (options , custom_functions );
566
- _add_custom_importers (options , custom_importers );
567
- sass_compile_data_context (context );
564
+ _add_custom_functions (compiler , custom_functions );
565
+ _add_custom_importers (compiler , custom_importers );
566
+
567
+ entry = sass_make_content_import (sass_copy_c_string (string ), NULL );
568
+ if (indented ) {
569
+ sass_import_set_format (entry , SASS_IMPORT_SASS );
570
+ } else {
571
+ sass_import_set_format (entry , SASS_IMPORT_SCSS );
572
+ }
573
+ sass_compiler_set_entry_point (compiler , entry );
574
+ sass_delete_import (entry );
575
+
576
+ sass_compiler_parse (compiler );
577
+ sass_compiler_compile (compiler );
578
+ sass_compiler_render (compiler );
568
579
569
- ctx = sass_data_context_get_context (context );
570
- error_status = sass_context_get_error_status (ctx );
571
- error_message = sass_context_get_error_message (ctx );
572
- output_string = sass_context_get_output_string (ctx );
580
+ error = sass_compiler_get_error (compiler );
581
+ error_status = sass_error_get_status (error );
582
+ output_string = sass_compiler_get_output_string (compiler );
573
583
result = Py_BuildValue (
574
584
PySass_IF_PY3 ("hy" , "hs" ),
575
585
(short int ) !error_status ,
576
- error_status ? error_message : output_string
586
+ error_status ? sass_error_get_formatted ( error ) : output_string
577
587
);
578
- sass_delete_data_context ( context );
588
+ sass_delete_compiler ( compiler );
579
589
return result ;
580
590
}
581
591
582
592
static PyObject *
583
593
PySass_compile_filename (PyObject * self , PyObject * args ) {
584
- struct Sass_Context * ctx ;
585
- struct Sass_File_Context * context ;
586
- struct Sass_Options * options ;
594
+ struct SassCompiler * compiler ;
595
+ struct SassImport * entry ;
596
+ const struct SassError * error ;
587
597
char * filename , * include_paths ;
588
- const char * error_message , * output_string , * source_map_string ;
589
- enum Sass_Output_Style output_style ;
598
+ const char * output_string , * source_map_string ;
599
+ enum SassSrcMapMode srcmap_mode ;
600
+ enum SassOutputStyle output_style ;
590
601
int source_comments , error_status , precision , source_map_embed ,
591
602
source_map_contents , omit_source_map_url ;
592
603
PyObject * source_map_filename , * custom_functions , * custom_importers ,
@@ -603,53 +614,66 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
603
614
return NULL ;
604
615
}
605
616
606
- context = sass_make_file_context (filename );
607
- options = sass_file_context_get_options (context );
617
+ compiler = sass_make_compiler ();
608
618
609
- if (PyBytes_Check (source_map_filename )) {
610
- if (PyBytes_Size (source_map_filename )) {
611
- sass_option_set_source_map_file (
612
- options , PyBytes_AsString (source_map_filename )
613
- );
614
- }
615
- }
616
619
if (PyBytes_Check (output_filename_hint )) {
617
620
if (PyBytes_Size (output_filename_hint )) {
618
- sass_option_set_output_path (
619
- options , PyBytes_AsString (output_filename_hint )
621
+ sass_compiler_set_output_path (
622
+ compiler , PyBytes_AsString (output_filename_hint )
620
623
);
621
624
}
622
625
}
623
626
624
627
if (PyBytes_Check (source_map_root ) && PyBytes_Size (source_map_root )) {
625
- sass_option_set_source_map_root (
626
- options , PyBytes_AsString (source_map_root )
628
+ sass_compiler_set_srcmap_root (
629
+ compiler , PyBytes_AsString (source_map_root )
627
630
);
628
631
}
629
632
630
- sass_option_set_output_style (options , output_style );
631
- sass_option_set_source_comments (options , source_comments );
632
- sass_option_set_include_path (options , include_paths );
633
- sass_option_set_precision (options , precision );
634
- sass_option_set_source_map_contents (options , source_map_contents );
635
- sass_option_set_source_map_embed (options , source_map_embed );
636
- sass_option_set_omit_source_map_url (options , omit_source_map_url );
637
- _add_custom_functions (options , custom_functions );
638
- _add_custom_importers (options , custom_importers );
639
- sass_compile_file_context (context );
640
-
641
- ctx = sass_file_context_get_context (context );
642
- error_status = sass_context_get_error_status (ctx );
643
- error_message = sass_context_get_error_message (ctx );
644
- output_string = sass_context_get_output_string (ctx );
645
- source_map_string = sass_context_get_source_map_string (ctx );
633
+ sass_compiler_set_output_style (compiler , output_style );
634
+ sass_compiler_set_source_comments (compiler , source_comments );
635
+ sass_compiler_add_include_paths (compiler , include_paths );
636
+ sass_compiler_set_precision (compiler , precision );
637
+ /* XXX: this is probably wrong */
638
+ srcmap_mode = SASS_SRCMAP_NONE ;
639
+ if (PyBytes_Check (source_map_filename ) && PyBytes_Size (source_map_filename )) {
640
+ srcmap_mode = SASS_SRCMAP_EMBED_LINK ;
641
+ sass_compiler_set_srcmap_path (
642
+ compiler , PyBytes_AsString (source_map_filename )
643
+ );
644
+ }
645
+ if (source_map_contents ) {
646
+ srcmap_mode = SASS_SRCMAP_EMBED_LINK ;
647
+ }
648
+ if (source_map_embed ) {
649
+ srcmap_mode = SASS_SRCMAP_EMBED_JSON ;
650
+ }
651
+ if (srcmap_mode != SASS_SRCMAP_NONE ) {
652
+ sass_compiler_set_srcmap_embed_contents (compiler , !omit_source_map_url );
653
+ }
654
+ sass_compiler_set_srcmap_mode (compiler , srcmap_mode );
655
+ _add_custom_functions (compiler , custom_functions );
656
+ _add_custom_importers (compiler , custom_importers );
657
+
658
+ entry = sass_make_file_import (sass_copy_c_string (filename ));
659
+ sass_compiler_set_entry_point (compiler , entry );
660
+ sass_delete_import (entry );
661
+
662
+ sass_compiler_parse (compiler );
663
+ sass_compiler_compile (compiler );
664
+ sass_compiler_render (compiler );
665
+
666
+ error = sass_compiler_get_error (compiler );
667
+ error_status = sass_error_get_status (error );
668
+ output_string = sass_compiler_get_output_string (compiler );
669
+ source_map_string = sass_compiler_get_srcmap_string (compiler );
646
670
result = Py_BuildValue (
647
671
PySass_IF_PY3 ("hyy" , "hss" ),
648
672
(short int ) !error_status ,
649
- error_status ? error_message : output_string ,
673
+ error_status ? sass_error_get_formatted ( error ) : output_string ,
650
674
error_status || source_map_string == NULL ? "" : source_map_string
651
675
);
652
- sass_delete_file_context ( context );
676
+ sass_delete_compiler ( compiler );
653
677
return result ;
654
678
}
655
679
0 commit comments