Work on book

This commit is contained in:
Greg Johnston 2022-10-12 14:43:49 -04:00
parent c02839d6fc
commit 60f9c7b91f
6 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,12 @@
[package]
name = "ch01_getting_started"
version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { version = "0.0", features = ["csr"] }
[profile.release]
codegen-units = 1
lto = true
opt-level = 'z'

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Leptos • Todos</title>
<link data-trunk rel="rust" data-wasm-opt="z" />
</head>
<body></body>
</html>

View file

@ -0,0 +1,5 @@
use leptos::*;
fn main() {
mount_to_body(|cx| view! { cx, <p>"Hello, world!"</p> })
}

View file

@ -1,4 +1,6 @@
# Summary
- [Introduction](./introduction.md)
- [Getting Started](./getting_started.md)
- [Templating: Building User Interfaces](./building_ui.md)
- [Reactivity: Making Things Interactive](./reactivity.md)

View file

@ -0,0 +1,50 @@
# Getting Started
> The code for this chapter can be found [here](https://github.com/gbj/leptos/tree/main/docs/book/project/ch01_getting_started).
The easiest way to get started using Leptos is to use [Trunk](https://trunkrs.dev/), as many of our [examples](https://github.com/gbj/leptos/tree/main/examples) do.
If you dont already have it installed, you can install Trunk by running
```bash
cargo install --lock trunk
```
Create a basic Rust binary project
```bash
cargo init leptos-todo
```
Add `leptos` as a dependency to your `Cargo.toml` with the `csr` featured enabled. (That stands for “client-side rendering.” Well talk more about Leptoss support for server-side rendering and hydration later.)
```toml
leptos = { version = "0.0", features = ["csr"] }
```
Youll want to set up a basic `index.html` with the following content:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Leptos • Todos</title>
<link data-trunk rel="rust" data-wasm-opt="z" />
</head>
<body></body>
</html>
```
Lets start with a very simple `main.rs`
```rust
use leptos::*;
fn main() {
mount_to_body(|cx| view! { cx, <p>"Hello, world!"</p> })
}
```
Now run `trunk serve --open`. Trunk should automatically compile your app and open it in your default browser.

View file

@ -0,0 +1,11 @@
# Introduction
This book is intended as an introduction to the [Leptos](https://github.com/gbj/leptos) Web framework. Together, well build a simple todo app—first as a client-side app, then as a full-stack app.
The guide doesnt assume you know anything about fine-grained reactivity or the details of modern Web frameworks. It does assume you are familiar with the Rust programming language, HTML, CSS, and the DOM and other Web APIs.
Leptos is most similar to frameworks like [Solid](https://www.solidjs.com) (JavaScript) and [Sycamore](https://sycamore-rs.netlify.app/) (Rust). There are some similarities to other frameworks like React (JavaScript), Yew (Rust), and Dioxus (Rust), so knowledge of one of those frameworks may also make it easier to understand Leptos.
You can find more detailed docs for each part of the API at [Docs.rs](https://docs.rs/leptos/latest/leptos/).
**The guide is a work in progress.**