Skip to content

Commit

Permalink
docs(examples): updated example writing docs and base example
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Jul 13, 2022
1 parent 5473683 commit 0c1b578
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 25 deletions.
4 changes: 3 additions & 1 deletion examples/.base/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.perseus/
dist/
target_engine/
target_wasm/
27 changes: 25 additions & 2 deletions examples/.base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
[package]
name = "perseus-example-base"
version = "0.3.2"
version = "0.4.0-beta.3"
edition = "2021"

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

[dependencies]
perseus = { path = "../../../packages/perseus", features = [ "hydrate" ] }
sycamore = "0.7"
sycamore = "=0.8.0-beta.7"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
fantoccini = "0.17"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }
# This is an internal convenience crate that exposes all integrations through features for testing
perseus-integration = { path = "../../../packages/perseus-integration", default-features = false }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"

[lib]
name = "lib"
path = "src/lib.rs"
crate-type = [ "cdylib", "rlib" ]

[[bin]]
name = "perseus-example-base"
path = "src/lib.rs"

[package.metadata.wasm-pack.profile.release]
wasm-opt = [ "-Oz" ]
4 changes: 3 additions & 1 deletion examples/.base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This isn't an example per se, rather it's a template for future examples. If you want to create a new example, you should copy this directory and modify it to suit your needs, its purpsoe is just to create a universal minimal boilerplate from which examples can work.

After copying this, you'll need to change this README to describe your example, and you'll need to change the name of your example in `Cargo.toml` to `perseus-example-<name>` (right now, it's `perseus-example-base`, leabving it as this will cause a compilation error).
After copying this, you'll need to change this README to describe your example, and you'll need to change the name of your example in `Cargo.toml` to `perseus-example-<name>` (right now, it's `perseus-example-base`, leaving it as this will cause a compilation error).

*Note: by default, all examples are compatible with all integrations, and will be tested with them all. If your example is only compatible with a single integration, you shouldn't use `perseus-integration`, but the specific integration crate instead, and make sure to add an empty `.integration_locked` file to the root of the example. See `examples/core/custom_server/` for more details.*

If you need some help with creating your example, feel free to pop over to our [Discord channel](https://discord.com/invite/GNqWYWNTdp)!
10 changes: 0 additions & 10 deletions examples/.base/index.html

This file was deleted.

8 changes: 4 additions & 4 deletions examples/.base/src/error_pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use perseus::{ErrorPages, Html};
use sycamore::view;

pub fn get_error_pages<G: Html>() -> ErrorPages<G> {
let mut error_pages = ErrorPages::new(|url, status, err, _| {
view! {
let mut error_pages = ErrorPages::new(|cx, url, status, err, _| {
view! { cx,
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
}
});
error_pages.add_page(404, |_, _, _, _| {
view! {
error_pages.add_page(404, |cx, _, _, _, _| {
view! { cx,
p { "Page not found." }
}
});
Expand Down
2 changes: 1 addition & 1 deletion examples/.base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod templates;

use perseus::{Html, PerseusApp};

#[perseus::main]
#[perseus::main(perseus_integration::dflt_server)]
pub fn main<G: Html>() -> PerseusApp<G> {
PerseusApp::new()
.template(crate::templates::index::get_template)
Expand Down
12 changes: 6 additions & 6 deletions examples/.base/src/templates/index.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use perseus::{Html, Template};
use sycamore::prelude::{view, SsrNode, View};
use perseus::Template;
use sycamore::prelude::{view, Html, Scope, SsrNode, View};

#[perseus::template_rx]
pub fn index_page() -> View<G> {
view! {
pub fn index_page<G: Html>(cx: Scope) -> View<G> {
view! { cx,
p { "Hello World!" }
}
}

#[perseus::head]
pub fn head() -> View<SsrNode> {
view! {
pub fn head(cx: Scope) -> View<SsrNode> {
view! { cx,
title { "Index Page" }
}
}
Expand Down

0 comments on commit 0c1b578

Please sign in to comment.