Skip to main content

fugo_sass/
lib.rs

1/*!
2This crate provides functionality for compiling [Sass](https://sass-lang.com/) to CSS.
3
4This crate targets compatibility with the reference implementation in Dart. If
5upgrading from the [now deprecated](https://sass-lang.com/blog/libsass-is-deprecated)
6`libsass`, one may have to modify their stylesheets. These changes will not differ
7from those necessary to upgrade to `dart-sass`, and in general such changes should
8be quite rare.
9
10This crate is capable of compiling Bootstrap 4 and 5, bulma and bulma-scss, Bourbon,
11as well as most other large Sass libraries with complete accuracy. For the vast
12majority of use cases there should be no perceptible differences from the reference
13implementation.
14
15## Use as library
16```
17fn main() -> Result<(), Box<fugo_sass::Error>> {
18    let css = fugo_sass::from_string(
19        "a { b { color: &; } }".to_owned(),
20        &fugo_sass::Options::default()
21    )?;
22    assert_eq!(css, "a b {\n  color: a b;\n}\n");
23    Ok(())
24}
25```
26
27## Use as binary
28```bash
29cargo install fugo-sass
30fugo-sass input.scss
31```
32*/
33
34#![cfg_attr(docsrs, feature(doc_cfg))]
35#![warn(clippy::all, clippy::cargo, clippy::dbg_macro)]
36#![deny(missing_debug_implementations)]
37#![forbid(unsafe_code)]
38#![allow(
39    clippy::use_self,
40    // filter isn't fallible
41    clippy::manual_filter_map,
42    renamed_and_removed_lints,
43    clippy::unknown_clippy_lints,
44    clippy::single_match,
45    clippy::new_without_default,
46    clippy::single_match_else,
47    clippy::multiple_crate_versions,
48    clippy::wrong_self_convention,
49    clippy::comparison_chain,
50
51    // these features are only available on nightly
52    clippy::unnested_or_patterns,
53    clippy::uninlined_format_args,
54
55    // todo: these should be enabled
56    clippy::cast_sign_loss,
57    clippy::cast_lossless,
58    clippy::cast_precision_loss,
59    clippy::float_cmp,
60
61    // todo: unignore once we bump MSRV
62    clippy::format_push_string,
63    clippy::unnecessary_unwrap,
64    clippy::needless_late_init,
65
66    unknown_lints,
67)]
68
69pub use fugo_sass_compiler::{
70    Error, ErrorKind, Fs, InputSyntax, Logger, NullFs, NullLogger, Options, OutputStyle, Result,
71    StdFs, StdLogger, from_path, from_string,
72};
73
74/// Include CSS in your binary at compile time from a Sass source file
75///
76/// `static CSS: &str = fugo_sass::include!("../static/_index.scss");`
77///
78/// This requires the `"macro"` feature, which is not enabled by default.
79///
80/// By default `fugo-sass` will track files using [`include_str!`]. This allows incremental
81/// compilation to be updated when any Sass files are modified.
82///
83/// If compiling with a nightly version of rust, `fugo-sass` can make use of
84/// [proc_macro::tracked_path](https://github.com/rust-lang/rust/issues/99515)
85/// in order to force incremental recompilation, which is more robust and potentially
86/// faster. This is enabled by the `"nightly"` feature.
87///
88/// ###### Limitations
89///
90/// Compilation options are not configurable with this macro. The default values
91/// for all options are used, except for output style, which is compressed.
92#[macro_export]
93#[cfg(any(feature = "macro", doc))]
94#[cfg_attr(docsrs, doc(cfg(feature = "macro")))]
95macro_rules! include {
96    ($path:literal) => {
97        $crate::__internal::fugo_sass_macro::include_sass!($path)
98    };
99}
100
101#[doc(hidden)]
102#[cfg(feature = "macro")]
103pub mod __internal {
104    #[doc(hidden)]
105    pub use fugo_sass_macro;
106}