grass/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<grass::Error>> {
18 let css = grass::from_string(
19 "a { b { color: &; } }".to_owned(),
20 &grass::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 grass
30grass input.scss
31```
32*/
33
34#![cfg_attr(doc_cfg, feature(doc_cfg))]
35#![warn(clippy::all, clippy::cargo, clippy::dbg_macro)]
36#![deny(missing_debug_implementations)]
37#![allow(
38 clippy::use_self,
39 // filter isn't fallible
40 clippy::manual_filter_map,
41 renamed_and_removed_lints,
42 clippy::unknown_clippy_lints,
43 clippy::single_match,
44 clippy::new_without_default,
45 clippy::single_match_else,
46 clippy::multiple_crate_versions,
47 clippy::wrong_self_convention,
48 clippy::comparison_chain,
49
50 // these features are only available on nightly
51 clippy::unnested_or_patterns,
52 clippy::uninlined_format_args,
53
54 // todo: these should be enabled
55 clippy::cast_sign_loss,
56 clippy::cast_lossless,
57 clippy::cast_precision_loss,
58 clippy::float_cmp,
59
60 // todo: unignore once we bump MSRV
61 clippy::format_push_string,
62 clippy::unnecessary_unwrap,
63 clippy::needless_late_init,
64
65 unknown_lints,
66)]
67
68pub use grass_compiler::{
69 from_path, from_string, Error, ErrorKind, Fs, InputSyntax, Logger, NullFs, NullLogger, Options,
70 OutputStyle, Result, StdFs, StdLogger,
71};
72
73/// Include CSS in your binary at compile time from a Sass source file
74///
75/// `static CSS: &str = grass::include!("../static/_index.scss");`
76///
77/// This requires the `"macro"` feature, which is not enabled by default.
78///
79/// By default `grass` will track files using [`include_str!`]. This allows incremental
80/// compilation to be updated when any Sass files are modified.
81///
82/// If compiling with a nightly version of rust, `grass` can make use of
83/// [proc_macro::tracked_path](https://github.com/rust-lang/rust/issues/99515)
84/// in order to force incremental recompilation, which is more robust and potentially
85/// faster. This is enabled by the `"nightly"` feature.
86///
87/// ###### Limitations
88///
89/// Compilation options are not configurable with this macro. The default values
90/// for all options are used, except for output style, which is compressed.
91#[macro_export]
92#[cfg(any(feature = "macro", doc))]
93#[cfg_attr(doc_cfg, doc(cfg(feature = "macro")))]
94macro_rules! include {
95 ($path:literal) => {
96 $crate::__internal::include_sass::include_sass!($path);
97 };
98}
99
100#[doc(hidden)]
101#[cfg(feature = "macro")]
102pub mod __internal {
103 #[doc(hidden)]
104 pub use include_sass;
105}