Skip to content

Commit

Permalink
docs(examples): 🚚 merged basic/cli examples and cleaned up examples
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Sep 20, 2021
1 parent 2c2d06b commit db6fbdd
Show file tree
Hide file tree
Showing 20 changed files with 23 additions and 71 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ members = [
"examples/*",
# We have the CLI subcrates as workspace members so we can actively develop on them
# They also can't be a workspace until nested workspaces are supported
"examples/cli/.perseus",
"examples/cli/.perseus/server"
"examples/basic/.perseus",
"examples/basic/.perseus/server"
]
6 changes: 3 additions & 3 deletions bonnie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dev.subcommands.cli.cmd = [
"cd packages/perseus-cli",
# We need to copy in the directory where we actually work on the subcrate
"rm -rf ./.perseus",
"cp -r ../../examples/cli/.perseus/ .perseus/",
"cp -r ../../examples/basic/.perseus/ .perseus/",
"mv .perseus/Cargo.toml .perseus/Cargo.toml.old",
"mv .perseus/server/Cargo.toml .perseus/server/Cargo.toml.old",
"cargo run -- %%"
Expand All @@ -15,7 +15,7 @@ dev.subcommands.example.cmd = [
"cd packages/perseus-cli",
# We need to copy in the directory where we actually work on the subcrate
"rm -rf ./.perseus",
"cp -r ../../examples/cli/.perseus/ .perseus/",
"cp -r ../../examples/basic/.perseus/ .perseus/",
"mv .perseus/Cargo.toml .perseus/Cargo.toml.old",
"mv .perseus/server/Cargo.toml .perseus/server/Cargo.toml.old",
# Now point this live version of the CLI at the given example
Expand Down Expand Up @@ -75,7 +75,7 @@ publish.cmd = [
# The CLI needs the `.perseus/` directory copied in for packaging (and we need to rename `Cargo.toml` to `Cargo.toml.old`)
"cd ../perseus-cli",
"rm -rf ./.perseus",
"cp -r ../../examples/cli/.perseus/ .perseus/",
"cp -r ../../examples/basic/.perseus/ .perseus/",
"mv .perseus/Cargo.toml .perseus/Cargo.toml.old",
"mv .perseus/server/Cargo.toml .perseus/server/Cargo.toml.old",
"cargo publish --allow-dirty %%", # Without this flag, `.perseus` will be a problem because it's not in Git
Expand Down
5 changes: 3 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This folder contains examples for Perseus, which are used to test the project an
These examples are all fully self-contained, and do not serve as examples in the traditional Cargo way, they are each indepedent crates to enable the use of build tools such as `wasm-pack`.

- Showcase -- an app that demonstrates all the different features of Perseus, including SSR, SSG, and ISR (this example is actively used for testing/development)
- Basic -- a simple app that uses the Perseus CLI (symlinks to CLI example)
- CLI -- same as basic, but includes the CLI subcrates (actively used for testing/development)
- Basic -- a simple app that uses the Perseus CLI
- This has `.perseus/` included in Git, it's where that's developed
- i18n -- a simple app that showcases internationalization in particular
- Tiny -- the smallest Perseus can get, the _Hello World!_ example
2 changes: 0 additions & 2 deletions examples/basic/.gitignore

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 3 additions & 11 deletions examples/basic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# This package is a testing playground for the CLI subcrates, which are stored here under `.perseus/`.
# Use the `basic` example for learning

[package]
name = "perseus-example-basic"
name = "perseus-example-cli"
version = "0.1.4"
edition = "2018"

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

[dependencies]
perseus = { path = "../../packages/perseus" }
sycamore = { version = "0.6", features = ["ssr"] }
sycamore-router = "0.6"
sycamore = "0.6"
serde = { version = "1", features = ["derive"] }
serde_json = "1" # Possibly don't need?

# This section is needed for Wasm Pack (which we use instead of Trunk for flexibility)
[lib]
crate-type = ["cdylib", "rlib"]
serde_json = "1"
1 change: 0 additions & 1 deletion examples/basic/src

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::rc::Rc;
use sycamore::template;

pub fn get_error_pages<G: GenericNode>() -> ErrorPages<G> {
let mut error_pages = ErrorPages::new(Rc::new(|_, _, _, _| {
let mut error_pages = ErrorPages::new(Rc::new(|url, status, err, _| {
template! {
p { "Another error occurred." }
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
}
}));
error_pages.add_page(
Expand All @@ -16,14 +16,6 @@ pub fn get_error_pages<G: GenericNode>() -> ErrorPages<G> {
}
}),
);
error_pages.add_page(
400,
Rc::new(|_, _, _, _| {
template! {
p { "Client error occurred..." }
}
}),
);

error_pages
}
6 changes: 3 additions & 3 deletions examples/cli/src/lib.rs → examples/basic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mod error_pages;
mod pages;
mod templates;

use perseus::define_app;

define_app! {
templates: [
crate::pages::index::get_page::<G>(),
crate::pages::about::get_page::<G>()
crate::templates::index::get_template::<G>(),
crate::templates::about::get_template::<G>()
],
error_pages: crate::error_pages::get_error_pages(),
static_aliases: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn about_page() -> SycamoreTemplate<G> {
}
}

pub fn get_page<G: GenericNode>() -> Template<G> {
pub fn get_template<G: GenericNode>() -> Template<G> {
Template::new("about")
.template(template_fn())
.head(head_fn())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use perseus::{StringResultWithCause, Template};
use perseus::{GenericNode, StringResultWithCause, Template};
use serde::{Deserialize, Serialize};
use std::rc::Rc;
use sycamore::prelude::{component, template, GenericNode, Template as SycamoreTemplate};
use sycamore::prelude::{component, template, Template as SycamoreTemplate};

#[derive(Serialize, Deserialize, Debug)]
pub struct IndexPageProps {
Expand All @@ -16,14 +16,14 @@ pub fn index_page(props: IndexPageProps) -> SycamoreTemplate<G> {
}
}

pub fn get_page<G: GenericNode>() -> Template<G> {
pub fn get_template<G: GenericNode>() -> Template<G> {
Template::new("index")
.build_state_fn(Rc::new(get_static_props))
.build_state_fn(Rc::new(get_build_props))
.template(template_fn())
.head(head_fn())
}

pub async fn get_static_props(_path: String) -> StringResultWithCause<String> {
pub async fn get_build_props(_path: String) -> StringResultWithCause<String> {
Ok(serde_json::to_string(&IndexPageProps {
greeting: "Hello World!".to_string(),
})
Expand Down
File renamed without changes.
20 changes: 0 additions & 20 deletions examples/cli/Cargo.toml

This file was deleted.

11 changes: 0 additions & 11 deletions examples/cli/index.html

This file was deleted.

1 change: 1 addition & 0 deletions examples/tiny/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Perseus Example – Tiny</title>
</head>
<body>
<div id="root"></div>
Expand Down

0 comments on commit db6fbdd

Please sign in to comment.