From 2885724931cb5620cc79402b12086a02293ee120 Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Sat, 7 Aug 2021 14:56:20 +1000 Subject: [PATCH] Make Cfg values all default false --- src/cfg/mod.rs | 26 ++++++++++++++++++------ src/lib.rs | 13 +++--------- src/minify/comment.rs | 2 +- src/minify/element.rs | 7 +++---- src/parse/element.rs | 3 +-- src/tests/mod.rs | 46 +++++++------------------------------------ 6 files changed, 35 insertions(+), 62 deletions(-) diff --git a/src/cfg/mod.rs b/src/cfg/mod.rs index 88f194d..fe40d72 100644 --- a/src/cfg/mod.rs +++ b/src/cfg/mod.rs @@ -15,14 +15,28 @@ pub struct Cfg { /// enabled; otherwise, this value has no effect. pub minify_css: bool, - /// Omit closing tags when possible. - pub omit_closing_tags: bool, - /// Remove spaces between attributes when possible (may result in invalid HTML). - pub remove_spaces_between_attributes: bool, - /// Remove all comments. - pub remove_comments: bool, + /// Do not omit closing tags when possible. + pub keep_closing_tags: bool, + /// Keep spaces between attributes when possible to conform to HTML standards. + pub keep_spaces_between_attributes: bool, + /// Keep all comments. + pub keep_comments: bool, /// Remove all bangs. pub remove_bangs: bool, /// Remove all processing_instructions. pub remove_processing_instructions: bool, } + +impl Cfg { + pub fn new() -> Cfg { + Cfg { + keep_closing_tags: false, + keep_comments: false, + keep_spaces_between_attributes: false, + minify_css: false, + minify_js: false, + remove_bangs: false, + remove_processing_instructions: false, + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 46ac75a..9a3c7b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,16 +30,9 @@ mod whitespace; /// use minify_html::{Cfg, minify}; /// /// let mut code: &[u8] = b"

Hello, world!

"; -/// let cfg = &Cfg { -/// minify_css: false, -/// minify_js: false, -/// omit_closing_tags: true, -/// remove_bangs: false, -/// remove_comments: true, -/// remove_processing_instructions: false, -/// remove_spaces_between_attributes: true, -/// }; -/// let minified = minify(&code, cfg); +/// let mut cfg = Cfg::new(); +/// cfg.keep_comments = true; +/// let minified = minify(&code, &cfg); /// assert_eq!(minified, b"

Hello, world!".to_vec()); /// ``` pub fn minify(src: &[u8], cfg: &Cfg) -> Vec { diff --git a/src/minify/comment.rs b/src/minify/comment.rs index 0ab2733..317fb04 100644 --- a/src/minify/comment.rs +++ b/src/minify/comment.rs @@ -1,7 +1,7 @@ use crate::cfg::Cfg; pub fn minify_comment(cfg: &Cfg, out: &mut Vec, code: &[u8], ended: bool) { - if !cfg.remove_comments { + if cfg.keep_comments { out.extend_from_slice(b"