Skip to content

Commit

Permalink
docs(book): 📝 fixed relative paths in docs and added docs about `Stri…
Browse files Browse the repository at this point in the history
…ngResultWithCause<T>`
  • Loading branch information
arctic-hen7 committed Sep 20, 2021
1 parent 58eb92d commit 39b3ce1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/next/src/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Let's get started with Perseus!
To begin, create a new folder for your project, let's call it `my-perseus-app`. Now, create a `Cargo.toml` file in that folder. This tells Rust which packages you want to use in your project and some other metadata. Put the following inside:

```toml
{{#include ../../../examples/tiny/Cargo.toml}}
{{#include ../../../examples/tiny/Cargo.toml.example}}
```

<details>
Expand Down
4 changes: 3 additions & 1 deletion docs/next/src/second-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If learning by reading isn't really your thing, or you'd like a reference, you c
Much like the *Hello World!* app, we'll start off by creating a new directory for the project, maybe `my-second-perseus-app` (or you could exercise imagination...). Then, we'll create a new `Cargo.toml` file and fill it with the following:

```toml
{{#include ../../../examples/basic/Cargo.toml}}
{{#include ../../../examples/basic/Cargo.toml.example}}
```

The only difference between this and the last `Cargo.toml` we created is two new dependencies:
Expand Down Expand Up @@ -116,6 +116,8 @@ Perseus' templating system is extremely versatile, and here we're using it to de

This function is part of Perseus' secret sauce (actually *open* sauce), and it will be called when the CLI builds your app to create properties that the template will take (it expects a string, hence the serialization). Here, we just hard-code a greeting in to be used, but the real power of this comes when you start using the fact that this function is `async`. You might query a database to get a list of blog posts, or pull in a Markdown documentation page and parse it, the possibilities are endless!

Note that this function returns a `StringResultWithCause<String>`, which means that it returns a normal Rust `Result<String, E>`, where `E` is a tuple of a `String` error message and a declaration of who caused the error (either the client or the server). This becomes important when you combine this rendering strategy with others, which are explained in depth later in the book.

### `template_fn()`

The result of this function is what Perseus will call when it wants to render your template (which it does more than you might think), and it passes it the props that your template takes as an `Option<String>`. This might seem a bit weird, but there are reasons under the hood. All you need to know here is that if your template takes any properties, they **will** be here, and it's safe to `.unwrap()` them for deserialization.
Expand Down
12 changes: 12 additions & 0 deletions examples/basic/Cargo.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "my-second-perseus-app"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
perseus = "0.2"
sycamore = "0.6"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
10 changes: 10 additions & 0 deletions examples/tiny/Cargo.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "my-perseus-app"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
perseus = "0.2"
sycamore = "0.6"

0 comments on commit 39b3ce1

Please sign in to comment.