Skip to content

Commit

Permalink
Fixed ordering of lists of things
Browse files Browse the repository at this point in the history
  • Loading branch information
theashguy committed May 24, 2020
1 parent d159b2a commit 1d5f88a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 5 additions & 2 deletions render_macros/src/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ impl Children {
quote! { #child }
})
.collect();

match children_quotes.len() {
0 => quote! { Option::<()>::None },
1 => quote! { Some(#(#children_quotes)*) },
1 => quote! { Some(#(#children_quotes),*) },
_ => {
let mut iter = children_quotes.iter();

let first = iter.next().unwrap();
let second = iter.next().unwrap();

let tuple_of_tuples = iter.fold(
quote!((#first, #second)),
|renderable, current| quote!((#current, #renderable)),
|renderable, current| quote!((#renderable, #current)),
);

quote! { Some(#tuple_of_tuples) }
Expand Down
16 changes: 15 additions & 1 deletion render_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,28 @@ pub fn element_ordering() {
use render::{html, raw};

let actual = html! {
<ul>
<li>{"1"}</li>
<li>{"2"}</li>
<li>{"3"}</li>
</ul>
};

assert_eq!(actual, "<ul><li>1</li><li>2</li><li>3</li></ul>");

let deep = html! {
<div>
<h1>{"A list"}</h1>
<hr />
<ul>
<li>{"1"}</li>
<li>{"2"}</li>
<li>{"3"}</li>
</ul>
</div>
};

assert_eq!(actual, "<ul><li>1</li><li>2</li><li>3</li></ul>");
assert_eq!(deep, "<div><h1>A list</h1><hr/><ul><li>1</li><li>2</li><li>3</li></ul></div>");
}

mod kaki {
Expand Down

0 comments on commit 1d5f88a

Please sign in to comment.