Chore: cargo fmt

This commit is contained in:
Jonathan Kelley committed 2021-01-14 02:57:30 -05:00
1 parent 2b9c8d09d9
commit cd20d3c168
6 files changed
+136 -43

No files matched your search

+9 -20
View File
@@ -1,13 +1,10 @@
use crate::parser::{HtmlParser, NodesToPush}; use crate::parser::{HtmlParser, NodesToPush};
use quote::quote; use quote::quote;
use syn::{Stmt, Expr, ExprIf}; use syn::{Expr, ExprIf, Stmt};
impl HtmlParser { impl HtmlParser {
/// Parse an incoming syn::Stmt node inside a block /// Parse an incoming syn::Stmt node inside a block
pub(crate) fn parse_statement( pub(crate) fn parse_statement(&mut self, stmt: &Stmt) {
&mut self,
stmt: &Stmt,
) {
// Here we handle a block being a descendant within some html! call. // Here we handle a block being a descendant within some html! call.
// //
// The descendant should implement Into<IterableNodes> // The descendant should implement Into<IterableNodes>
@@ -16,7 +13,7 @@ impl HtmlParser {
match stmt { match stmt {
Stmt::Expr(expr) => { Stmt::Expr(expr) => {
self.parse_expr(stmt, expr); self.parse_expr(stmt, expr);
}, }
_ => { _ => {
self.push_iterable_nodes(NodesToPush::Stmt(stmt)); self.push_iterable_nodes(NodesToPush::Stmt(stmt));
} }
@@ -24,15 +21,11 @@ impl HtmlParser {
} }
/// Parse an incoming syn::Expr node inside a block /// Parse an incoming syn::Expr node inside a block
pub(crate) fn parse_expr( pub(crate) fn parse_expr(&mut self, stmt: &Stmt, expr: &Expr) {
&mut self,
stmt: &Stmt,
expr: &Expr
) {
match expr { match expr {
Expr::If(expr_if) => { Expr::If(expr_if) => {
self.expand_if(stmt, expr_if); self.expand_if(stmt, expr_if);
}, }
_ => { _ => {
self.push_iterable_nodes(NodesToPush::Stmt(stmt)); self.push_iterable_nodes(NodesToPush::Stmt(stmt));
} }
@@ -42,9 +35,9 @@ impl HtmlParser {
/// Expand an incoming Expr::If block /// Expand an incoming Expr::If block
/// This enables us to use JSX-style conditions inside of blocks such as /// This enables us to use JSX-style conditions inside of blocks such as
/// the following example. /// the following example.
/// ///
/// # Examples /// # Examples
/// ///
/// ```rust,ignore /// ```rust,ignore
/// html! { /// html! {
/// <div> /// <div>
@@ -54,16 +47,12 @@ impl HtmlParser {
/// </div> /// </div>
/// } /// }
/// ``` /// ```
/// ///
/// Traditionally this would be possible as an if statement in rust is an /// Traditionally this would be possible as an if statement in rust is an
/// expression, so the then, and the else block have to return matching types. /// expression, so the then, and the else block have to return matching types.
/// Here we identify whether the block is missing the else and fill it in with /// Here we identify whether the block is missing the else and fill it in with
/// a blank VirtualNode::text("") /// a blank VirtualNode::text("")
pub(crate) fn expand_if( pub(crate) fn expand_if(&mut self, stmt: &Stmt, expr_if: &ExprIf) {
&mut self,
stmt: &Stmt,
expr_if: &ExprIf
) {
// Has else branch, we can parse the expression as normal. // Has else branch, we can parse the expression as normal.
if let Some(_else_branch) = &expr_if.else_branch { if let Some(_else_branch) = &expr_if.else_branch {
self.push_iterable_nodes(NodesToPush::Stmt(stmt)); self.push_iterable_nodes(NodesToPush::Stmt(stmt));
+1 -1
View File
@@ -120,7 +120,7 @@ fn parse_open_tag(input: &mut ParseStream, open_bracket_span: Span) -> Result<Ta
attrs, attrs,
open_bracket_span, open_bracket_span,
closing_bracket_span, closing_bracket_span,
is_self_closing is_self_closing,
}) })
} }
+113 -10
View File
@@ -5,16 +5,119 @@ use super::svg_namespace::is_svg_namespace;
lazy_static! { lazy_static! {
static ref VALID_TAGS: HashSet<&'static str> = [ static ref VALID_TAGS: HashSet<&'static str> = [
"a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","big", "a",
"blockquote","body","br","button","canvas","caption","cite","code","col","colgroup", "abbr",
"command", "data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed", "address",
"fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head", "area",
"header","hr","html","i","iframe","img","input","ins","kbd","keygen","label","legend", "article",
"li","link","main","map","mark","menu","menuitem","meta","meter","nav","noscript","object", "aside",
"ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt", "audio",
"ruby","s","samp","script","section","select","small","source","span","strong","style", "b",
"sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title", "base",
"tr","track","u","ul","var","video","wbr", "bdi",
"bdo",
"big",
"blockquote",
"body",
"br",
"button",
"canvas",
"caption",
"cite",
"code",
"col",
"colgroup",
"command",
"data",
"datalist",
"dd",
"del",
"details",
"dfn",
"dialog",
"div",
"dl",
"dt",
"em",
"embed",
"fieldset",
"figcaption",
"figure",
"footer",
"form",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hr",
"html",
"i",
"iframe",
"img",
"input",
"ins",
"kbd",
"keygen",
"label",
"legend",
"li",
"link",
"main",
"map",
"mark",
"menu",
"menuitem",
"meta",
"meter",
"nav",
"noscript",
"object",
"ol",
"optgroup",
"option",
"output",
"p",
"param",
"picture",
"pre",
"progress",
"q",
"rp",
"rt",
"ruby",
"s",
"samp",
"script",
"section",
"select",
"small",
"source",
"span",
"strong",
"style",
"sub",
"summary",
"sup",
"table",
"tbody",
"td",
"textarea",
"tfoot",
"th",
"thead",
"time",
"title",
"tr",
"track",
"u",
"ul",
"var",
"video",
"wbr",
] ]
.iter() .iter()
.cloned() .cloned()
+1
View File
@@ -0,0 +1 @@
+9 -9
View File
@@ -22,15 +22,15 @@ fn on_input() {
let text_clone = Rc::clone(&text); let text_clone = Rc::clone(&text);
let input = html! { let input = html! {
<input <input
// On input we'll set our Rc<RefCell<String>> value to the input elements value // On input we'll set our Rc<RefCell<String>> value to the input elements value
oninput=move |event: Event| { oninput=move |event: Event| {
let input_elem = event.target().unwrap(); let input_elem = event.target().unwrap();
let input_elem = input_elem.dyn_into::<HtmlInputElement>().unwrap(); let input_elem = input_elem.dyn_into::<HtmlInputElement>().unwrap();
*text_clone.borrow_mut() = input_elem.value(); *text_clone.borrow_mut() = input_elem.value();
} }
value="End Text" value="End Text"
> >
}; };
let input_event = InputEvent::new("input").unwrap(); let input_event = InputEvent::new("input").unwrap();
+3 -3
View File
@@ -454,19 +454,19 @@ impl From<Vec<VirtualNode>> for IterableNodes {
impl<V: View> From<Vec<V>> for IterableNodes { impl<V: View> From<Vec<V>> for IterableNodes {
fn from(other: Vec<V>) -> Self { fn from(other: Vec<V>) -> Self {
IterableNodes(other.into_iter().map(|it| it.render()).collect()) IterableNodes(other.into_iter().map(|it| it.render()).collect())
} }
} }
impl<V: View> From<&Vec<V>> for IterableNodes { impl<V: View> From<&Vec<V>> for IterableNodes {
fn from(other: &Vec<V>) -> Self { fn from(other: &Vec<V>) -> Self {
IterableNodes(other.iter().map(|it| it.render()).collect()) IterableNodes(other.iter().map(|it| it.render()).collect())
} }
} }
impl<V: View> From<&[V]> for IterableNodes { impl<V: View> From<&[V]> for IterableNodes {
fn from(other: &[V]) -> Self { fn from(other: &[V]) -> Self {
IterableNodes(other.iter().map(|it| it.render()).collect()) IterableNodes(other.iter().map(|it| it.render()).collect())
} }
} }