sass_rs/bindings/
options.rs

1use std::ffi;
2
3use sass_sys::{self, Sass_Output_Style};
4
5use bindings::ptr::Unique;
6
7use options::OutputStyle;
8
9/// The internal options we will pass to libsass
10#[derive(Debug)]
11pub struct SassOptions {
12    pub raw: Unique<sass_sys::Sass_Options>
13}
14
15impl SassOptions {
16    pub fn set_output_style(&mut self, style: OutputStyle) {
17        let style = match style {
18            OutputStyle::Nested => Sass_Output_Style::SASS_STYLE_NESTED,
19            OutputStyle::Expanded => Sass_Output_Style::SASS_STYLE_EXPANDED,
20            OutputStyle::Compact => Sass_Output_Style::SASS_STYLE_COMPACT,
21            OutputStyle::Compressed => Sass_Output_Style::SASS_STYLE_COMPRESSED,
22        };
23
24        unsafe {
25            sass_sys::sass_option_set_output_style(self.raw.get_mut(), style);
26        }
27    }
28
29    pub fn set_precision(&mut self, precision: usize) {
30        unsafe {
31            sass_sys::sass_option_set_precision(self.raw.get_mut(), precision as i32);
32        }
33    }
34
35    pub fn set_is_indented_syntax(&mut self) {
36        unsafe {
37            sass_sys::sass_option_set_is_indented_syntax_src(self.raw.get_mut(), true);
38        }
39    }
40
41    pub fn set_include_path(&mut self, paths: Vec<String>) {
42        let include_path = if cfg!(windows) {
43            paths.join(";")
44        } else {
45            paths.join(":")
46        };
47        let c_str = ffi::CString::new(include_path).unwrap();
48        let ptr = c_str.into_raw();
49        unsafe {
50            sass_sys::sass_option_set_include_path(self.raw.get_mut(), ptr);
51            let _ = ffi::CString::from_raw(ptr);
52        }
53    }
54}