diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/minifier/src/css/mod.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/minifier/src/css/mod.rs')
-rw-r--r-- | vendor/minifier/src/css/mod.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/minifier/src/css/mod.rs b/vendor/minifier/src/css/mod.rs new file mode 100644 index 000000000..224ad8126 --- /dev/null +++ b/vendor/minifier/src/css/mod.rs @@ -0,0 +1,40 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use std::{fmt, io}; + +mod token; + +/// Minifies a given CSS source code. +/// +/// # Example +/// +/// ```rust +/// use minifier::css::minify; +/// +/// let css = r#" +/// .foo > p { +/// color: red; +/// }"#.into(); +/// let css_minified = minify(css).expect("minification failed"); +/// assert_eq!(&css_minified.to_string(), ".foo>p{color:red;}"); +/// ``` +pub fn minify<'a>(content: &'a str) -> Result<Minified<'a>, &'static str> { + token::tokenize(content).map(Minified) +} + +pub struct Minified<'a>(token::Tokens<'a>); + +impl<'a> Minified<'a> { + pub fn write<W: io::Write>(self, w: W) -> io::Result<()> { + self.0.write(w) + } +} + +impl<'a> fmt::Display for Minified<'a> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +#[cfg(test)] +mod tests; |