02548be3
—
Naitik Shah 5 years ago
Eliminate unused brace errors & unused import (#25)
render/src/text_element.rs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
use crate::html_escaping::escape_html;
|
|
1
2
|
use crate::Render;
|
|
2
3
|
use std::fmt::{Result, Write};
|
|
3
|
-
use crate::html_escaping::escape_html;
|
|
4
4
|
|
|
5
5
|
impl Render for String {
|
|
6
6
|
fn render_into<W: Write>(self, writer: &mut W) -> Result {
|
render_macros/src/child.rs
CHANGED
|
@@ -12,7 +12,12 @@ impl ToTokens for Child {
|
|
|
12
12
|
match self {
|
|
13
13
|
Self::Element(element) => element.to_tokens(tokens),
|
|
14
14
|
Self::RawBlock(block) => {
|
|
15
|
+
let ts = if block.stmts.len() == 1 {
|
|
16
|
+
let first = &block.stmts[0];
|
|
17
|
+
quote!(#first)
|
|
18
|
+
} else {
|
|
15
|
-
|
|
19
|
+
quote!(#block)
|
|
20
|
+
};
|
|
16
21
|
ts.to_tokens(tokens);
|
|
17
22
|
}
|
|
18
23
|
}
|
render_macros/src/children.rs
CHANGED
|
@@ -30,7 +30,7 @@ impl Children {
|
|
|
30
30
|
1 => quote! { Some(#(#children_quotes),*) },
|
|
31
31
|
_ => {
|
|
32
32
|
let mut iter = children_quotes.iter();
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
let first = iter.next().unwrap();
|
|
35
35
|
let second = iter.next().unwrap();
|
|
36
36
|
|
render_macros/src/element_attribute.rs
CHANGED
|
@@ -23,7 +23,14 @@ impl ElementAttribute {
|
|
|
23
23
|
|
|
24
24
|
pub fn value_tokens(&self) -> proc_macro2::TokenStream {
|
|
25
25
|
match self {
|
|
26
|
-
Self::WithValue(_, value) =>
|
|
26
|
+
Self::WithValue(_, value) => {
|
|
27
|
+
if value.stmts.len() == 1 {
|
|
28
|
+
let first = &value.stmts[0];
|
|
29
|
+
quote!(#first)
|
|
30
|
+
} else {
|
|
31
|
+
quote!(#value)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
27
34
|
Self::Punned(ident) => quote!(#ident),
|
|
28
35
|
}
|
|
29
36
|
}
|
render_macros/src/function_component.rs
CHANGED
|
@@ -10,9 +10,7 @@ pub fn create_function_component(f: syn::ItemFn) -> TokenStream {
|
|
|
10
10
|
let vis = f.vis;
|
|
11
11
|
|
|
12
12
|
let inputs_block = if inputs.len() > 0 {
|
|
13
|
-
let input_names: Vec<_> = inputs
|
|
13
|
+
let input_names: Vec<_> = inputs.iter().collect();
|
|
14
|
-
.iter()
|
|
15
|
-
.collect();
|
|
16
14
|
|
|
17
15
|
quote!({ #(#vis #input_names),* })
|
|
18
16
|
} else {
|
render_tests/src/lib.rs
CHANGED
|
@@ -33,8 +33,8 @@ pub fn works_with_raw_ident() {
|
|
|
33
33
|
|
|
34
34
|
#[test]
|
|
35
35
|
pub fn element_ordering() {
|
|
36
|
-
|
|
36
|
+
use pretty_assertions::assert_eq;
|
|
37
|
-
use render::
|
|
37
|
+
use render::html;
|
|
38
38
|
|
|
39
39
|
let actual = html! {
|
|
40
40
|
<ul>
|
|
@@ -58,7 +58,10 @@ pub fn element_ordering() {
|
|
|
58
58
|
</div>
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
assert_eq!(
|
|
62
|
+
deep,
|
|
61
|
-
|
|
63
|
+
"<div><h1>A list</h1><hr/><ul><li>1</li><li>2</li><li>3</li></ul></div>"
|
|
64
|
+
);
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
mod kaki {
|
|
@@ -111,8 +114,8 @@ mod kaki {
|
|
|
111
114
|
|
|
112
115
|
#[test]
|
|
113
116
|
fn externals_test() {
|
|
114
|
-
use pretty_assertions::assert_eq;
|
|
115
117
|
use crate::other::ExternalPage;
|
|
118
|
+
use pretty_assertions::assert_eq;
|
|
116
119
|
|
|
117
120
|
let actual = render::html! {
|
|
118
121
|
<ExternalPage title={"Home"} subtitle={"Foo"}>
|
|
@@ -135,30 +138,30 @@ mod kaki {
|
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
/// ## Other
|
|
138
|
-
///
|
|
141
|
+
///
|
|
139
142
|
/// Module for testing component visibility when imported from other modules.
|
|
140
143
|
|
|
141
144
|
mod other {
|
|
142
|
-
|
|
145
|
+
use render::html::HTML5Doctype;
|
|
143
|
-
|
|
146
|
+
use render::{component, rsx, Render};
|
|
144
|
-
|
|
147
|
+
|
|
145
|
-
|
|
148
|
+
#[component]
|
|
146
|
-
|
|
149
|
+
pub fn ExternalPage<'title, 'subtitle, Children: Render>(
|
|
147
|
-
|
|
150
|
+
title: &'title str,
|
|
148
|
-
|
|
151
|
+
subtitle: &'subtitle str,
|
|
149
|
-
|
|
152
|
+
children: Children,
|
|
150
|
-
|
|
153
|
+
) {
|
|
151
|
-
|
|
154
|
+
rsx! {
|
|
152
|
-
|
|
155
|
+
<>
|
|
153
|
-
|
|
156
|
+
<HTML5Doctype />
|
|
154
|
-
|
|
157
|
+
<html>
|
|
155
|
-
|
|
158
|
+
<head><title>{title}</title></head>
|
|
156
|
-
|
|
159
|
+
<body>
|
|
157
|
-
|
|
160
|
+
<h1>{subtitle}</h1>
|
|
158
|
-
|
|
161
|
+
{children}
|
|
159
|
-
|
|
162
|
+
</body>
|
|
160
|
-
|
|
163
|
+
</html>
|
|
161
|
-
|
|
164
|
+
</>
|
|
162
|
-
|
|
165
|
+
}
|
|
163
|
-
|
|
166
|
+
}
|
|
164
|
-
}
|
|
167
|
+
}
|