Skip to content

Commit 2c2d06b

Browse files
committed
docs(examples): ✨ added new tiny example and updated readme with it
1 parent c2a4560 commit 2c2d06b

File tree

7 files changed

+70
-13
lines changed

7 files changed

+70
-13
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"conventionalCommits.scopes": ["i18n", "routing", "cli", "book"]
2+
"conventionalCommits.scopes": ["i18n", "routing", "cli", "book", "examples"]
33
}

Cargo.toml

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
[workspace]
22
members = [
3-
"packages/perseus",
4-
"packages/perseus-actix-web",
5-
"packages/perseus-cli",
6-
"examples/showcase",
7-
"examples/cli",
3+
"packages/*",
4+
"examples/*",
85
# We have the CLI subcrates as workspace members so we can actively develop on them
96
# They also can't be a workspace until nested workspaces are supported
107
"examples/cli/.perseus",
11-
"examples/cli/.perseus/server",
12-
"examples/basic",
13-
"examples/i18n"
8+
"examples/cli/.perseus/server"
149
]

README.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,31 @@ Perseus is a blazingly fast frontend web development framework built in Rust wit
1212
- ✨ CLI harness that lets you build apps with ease and confidence
1313
- ✨ Full i18n support out-of-the-box with [Fluent](https://projectfluent.org)
1414

15-
## How to use
16-
17-
Check out the docs [here](https://arctic-hen7.github.io/perseus) for how to use Perseus.
15+
## Usage
16+
17+
Here's a taste of Perseus (see [the *tiny* example](https://github.com/arctic-hen7/perseus/tree/main/examples/tiny) for more):
18+
19+
```rust
20+
use perseus::{define_app, ErrorPages, Template};
21+
use std::rc::Rc;
22+
use sycamore::template;
23+
define_app! {
24+
templates: [
25+
Template::<G>::new("index").template(Rc::new(|_| {
26+
template! {
27+
p { "Hello World!" }
28+
}
29+
}))
30+
],
31+
error_pages: ErrorPages::new(Rc::new(|url, status, err, _| {
32+
template! {
33+
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
34+
}
35+
}))
36+
}
37+
```
38+
39+
Check out [the book](https://arctic-hen7.github.io/perseus) to learn how to turn that into your next app!
1840

1941
## Aim
2042

@@ -35,7 +57,7 @@ These tasks still need to be done before Perseus can be pushed to v1.0.0.
3557
* [x] Support i18n out of the box
3658
* [x] Implement custom router
3759
* [x] Allow direct modification of the document head
38-
* [ ] Improve SEO and initial load performance
60+
* [x] Improve SEO and initial load performance
3961
* [ ] Support custom template hierarchies
4062
* [ ] Pre-built integrations
4163
- [x] Actix Web

examples/tiny/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.perseus/

examples/tiny/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "perseus-example-tiny"
3+
version = "0.1.4"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
perseus = { path = "../../packages/perseus" }
10+
sycamore = "0.6"

examples/tiny/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
</body>
11+
</html>

examples/tiny/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use perseus::{define_app, ErrorPages, Template};
2+
use std::rc::Rc;
3+
use sycamore::template;
4+
define_app! {
5+
templates: [
6+
Template::<G>::new("index").template(Rc::new(|_| {
7+
template! {
8+
p { "Hello World!" }
9+
}
10+
}))
11+
],
12+
error_pages: ErrorPages::new(Rc::new(|url, status, err, _| {
13+
template! {
14+
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
15+
}
16+
}))
17+
}

0 commit comments

Comments
 (0)