diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 8e0f7213e..793bca68f 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -137,7 +137,7 @@ jobs: - name: Run website code snippet tests run: | - cd packages/website-test + cd tools/website-test cargo test integration_tests: diff --git a/Cargo.toml b/Cargo.toml index 6b6177b5b..de23a7e92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,9 @@ [workspace] members = [ + # Packages "packages/yew", "packages/yew-macro", - "packages/yew-validation", "packages/yew-agent", - - # Router "packages/yew-router", "packages/yew-router-macro", @@ -35,9 +33,10 @@ members = [ "examples/webgl", "examples/web_worker_fib", - # Release tools - "packages/changelog", + # Tools + "tools/changelog", ] exclude = [ - "packages/website-test", + # Tools + "tools/website-test", ] diff --git a/Makefile.toml b/Makefile.toml index 076d45a8d..7f4a7ea26 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -97,7 +97,7 @@ args = ["test", "--doc"] [tasks.website-test] script = [ """ - cd packages/website-test + cd tools/website-test cargo test """ ] diff --git a/packages/yew-validation/Cargo.toml b/packages/yew-validation/Cargo.toml deleted file mode 100644 index 29f90876e..000000000 --- a/packages/yew-validation/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "yew-validation" -version = "0.1.0" -authors = ["Philip Peterson "] -edition = "2018" -license = "MIT OR Apache-2.0" -keywords = ["web", "yew", "validation"] -categories = ["text-processing", "parsing", "web-programming"] -description = "Utilities for Yew to validate tag names and attributes" -repository = "https://github.com/yewstack/yew" - -[dependencies] diff --git a/packages/yew-validation/src/lib.rs b/packages/yew-validation/src/lib.rs deleted file mode 100644 index b1cd8245d..000000000 --- a/packages/yew-validation/src/lib.rs +++ /dev/null @@ -1,232 +0,0 @@ -//! Utility library for the Yew frontend web framework to handle validating strings relating -//! to HTML/SVG/MathML tags. - -/// Returns true when the character provided is a "control" as defined -/// in [the WhatWG spec](https://infra.spec.whatwg.org/#control) -fn is_control(c: char) -> bool { - match c { - '\u{007F}'..='\u{009F}' => true, - _ => is_c0_control(c), - } -} - -/// Returns true when the character provided is a "c0 control" as defined -/// in [the WhatWG spec](https://infra.spec.whatwg.org/#c0-control) -fn is_c0_control(c: char) -> bool { - matches!(c, '\u{0000}'..='\u{001F}') -} - -/// Returns true when the string provided is a "noncharacter" as defined -/// in [the WhatWG spec](https://infra.spec.whatwg.org/#noncharacter) -fn is_noncharacter(c: char) -> bool { - matches!( - c, - '\u{FDD0}' - ..='\u{FDEF}' - | '\u{FFFE}' - | '\u{FFFF}' - | '\u{1FFFE}' - | '\u{1FFFF}' - | '\u{2FFFE}' - | '\u{2FFFF}' - | '\u{3FFFE}' - | '\u{3FFFF}' - | '\u{4FFFE}' - | '\u{4FFFF}' - | '\u{5FFFE}' - | '\u{5FFFF}' - | '\u{6FFFE}' - | '\u{6FFFF}' - | '\u{7FFFE}' - | '\u{7FFFF}' - | '\u{8FFFE}' - | '\u{8FFFF}' - | '\u{9FFFE}' - | '\u{9FFFF}' - | '\u{AFFFE}' - | '\u{AFFFF}' - | '\u{BFFFE}' - | '\u{BFFFF}' - | '\u{CFFFE}' - | '\u{CFFFF}' - | '\u{DFFFE}' - | '\u{DFFFF}' - | '\u{EFFFE}' - | '\u{EFFFF}' - | '\u{FFFFE}' - | '\u{FFFFF}' - | '\u{10FFFE}' - | '\u{10FFFF}' - ) -} - -/// Returns true when the string provided is a valid "attribute name" as defined -/// in [the WhatWG spec](https://html.spec.whatwg.org/multipage/syntax.html#syntax-attribute-name) -pub fn is_valid_html_attribute_name(attr: &str) -> bool { - for c in attr.chars() { - if is_noncharacter(c) - || is_control(c) - || c == '\u{0020}' - || c == '\u{0022}' - || c == '\u{0027}' - || c == '\u{003E}' - || c == '\u{002F}' - || c == '\u{003D}' - { - return false; - } - } - true -} - -/// Returns true when the character provided is a valid PCENChar as defined -/// in [the WhatWG spec](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-pcenchar) -fn is_pcen_char(c: char) -> bool { - matches!(c, '-' | '.' | '0'..='9' | 'a'..='z' | '_' - | '\u{B7}' - | '\u{C0}'..='\u{D6}' - | '\u{D8}'..='\u{F6}' - | '\u{F8}'..='\u{37D}' - | '\u{37F}'..='\u{1FFF}' - | '\u{200C}'..='\u{200D}' - | '\u{203F}'..='\u{2040}' - | '\u{2070}'..='\u{218F}' - | '\u{2C00}'..='\u{2FEF}' - | '\u{3001}'..='\u{D7FF}' - | '\u{F900}'..='\u{FDCF}' - | '\u{FDF0}'..='\u{FFFD}' - | '\u{10000}'..='\u{EFFFF}' - ) -} - -/// Returns true when the tag name provided would be a valid "custom element" per -/// [the WhatWG spec](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name). -/// Only technically returns correct results if called with a string that is not one of the following: -/// - annotation-xml -/// - color-profile -/// - font-face -/// - font-face-src -/// - font-face-uri -/// - font-face-format -/// - font-face-name -/// - missing-glyph -/// But, given the way it is used in this file, as of this writing, this limitation does not affect the -/// behavior of the program. -fn is_valid_html_custom_element_name(tag: &str) -> bool { - let mut chars = tag.chars(); - let first_char = chars.next(); - - match first_char { - None => false, - Some(first_char) => { - // must begin with [a-z] - if !('a'..='z').contains(&first_char) { - return false; - } - - let mut seen_hyphen = false; - for c in chars { - if c == '-' { - seen_hyphen = true - } - - // all characters must be valid PCENChar's - if !is_pcen_char(c) { - return false; - } - } - - // must contain at least one hyphen - seen_hyphen - } - } -} - -/// Returns true when the tag name provided looks like a valid non-custom HTML element or valid SVG element. -/// There's no official spec here, it's just arbitrary. -fn resembles_standard_html_element_name(tag: &str) -> bool { - // must contain at least one character - if tag.is_empty() { - return false; - } - - let mut saw_non_hyphen = false; - for c in tag.chars() { - match c { - 'a'..='z' | 'A'..='Z' | '0'..='9' => saw_non_hyphen = true, - '-' => {} - _ => { - return false; - } - } - } - - saw_non_hyphen -} - -/// Returns true when you could validly construct a tag using this name in an HTML document -pub fn is_valid_sgml_tag(tag: &str) -> bool { - resembles_standard_html_element_name(tag) || is_valid_html_custom_element_name(tag) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn valid_custom_element() { - assert!(is_valid_html_custom_element_name("foo-bar")); - assert!(is_valid_html_custom_element_name("foo-")); - assert!(is_valid_html_custom_element_name("bar-baz")); - } - - #[test] - fn invalid_custom_element() { - assert!(!is_valid_html_custom_element_name("foobar")); - assert!(!is_valid_html_custom_element_name("-bar")); - assert!(!is_valid_html_custom_element_name("foo bar")); - assert!(!is_valid_html_custom_element_name("")); - assert!(!is_valid_html_custom_element_name("foo\nbar")); - assert!(!is_valid_html_custom_element_name("-")); - } - - #[test] - fn valid_html_element() { - assert!(resembles_standard_html_element_name("section")); - assert!(resembles_standard_html_element_name("h2")); - assert!(resembles_standard_html_element_name("applet")); - assert!(resembles_standard_html_element_name("appLET")); - assert!(resembles_standard_html_element_name("aPPlet")); - assert!(resembles_standard_html_element_name("foo-bar")); - } - - #[test] - fn invalid_html_element() { - assert!(!resembles_standard_html_element_name(" foo")); - assert!(!resembles_standard_html_element_name("foo ")); - assert!(!resembles_standard_html_element_name("-")); - assert!(!resembles_standard_html_element_name("!doctype")); - } - - #[test] - fn valid_html_attribute() { - assert!(is_valid_html_attribute_name("-foo-bar")); - assert!(is_valid_html_attribute_name("data-foobar")); - assert!(is_valid_html_attribute_name("foobar")); - } - - #[test] - fn invalid_sgml_tag() { - assert!(!is_valid_sgml_tag("f>bar")); - assert!(!is_valid_sgml_tag("f")); - } -} diff --git a/packages/changelog/Cargo.toml b/tools/changelog/Cargo.toml similarity index 100% rename from packages/changelog/Cargo.toml rename to tools/changelog/Cargo.toml diff --git a/packages/changelog/Makefile.toml b/tools/changelog/Makefile.toml similarity index 100% rename from packages/changelog/Makefile.toml rename to tools/changelog/Makefile.toml diff --git a/packages/changelog/src/main.rs b/tools/changelog/src/main.rs similarity index 100% rename from packages/changelog/src/main.rs rename to tools/changelog/src/main.rs diff --git a/packages/website-test/Cargo.toml b/tools/website-test/Cargo.toml similarity index 100% rename from packages/website-test/Cargo.toml rename to tools/website-test/Cargo.toml diff --git a/packages/website-test/Makefile.toml b/tools/website-test/Makefile.toml similarity index 100% rename from packages/website-test/Makefile.toml rename to tools/website-test/Makefile.toml diff --git a/packages/website-test/build.rs b/tools/website-test/build.rs similarity index 100% rename from packages/website-test/build.rs rename to tools/website-test/build.rs diff --git a/packages/website-test/src/agents.rs b/tools/website-test/src/agents.rs similarity index 100% rename from packages/website-test/src/agents.rs rename to tools/website-test/src/agents.rs diff --git a/packages/website-test/src/lib.rs b/tools/website-test/src/lib.rs similarity index 100% rename from packages/website-test/src/lib.rs rename to tools/website-test/src/lib.rs diff --git a/packages/website-test/src/tutorial.rs b/tools/website-test/src/tutorial.rs similarity index 100% rename from packages/website-test/src/tutorial.rs rename to tools/website-test/src/tutorial.rs