From ae1462cdb83bc149e56d3a175a96b402fa529e1d Mon Sep 17 00:00:00 2001 From: Sara Vieira Date: Thu, 22 Dec 2022 14:28:12 +0000 Subject: [PATCH 1/3] fix data attrs, support scfript --- macros/src/declare.rs | 2 +- typed-html/src/elements.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/macros/src/declare.rs b/macros/src/declare.rs index adcbf7a..6751709 100644 --- a/macros/src/declare.rs +++ b/macros/src/declare.rs @@ -357,7 +357,7 @@ impl Declare { write!(f, "<{}", #name)?; #print_attrs for (key, value) in &self.data_attributes { - write!(f, " data-{}=\"{}\"", key, + write!(f, " data-{}=\"{}\"", str::replace(key, "_", "-"), crate::escape_html_attribute(value.to_string()))?; } for (key, value) in &self.aria_attributes { diff --git a/typed-html/src/elements.rs b/typed-html/src/elements.rs index 5312da1..ef3c029 100644 --- a/typed-html/src/elements.rs +++ b/typed-html/src/elements.rs @@ -31,6 +31,7 @@ macro_rules! marker_trait { }; } +marker_trait!(HTMLContent); marker_trait!(MetadataContent); marker_trait!(FlowContent); marker_trait!(SectioningContent); @@ -53,7 +54,7 @@ marker_trait!(TableColumnContent); declare_elements! { html { xmlns: Uri, - } with [head, body]; + } with [head, body] HTMLContent; head with [title] MetadataContent; body with FlowContent; @@ -311,7 +312,7 @@ declare_elements! { src: Uri, text: String, type: String, // TODO could be an enum - } in [MetadataContent, FlowContent, PhrasingContent, TableColumnContent] with TextNode; + } in [MetadataContent, FlowContent, PhrasingContent, TableColumnContent, HTMLContent] with TextNode; section in [FlowContent, SectioningContent] with FlowContent; select { autocomplete: String, From da3e87a38e3b163b2ed7f21b1577befb35cb7280 Mon Sep 17 00:00:00 2001 From: Sara Vieira Date: Thu, 22 Dec 2022 15:02:41 +0000 Subject: [PATCH 2/3] move implementatipn --- macros/src/declare.rs | 2 +- macros/src/html.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/macros/src/declare.rs b/macros/src/declare.rs index 6751709..adcbf7a 100644 --- a/macros/src/declare.rs +++ b/macros/src/declare.rs @@ -357,7 +357,7 @@ impl Declare { write!(f, "<{}", #name)?; #print_attrs for (key, value) in &self.data_attributes { - write!(f, " data-{}=\"{}\"", str::replace(key, "_", "-"), + write!(f, " data-{}=\"{}\"", key, crate::escape_html_attribute(value.to_string()))?; } for (key, value) in &self.aria_attributes { diff --git a/macros/src/html.rs b/macros/src/html.rs index 4fd914c..dc1034e 100644 --- a/macros/src/html.rs +++ b/macros/src/html.rs @@ -76,7 +76,10 @@ fn extract_data_attrs(attrs: &mut StringyMap) -> StringyMap Date: Thu, 22 Dec 2022 17:35:41 +0000 Subject: [PATCH 3/3] type aria orientation --- macros/src/config.rs | 2 +- typed-html/src/types/mod.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/macros/src/config.rs b/macros/src/config.rs index 068e498..2febe78 100644 --- a/macros/src/config.rs +++ b/macros/src/config.rs @@ -46,7 +46,7 @@ pub fn global_attrs(span: Span) -> StringyMap { insert("aria_modal", "crate::types::Bool"); insert("aria_multiline", "crate::types::Bool"); insert("aria_multiselectable", "crate::types::Bool"); - insert("aria_orientation", "String"); // TODO Only supports some values https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-orientation + insert("aria_orientation", "crate::types::AriaOrientation"); insert("aria_placeholder", "String"); insert("aria_pressed", "crate::types::Bool"); insert("aria_readonly", "crate::types::Bool"); diff --git a/typed-html/src/types/mod.rs b/typed-html/src/types/mod.rs index f2d81bc..eebc5fd 100644 --- a/typed-html/src/types/mod.rs +++ b/typed-html/src/types/mod.rs @@ -537,3 +537,11 @@ pub enum Wrap { #[strum(to_string = "off")] Off, } + +#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, IntoStaticStr)] +pub enum AriaOrientation { + #[strum(to_string = "horizontal")] + Horizontal, + #[strum(to_string = "vertical")] + Vertical, +}