Skip to content

Commit c5a42a5

Browse files
feat(layout): plz work
1 parent 80c877f commit c5a42a5

File tree

6 files changed

+120
-21
lines changed

6 files changed

+120
-21
lines changed

Cargo.lock

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ authors = ["Ashley Williams <[email protected]>"]
66
[dependencies]
77
rocket = "0.3.6"
88
rocket_codegen = "0.3.6"
9+
serde = "1.0"
10+
serde_derive = "1.0"
911

1012
[dependencies.rocket_contrib]
1113
version = "*"

src/main.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
#![feature(plugin)]
22
#![plugin(rocket_codegen)]
33

4-
extern crate rocket_contrib;
54
extern crate rocket;
65

6+
extern crate rocket_contrib;
7+
#[macro_use] extern crate serde_derive;
8+
79
use rocket_contrib::Template;
810

11+
#[derive(Serialize)]
12+
struct Context {
13+
page: String,
14+
}
15+
916
#[get("/")]
1017
fn index() -> Template {
11-
let context = {};
12-
Template::render("index", &context)
18+
let page = "index".to_string();
19+
let context = Context {
20+
page,
21+
};
22+
Template::render("layout", &context)
1323
}
1424

1525
#[get("/<category>")]
1626
fn category(category: String) -> Template {
17-
let context = {};
18-
let path = format!("{}/index", category.as_str());
19-
Template::render(path, &context)
27+
let page = format!("{}/index", category.as_str()).to_string();
28+
let context = Context {
29+
page,
30+
};
31+
Template::render("layout", &context)
2032
}
2133

2234
#[get("/<category>/<subject>")]
2335
fn subject(category: String, subject: String) -> Template {
24-
let context = {};
25-
let path = format!("{}/{}", category.as_str(), subject.as_str());
26-
Template::render(path, &context)
36+
let page = format!("{}/{}", category.as_str(), subject.as_str()).to_string();
37+
let context = Context {
38+
page,
39+
};
40+
Template::render("layout", &context)
2741
}
2842

2943
fn main() {

static/styles/skeleton.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
body {
2+
font-family: sans-serif;
3+
}
4+
5+
section {
6+
border: 1px dashed black;
7+
padding: 10px;
8+
margin: 10px;
9+
}
10+
11+
div {
12+
border: 1px dotted grey;
13+
padding: 5px;
14+
margin: 5px;
15+
}

templates/index.hbs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
<h1>Home</h1>
1+
{{#*inline "index"}}
2+
<h1>Home</h1>
23

3-
<a href="what">What?</a>
4-
<a href="production">Production</a>
5-
<a href="policies">Policies</a>
6-
<a href="governance">Governance</a>
7-
<a href="community">Community</a>
8-
<a href="contribute">Contribute</a>
9-
<a href="tools/cargo">Cargo</a>
10-
<a href="tools">Tools</a>
11-
<a href="learn">Learn</a>
12-
<a href="learn/getting-started">Getting Started</a>
13-
<a href="what/release-timeline">Release Timeline</a>
4+
<a href="what">What?</a>
5+
<a href="production">Production</a>
6+
<a href="policies">Policies</a>
7+
<a href="governance">Governance</a>
8+
<a href="community">Community</a>
9+
<a href="contribute">Contribute</a>
10+
<a href="tools/cargo">Cargo</a>
11+
<a href="tools">Tools</a>
12+
<a href="learn">Learn</a>
13+
<a href="learn/getting-started">Getting Started</a>
14+
<a href="what/release-timeline">Release Timeline</a>
15+
{{/inline}}
16+
{{~> (parent)~}}

templates/layout.hbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>{{title}}</title>
5+
<link rel="stylesheet" href="/styles.css"/>
6+
</head>
7+
<body>
8+
{{~> index}}
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)