1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
mod api;
mod importer;
use std::{sync::Arc, time::SystemTime};
pub use api::*;
pub use importer::*;
use crate::{
Embedded, Exception, Importer, Options, Result, SassImporter, StringOptions,
};
impl Embedded {
pub fn render(&mut self, options: LegacyOptions) -> Result<LegacyResult> {
let start = SystemTime::now();
let entry = options
.file
.clone()
.map(|file| file.to_str().unwrap().to_string())
.unwrap_or_else(|| "stdin".to_string());
let mut options = options.adjust_options();
let result = if let Some(data) = options.data.clone() {
let this = LegacyPluginThis::new(&options);
let (importers, input_importer) =
if let Some(importers) = options.importers.take() {
let wrapper = LegacyImporterWrapper::new(
this,
importers,
options.include_paths.clone(),
&entry,
);
let importers = vec![SassImporter::Importer(Box::new(Arc::clone(
&wrapper,
))
as Box<dyn Importer>)];
let input_importer = Some(SassImporter::Importer(
Box::new(wrapper) as Box<dyn Importer>
));
(importers, input_importer)
} else {
(Vec::new(), None)
};
let mut options = StringOptions::from(options);
options.common.importers = importers;
options.input_importer = input_importer;
self.compile_string(data, options)
} else if let Some(file) = options.file.clone() {
let this = LegacyPluginThis::new(&options);
let importers = options
.importers
.take()
.map(|importers| {
let wrapper = LegacyImporterWrapper::new(
this,
importers,
options.include_paths.clone(),
&entry,
);
let importers = vec![SassImporter::Importer(Box::new(Arc::clone(
&wrapper,
))
as Box<dyn Importer>)];
importers
})
.unwrap_or_default();
let mut options = Options::from(options);
options.importers = importers;
self.compile(file, options)
} else {
Err(Exception::new(
"Either options.data or options.file must be set.",
))
}?;
Ok(LegacyResult::new(
if entry == "stdin" {
"data".to_string()
} else {
entry
},
start,
result,
))
}
}