accent_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<accent_sass::Error>> {
18 let css = accent_sass::from_string(
19 "a { b { color: &; } }".to_owned(),
20 &accent_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 accent-sass
30accent-sass 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
68#[cfg(feature = "wasi-exports")]
69pub mod wasi_exports;
70
71pub use accent_sass_compiler::{
72 Deprecation, DeprecationWarning, Error, ErrorKind, Fs, InputSyntax, Logger, MemoryFs, NullFs,
73 NullLogger, Options, OutputStyle, Result, StdFs, StdLogger, from_path, from_string,
74 from_string_with_file_name,
75};
76
77/// Include CSS in your binary at compile time from a Sass source file
78///
79/// `static CSS: &str = accent_sass::include!("../static/_index.scss");`
80///
81/// This requires the `"macro"` feature, which is not enabled by default.
82///
83/// By default `accent-sass` will track files using [`include_str!`]. This allows incremental
84/// compilation to be updated when any Sass files are modified.
85///
86/// If compiling with a nightly version of rust, `accent-sass` can make use of
87/// [proc_macro::tracked_path](https://github.com/rust-lang/rust/issues/99515)
88/// in order to force incremental recompilation, which is more robust and potentially
89/// faster. This is enabled by the `"nightly"` feature.
90///
91/// ###### Limitations
92///
93/// Compilation options are not configurable with this macro. The default values
94/// for all options are used, except for output style, which is compressed.
95#[macro_export]
96#[cfg(any(feature = "macro", doc))]
97#[cfg_attr(doc_cfg, doc(cfg(feature = "macro")))]
98macro_rules! include {
99 ($path:literal) => {
100 $crate::__internal::accent_sass_macro::include_sass!($path);
101 };
102}
103
104#[doc(hidden)]
105#[cfg(feature = "macro")]
106pub mod __internal {
107 #[doc(hidden)]
108 pub use accent_sass_macro;
109}