45d44a97
—
Gal Schlezinger 6 years ago
Move readme test to the lib root
- render/src/lib.rs +13 -0
- render_tests/src/lib.rs +0 -65
render/src/lib.rs
CHANGED
|
@@ -58,6 +58,19 @@
|
|
|
58
58
|
//! </Page>
|
|
59
59
|
//! }
|
|
60
60
|
//! }
|
|
61
|
+
//!
|
|
62
|
+
//! # use pretty_assertions::assert_eq;
|
|
63
|
+
//! # let actual = some_page("Gal");
|
|
64
|
+
//! # let expected = concat!(
|
|
65
|
+
//! # "<!DOCTYPE html>",
|
|
66
|
+
//! # "<html>",
|
|
67
|
+
//! # "<head><title>Home</title></head>",
|
|
68
|
+
//! # "<body>",
|
|
69
|
+
//! # "Welcome, Gal",
|
|
70
|
+
//! # "</body>",
|
|
71
|
+
//! # "</html>"
|
|
72
|
+
//! # );
|
|
73
|
+
//! # assert_eq!(actual, expected);
|
|
61
74
|
//! ```
|
|
62
75
|
|
|
63
76
|
pub mod fragment;
|
render_tests/src/lib.rs
CHANGED
|
@@ -44,68 +44,3 @@ pub fn it_works() -> String {
|
|
|
44
44
|
pub fn verify_works() {
|
|
45
45
|
println!("{}", it_works());
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
pub mod readme_code {
|
|
49
|
-
// A simple HTML 5 doctype declaration
|
|
50
|
-
use render::html::HTML5Doctype;
|
|
51
|
-
use render::{
|
|
52
|
-
// A macro to compose components in JSX fashion
|
|
53
|
-
html,
|
|
54
|
-
// A component that just render its children
|
|
55
|
-
Fragment,
|
|
56
|
-
// A trait for custom components
|
|
57
|
-
Renderable,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// This can be any layout we want
|
|
61
|
-
#[derive(Debug)]
|
|
62
|
-
struct Page<'a, T: Renderable> {
|
|
63
|
-
title: &'a str,
|
|
64
|
-
children: T,
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Implementing `Renderable` gives the ability to compose
|
|
68
|
-
// components
|
|
69
|
-
impl<'a, T: Renderable> Renderable for Page<'a, T> {
|
|
70
|
-
fn render(self) -> String {
|
|
71
|
-
html! {
|
|
72
|
-
<Fragment>
|
|
73
|
-
<HTML5Doctype />
|
|
74
|
-
<html>
|
|
75
|
-
<head><title>{self.title}</title></head>
|
|
76
|
-
<body>
|
|
77
|
-
{self.children}
|
|
78
|
-
</body>
|
|
79
|
-
</html>
|
|
80
|
-
</Fragment>
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// This can be a route in Rocket, the web framework,
|
|
86
|
-
// for instance.
|
|
87
|
-
pub fn some_page(user_name: &str) -> String {
|
|
88
|
-
html! {
|
|
89
|
-
<Page title={"Home"}>
|
|
90
|
-
{format!("Welcome, {}", user_name)}
|
|
91
|
-
</Page>
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
#[test]
|
|
97
|
-
fn test_readme_stuff() {
|
|
98
|
-
use pretty_assertions::assert_eq;
|
|
99
|
-
let result = readme_code::some_page("Gal");
|
|
100
|
-
let expected = concat!(
|
|
101
|
-
"<!DOCTYPE html>",
|
|
102
|
-
"<html>",
|
|
103
|
-
"<head><title>Home</title></head>",
|
|
104
|
-
"<body>",
|
|
105
|
-
"Welcome, Gal",
|
|
106
|
-
"</body>",
|
|
107
|
-
"</html>"
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
assert_eq!(result, expected);
|
|
111
|
-
}
|