From 8bb64b31f006a9dfa206f57ae741b87b08f1c376 Mon Sep 17 00:00:00 2001 From: Mnwa Date: Sat, 17 Aug 2024 18:17:06 +0300 Subject: [PATCH] Make minifier shareable --- css-minifier-web/src/main.rs | 10 +++++---- css-minify/src/optimizations/font.rs | 8 +++---- css-minify/src/optimizations/merge_blocks.rs | 16 +++++++------- css-minify/src/optimizations/merge_m_n_p.rs | 16 +++++++------- css-minify/src/optimizations/merge_media.rs | 22 +++++++++---------- .../src/optimizations/merge_shorthand.rs | 20 ++++++++--------- css-minify/src/optimizations/transformer.rs | 6 ++--- 7 files changed, 50 insertions(+), 48 deletions(-) diff --git a/css-minifier-web/src/main.rs b/css-minifier-web/src/main.rs index 5947615..d2be966 100644 --- a/css-minifier-web/src/main.rs +++ b/css-minifier-web/src/main.rs @@ -24,7 +24,9 @@ async fn minify_css( minifier: web::Data, ) -> impl Responder { let level = Level::from_str(&request.level).unwrap_or(Level::One); - let output_css = minifier.minify(&request.input_css, level).unwrap_or_else(|e| e.to_string()); + let output_css = minifier + .minify(&request.input_css, level) + .unwrap_or_else(|e| e.to_string()); match Template::call(&IndexTemplate { input_css: Some(request.into_inner().input_css), @@ -73,9 +75,9 @@ async fn main() -> std::io::Result<()> { .service(minify_css) .service(main_css) }) - .bind(std::env::var("HTTP_HOST").unwrap_or_else(|_| "0.0.0.0:8081".into()))? - .run() - .await + .bind(std::env::var("HTTP_HOST").unwrap_or_else(|_| "0.0.0.0:8081".into()))? + .run() + .await } struct MinifiedCss { diff --git a/css-minify/src/optimizations/font.rs b/css-minify/src/optimizations/font.rs index 3ea98fd..5574c96 100644 --- a/css-minify/src/optimizations/font.rs +++ b/css-minify/src/optimizations/font.rs @@ -34,25 +34,25 @@ mod test { Some(Selector::Class("test".into())), vec![], )] - .into(), + .into(), parameters: { let mut tmp = IndexMap::new(); tmp.insert("font-weight".into(), "bold".into()); tmp.into() }, - }), ])), + }),])), CssEntities(vec![CssEntity::Block(Block { selectors: vec![SelectorWithPseudoClasses( Some(Selector::Class("test".into())), vec![], )] - .into(), + .into(), parameters: { let mut tmp = IndexMap::new(); tmp.insert("font-weight".into(), "700".into()); tmp.into() }, - }), ]) + }),]) ) } } diff --git a/css-minify/src/optimizations/merge_blocks.rs b/css-minify/src/optimizations/merge_blocks.rs index ae62c41..c0a8ade 100644 --- a/css-minify/src/optimizations/merge_blocks.rs +++ b/css-minify/src/optimizations/merge_blocks.rs @@ -43,15 +43,15 @@ impl Transform for MergeBlocks { screen, entities: self.transform_many(entities), } - .into(), + .into(), CssEntity::Supports(Supports { - conditions, - entities, - }) => Supports { + conditions, + entities, + }) => Supports { conditions, entities: self.transform_many(entities), } - .into(), + .into(), entity => entity, }) .collect(), @@ -79,7 +79,7 @@ mod test { Some(Selector::Class("test".into())), vec![] )] - .into(), + .into(), parameters: { let mut tmp = IndexMap::new(); tmp.insert("background-color".into(), "#f64e60 !important".into()); @@ -91,7 +91,7 @@ mod test { Some(Selector::Class("test".into())), vec![] )] - .into(), + .into(), parameters: { let mut tmp = IndexMap::new(); tmp.insert("color".into(), "#f64e60 !important".into()); @@ -104,7 +104,7 @@ mod test { Some(Selector::Class("test".into())), vec![] )] - .into(), + .into(), parameters: { let mut tmp = IndexMap::new(); tmp.insert("background-color".into(), "#f64e60 !important".into()); diff --git a/css-minify/src/optimizations/merge_m_n_p.rs b/css-minify/src/optimizations/merge_m_n_p.rs index 43f1840..0242afd 100644 --- a/css-minify/src/optimizations/merge_m_n_p.rs +++ b/css-minify/src/optimizations/merge_m_n_p.rs @@ -235,7 +235,7 @@ mod test { Parameters(map) }, } - .into() + .into() ), Block { selectors: Selectors::default(), @@ -245,7 +245,7 @@ mod test { Parameters(map) }, } - .into() + .into() ) } @@ -264,7 +264,7 @@ mod test { Parameters(map) }, } - .into() + .into() ), Block { selectors: Selectors::default(), @@ -274,7 +274,7 @@ mod test { Parameters(map) }, } - .into() + .into() ) } @@ -293,7 +293,7 @@ mod test { Parameters(map) }, } - .into() + .into() ), Block { selectors: Selectors::default(), @@ -303,7 +303,7 @@ mod test { Parameters(map) }, } - .into() + .into() ) } @@ -322,7 +322,7 @@ mod test { Parameters(map) }, } - .into() + .into() ), Block { selectors: Selectors::default(), @@ -332,7 +332,7 @@ mod test { Parameters(map) }, } - .into() + .into() ) } } diff --git a/css-minify/src/optimizations/merge_media.rs b/css-minify/src/optimizations/merge_media.rs index 7b5b4ec..104ae22 100644 --- a/css-minify/src/optimizations/merge_media.rs +++ b/css-minify/src/optimizations/merge_media.rs @@ -47,13 +47,13 @@ impl Transform for MergeMedia { .filter(|e| !matches!(e, CssEntity::Media(_))) .map(|e| match e { CssEntity::Supports(Supports { - conditions, - entities, - }) => Supports { + conditions, + entities, + }) => Supports { conditions, entities: self.transform_many(entities), } - .into(), + .into(), entity => entity, }) .collect(), @@ -88,10 +88,10 @@ mod test { Some(Selector::Class("test".into())), vec![] )] - .into(), + .into(), parameters: Default::default() })] - .into() + .into() }), CssEntity::Media(Media { screen: Value::from("only screen and (max-width: 992px)"), @@ -100,10 +100,10 @@ mod test { Some(Selector::Class("test2".into())), vec![] )] - .into(), + .into(), parameters: Default::default() })] - .into() + .into() }) ])), CssEntities(vec![CssEntity::Media(Media { @@ -114,7 +114,7 @@ mod test { Some(Selector::Class("test".into())), vec![] )] - .into(), + .into(), parameters: Default::default() }), CssEntity::Block(Block { @@ -122,11 +122,11 @@ mod test { Some(Selector::Class("test2".into())), vec![] )] - .into(), + .into(), parameters: Default::default() }) ] - .into() + .into() })]) ) } diff --git a/css-minify/src/optimizations/merge_shorthand.rs b/css-minify/src/optimizations/merge_shorthand.rs index a673bb5..14cf0f8 100644 --- a/css-minify/src/optimizations/merge_shorthand.rs +++ b/css-minify/src/optimizations/merge_shorthand.rs @@ -508,7 +508,7 @@ mod test { Parameters(map) }, } - .into() + .into() ), Block { selectors: Selectors::default(), @@ -521,7 +521,7 @@ mod test { Parameters(map) }, } - .into() + .into() ) } @@ -540,7 +540,7 @@ mod test { Parameters(map) }, } - .into() + .into() ), Block { selectors: Selectors::default(), @@ -553,7 +553,7 @@ mod test { Parameters(map) }, } - .into() + .into() ) } @@ -569,7 +569,7 @@ mod test { Parameters(map) }, } - .into() + .into() ), Block { selectors: Selectors::default(), @@ -579,7 +579,7 @@ mod test { Parameters(map) }, } - .into() + .into() ) } @@ -597,7 +597,7 @@ mod test { Parameters(map) }, } - .into() + .into() ), Block { selectors: Selectors::default(), @@ -607,7 +607,7 @@ mod test { Parameters(map) }, } - .into() + .into() ) } @@ -625,7 +625,7 @@ mod test { Parameters(map) }, } - .into() + .into() ), Block { selectors: Selectors::default(), @@ -635,7 +635,7 @@ mod test { Parameters(map) }, } - .into() + .into() ) } } diff --git a/css-minify/src/optimizations/transformer.rs b/css-minify/src/optimizations/transformer.rs index e0ad5ef..c347d4d 100644 --- a/css-minify/src/optimizations/transformer.rs +++ b/css-minify/src/optimizations/transformer.rs @@ -56,9 +56,9 @@ pub trait Transform { .into(), }), CssEntity::Supports(Supports { - conditions, - entities, - }) => CssEntity::Supports(Supports { + conditions, + entities, + }) => CssEntity::Supports(Supports { conditions, entities: entities .0