@@ -3,55 +3,49 @@ use std::{
3
3
path:: { Path , PathBuf } ,
4
4
} ;
5
5
6
+ #[ cfg( feature = "serde" ) ]
7
+ use serde:: { Deserialize , Serialize } ;
8
+
6
9
use crate :: {
7
10
protocol:: {
11
+ self ,
8
12
outbound_message:: {
9
13
compile_response:: { self , CompileSuccess } ,
10
14
CompileResponse ,
11
15
} ,
12
- OutputStyle , SourceSpan , Syntax ,
13
16
} ,
14
17
Exception , Result , Url ,
15
18
} ;
16
19
17
20
/// Options that can be passed to [Sass::compile].
18
21
///
19
- /// More information:
20
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options)
22
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options)
23
+ # [ cfg_attr ( feature = "serde" , derive ( Serialize , Deserialize ) ) ]
21
24
#[ derive( Debug ) ]
22
25
pub struct Options {
23
- /// More information:
24
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#alertAscii)
26
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#alertAscii)
25
27
pub alert_ascii : bool ,
26
- /// More information:
27
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#alertColor)
28
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#alertColor)
28
29
pub alert_color : Option < bool > ,
29
- /// More information:
30
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#importers)
30
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#importers)
31
+ # [ serde ( skip ) ]
31
32
pub importers : Vec < SassImporter > ,
32
- /// More information:
33
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#loadPaths)
33
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#loadPaths)
34
34
pub load_paths : Vec < PathBuf > ,
35
- /// More information:
36
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#logger)
35
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#logger)
36
+ # [ serde ( skip ) ]
37
37
pub logger : Option < BoxedLogger > ,
38
- /// More information:
39
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#quietDeps)
38
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#quietDeps)
40
39
pub quiet_deps : bool ,
41
- /// More information:
42
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#sourceMap)
40
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#sourceMap)
43
41
pub source_map : bool ,
44
- /// More information:
45
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#sourceMapIncludeSources)
42
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#sourceMapIncludeSources)
46
43
pub source_map_include_sources : bool ,
47
- /// More information:
48
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#style)
44
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#style)
49
45
pub style : OutputStyle ,
50
- /// More information:
51
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#verbose)
46
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#verbose)
52
47
pub verbose : bool ,
53
- /// More information:
54
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#charset)
48
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options#charset)
55
49
pub charset : bool ,
56
50
}
57
51
@@ -192,21 +186,19 @@ impl OptionsBuilder {
192
186
193
187
/// Options that can be passed to [Sass::compile_string].
194
188
///
195
- /// More information:
196
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/modules#StringOptions)
189
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/modules#StringOptions)
190
+ # [ cfg_attr ( feature = "serde" , derive ( Serialize , Deserialize ) ) ]
197
191
#[ derive( Debug , Default ) ]
198
192
pub struct StringOptions {
199
193
/// Field for [Options]
200
194
pub common : Options ,
201
- /// More information:
202
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/StringOptionsWithImporter#importer)
195
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/StringOptionsWithImporter#importer)
196
+ # [ serde ( skip ) ]
203
197
pub input_importer : Option < SassImporter > ,
204
- /// More information:
205
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/StringOptionsWithoutImporter#syntax)
198
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/StringOptionsWithoutImporter#syntax)
206
199
/// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/StringOptionsWithImporter#syntax)
207
200
pub syntax : Syntax ,
208
- /// More information:
209
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/StringOptionsWithoutImporter#url)
201
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/StringOptionsWithoutImporter#url)
210
202
/// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/StringOptionsWithImporter#url)
211
203
pub url : Option < Url > ,
212
204
}
@@ -373,26 +365,22 @@ impl StringOptionsBuilder {
373
365
/// A type alias for [Box<dyn Logger>].
374
366
pub type BoxedLogger = Box < dyn Logger > ;
375
367
376
- /// More information
377
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger)
368
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger)
378
369
pub trait Logger : Debug + Send + Sync {
379
- /// More information
380
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger#warn)
370
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger#warn)
381
371
fn warn ( & self , _message : & str , options : & LoggerWarnOptions ) {
382
372
eprintln ! ( "{}" , options. formatted) ;
383
373
}
384
374
385
- /// More information
386
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger#debug)
375
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger#debug)
387
376
fn debug ( & self , _message : & str , options : & LoggerDebugOptions ) {
388
377
eprintln ! ( "{}" , options. formatted) ;
389
378
}
390
379
}
391
380
392
381
/// Options for [Logger::warn].
393
382
///
394
- /// More information
395
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger#warn)
383
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger#warn)
396
384
pub struct LoggerWarnOptions {
397
385
/// Whether this is a deprecation warning.
398
386
pub deprecation : bool ,
@@ -405,8 +393,7 @@ pub struct LoggerWarnOptions {
405
393
406
394
/// Options for [Logger::debug].
407
395
///
408
- /// More information
409
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger#debug)
396
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Logger#debug)
410
397
pub struct LoggerDebugOptions {
411
398
/// The location in the Sass source code that generated this debug message.
412
399
pub span : Option < SourceSpan > ,
@@ -428,70 +415,57 @@ pub type BoxedImporter = Box<dyn Importer>;
428
415
/// A type alias for [Box<dyn FileImporter>].
429
416
pub type BoxedFileImporter = Box < dyn FileImporter > ;
430
417
431
- /// More information
432
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Importer)
418
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Importer)
433
419
pub trait Importer : Debug + Send + Sync {
434
- /// More information
435
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Importer#canonicalize)
420
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Importer#canonicalize)
436
421
fn canonicalize (
437
422
& self ,
438
423
url : & str ,
439
424
options : & ImporterOptions ,
440
425
) -> Result < Option < Url > > ;
441
426
442
- /// More information
443
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Importer#load)
427
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Importer#load)
444
428
fn load ( & self , canonical_url : & Url ) -> Result < Option < ImporterResult > > ;
445
429
}
446
430
447
431
/// Options for [Importer::canonicalize] or [Importer::load].
448
432
///
449
- /// More information
450
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Importer#canonicalize)
433
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Importer#canonicalize)
451
434
pub struct ImporterOptions {
452
435
/// Whether this is being invoked because of a Sass @import rule, as opposed to a @use
453
436
/// or @forward rule.
454
437
pub from_import : bool ,
455
438
}
456
439
457
- /// More information
458
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/FileImporter)
440
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/FileImporter)
459
441
pub trait FileImporter : Debug + Send + Sync {
460
- /// More information
461
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/FileImporter#findFileUrl)
442
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/FileImporter#findFileUrl)
462
443
fn find_file_url (
463
444
& self ,
464
445
url : & str ,
465
446
options : & ImporterOptions ,
466
447
) -> Result < Option < Url > > ;
467
448
}
468
449
469
- /// More information
470
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/ImporterResult)
450
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/ImporterResult)
471
451
pub struct ImporterResult {
472
- /// More information
473
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#contents)
452
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#contents)
474
453
pub contents : String ,
475
- /// More information
476
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#sourceMapUrl)
454
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#sourceMapUrl)
477
455
pub source_map_url : Option < Url > ,
478
- /// More information
479
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#syntax)
456
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/ImporterResult#syntax)
480
457
pub syntax : Syntax ,
481
458
}
482
459
483
- /// More information
484
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/CompileResult)
460
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/CompileResult)
461
+ # [ cfg_attr ( feature = "serde" , derive ( Serialize , Deserialize ) ) ]
485
462
#[ derive( Debug , Clone ) ]
486
463
pub struct CompileResult {
487
- /// More information
488
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/CompileResult#css)
464
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/CompileResult#css)
489
465
pub css : String ,
490
- /// More information
491
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/CompileResult#loadedUrls)
466
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/CompileResult#loadedUrls)
492
467
pub loaded_urls : Vec < Url > ,
493
- /// More information
494
- /// - [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/CompileResult#sourceMap)
468
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/CompileResult#sourceMap)
495
469
pub source_map : Option < String > ,
496
470
}
497
471
@@ -526,3 +500,111 @@ impl From<CompileSuccess> for CompileResult {
526
500
}
527
501
}
528
502
}
503
+
504
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/modules#OutputStyle)
505
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
506
+ #[ derive( Debug ) ]
507
+ pub enum OutputStyle {
508
+ /// Writes each selector and declaration on its own line.
509
+ Expanded ,
510
+ /// Removes as many extra characters as possible, and writes the entire stylesheet on a single line.
511
+ Compressed ,
512
+ }
513
+
514
+ impl Default for OutputStyle {
515
+ fn default ( ) -> Self {
516
+ Self :: Expanded
517
+ }
518
+ }
519
+
520
+ impl From < OutputStyle > for protocol:: OutputStyle {
521
+ fn from ( o : OutputStyle ) -> Self {
522
+ match o {
523
+ OutputStyle :: Expanded => Self :: Expanded ,
524
+ OutputStyle :: Compressed => Self :: Compressed ,
525
+ }
526
+ }
527
+ }
528
+
529
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/modules#Syntax)
530
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
531
+ #[ derive( Debug ) ]
532
+ pub enum Syntax {
533
+ /// the [scss syntax](https://sass-lang.com/documentation/syntax#scss)
534
+ Scss ,
535
+ /// the [indented syntax](https://sass-lang.com/documentation/syntax#the-indented-syntax)
536
+ Indented ,
537
+ /// the plain css syntax, which is parsed like SCSS but forbids the use of any special Sass features.
538
+ Css ,
539
+ }
540
+
541
+ impl Default for Syntax {
542
+ fn default ( ) -> Self {
543
+ Self :: Scss
544
+ }
545
+ }
546
+
547
+ impl From < Syntax > for protocol:: Syntax {
548
+ fn from ( s : Syntax ) -> Self {
549
+ match s {
550
+ Syntax :: Scss => Self :: Scss ,
551
+ Syntax :: Indented => Self :: Indented ,
552
+ Syntax :: Css => Self :: Css ,
553
+ }
554
+ }
555
+ }
556
+
557
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/SourceSpan)
558
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
559
+ #[ derive( Debug ) ]
560
+ pub struct SourceSpan {
561
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/SourceSpan#context)
562
+ pub context : Option < String > ,
563
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/SourceSpan#end)
564
+ pub end : SourceLocation ,
565
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/SourceSpan#start)
566
+ pub start : SourceLocation ,
567
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/SourceSpan#url)
568
+ pub url : Option < Url > ,
569
+ /// More information: [Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/SourceSpan#text)
570
+ pub text : String ,
571
+ }
572
+
573
+ impl From < protocol:: SourceSpan > for SourceSpan {
574
+ fn from ( span : protocol:: SourceSpan ) -> Self {
575
+ let start = span. start . unwrap ( ) ;
576
+ Self {
577
+ context : if span. context . is_empty ( ) {
578
+ None
579
+ } else {
580
+ Some ( span. context )
581
+ } ,
582
+ end : span. end . unwrap_or_else ( || start. clone ( ) ) . into ( ) ,
583
+ start : start. into ( ) ,
584
+ url : if span. url . is_empty ( ) {
585
+ None
586
+ } else {
587
+ Some ( Url :: parse ( & span. url ) . unwrap ( ) )
588
+ } ,
589
+ text : span. text ,
590
+ }
591
+ }
592
+ }
593
+
594
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
595
+ #[ derive( Debug ) ]
596
+ pub struct SourceLocation {
597
+ pub offset : usize ,
598
+ pub line : usize ,
599
+ pub column : usize ,
600
+ }
601
+
602
+ impl From < protocol:: source_span:: SourceLocation > for SourceLocation {
603
+ fn from ( location : protocol:: source_span:: SourceLocation ) -> Self {
604
+ Self {
605
+ offset : location. offset as usize ,
606
+ line : location. line as usize ,
607
+ column : location. column as usize ,
608
+ }
609
+ }
610
+ }
0 commit comments