From 58c69d3bfb2bc12d9734ba5f5973da81ccf40820 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Mon, 27 May 2019 23:23:09 -0400 Subject: [PATCH] Special handling for href --- crates/macro-impl/src/html_tree/html_tag.rs | 11 +++++++++++ crates/macro/tests/html-tag-fail.rs | 1 + crates/macro/tests/html-tag-fail.stderr | 12 ++++++++++++ crates/macro/tests/html-tag-pass.rs | 1 + 4 files changed, 25 insertions(+) diff --git a/crates/macro-impl/src/html_tree/html_tag.rs b/crates/macro-impl/src/html_tree/html_tag.rs index 4ee879d5dbd..cd4b612f4fd 100644 --- a/crates/macro-impl/src/html_tree/html_tag.rs +++ b/crates/macro-impl/src/html_tree/html_tag.rs @@ -103,6 +103,7 @@ impl ToTokens for HtmlTag { checked, disabled, selected, + href, listeners, } = &open.attributes; let attr_names = attributes.iter().map(|attr| attr.name.to_string()); @@ -130,6 +131,12 @@ impl ToTokens for HtmlTag { } } }); + let add_href = href.iter().map(|href| { + quote! { + let __yew_href: $crate::html::Href = #href.into(); + __yew_vtag.add_attribute("href", &__yew_href); + } + }); let set_classes = classes.iter().map(|classes_form| match classes_form { ClassesForm::Tuple(classes) => quote! { #(__yew_vtag.add_class(&(#classes));)* }, ClassesForm::Single(classes) => quote! { @@ -147,6 +154,7 @@ impl ToTokens for HtmlTag { #(#set_checked)* #(#add_disabled)* #(#add_selected)* + #(#add_href)* #(__yew_vtag.add_child(#children);)* __yew_vtag }}); @@ -219,6 +227,7 @@ struct TagAttributes { checked: Option, disabled: Option, selected: Option, + href: Option, } enum ClassesForm { @@ -394,6 +403,7 @@ impl Parse for TagAttributes { let checked = TagAttributes::remove_attr(&mut attributes, "checked"); let disabled = TagAttributes::remove_attr(&mut attributes, "disabled"); let selected = TagAttributes::remove_attr(&mut attributes, "selected"); + let href = TagAttributes::remove_attr(&mut attributes, "href"); Ok(TagAttributes { attributes, @@ -404,6 +414,7 @@ impl Parse for TagAttributes { checked, disabled, selected, + href, }) } } diff --git a/crates/macro/tests/html-tag-fail.rs b/crates/macro/tests/html-tag-fail.rs index 0c70e3ba53a..685c7330bbf 100644 --- a/crates/macro/tests/html-tag-fail.rs +++ b/crates/macro/tests/html-tag-fail.rs @@ -23,5 +23,6 @@ test_html! { |t31| } test_html! { |t32|