Skip to content

Commit b7f514e

Browse files
authored
Check the code in the guide (#380)
* check the code in the asset, component, and backend guide * check remaining guide sections
1 parent 0e7b49b commit b7f514e

40 files changed

+1342
-860
lines changed

Cargo.lock

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dioxus = { version = "0.6.0", features = ["router"] }
1212
dioxus-web = { version = "0.6.0", features = ["hydrate"], optional = true }
1313
dioxus-ssr = { version = "0.6.0", optional = true }
1414
dioxus-desktop = { version = "0.6.0", optional = true }
15+
dioxus-cli-config = { version = "0.6.0", optional = true }
1516
dioxus-liveview = { version = "0.6.0", features = ["axum"], optional = true }
1617

1718
dioxus-material-icons = { git = "https://github.com/jkelleyrtp/dioxus-material-icons", branch = "jk/git-rev" }
@@ -57,6 +58,7 @@ dioxus-sdk = { version = "0.6.0", optional = true }
5758
tower-http = { version = "0.5.0", optional = true, features = ["timeout"] }
5859
tracing = "0.1.40"
5960
rand = { version = "0.8.5", optional = true }
61+
rusqlite = { version = "0.32.1", optional = true }
6062
askama_escape = { version = "0.10.3", optional = true }
6163

6264
[build-dependencies]
@@ -169,5 +171,7 @@ doc_test = [
169171
"http",
170172
"rand",
171173
"server",
172-
"dioxus/fullstack"
174+
"dioxus/fullstack",
175+
"dioxus-cli-config",
176+
"dep:rusqlite"
173177
]

assets/icon.png

3.21 KB
Loading

docs-src/0.4/en/router/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

docs-src/0.6/src/guide/assets.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@ The bare-bones template already includes a base `main.css` in the `assets` folde
2929
To include the CSS in our app, we can use the `asset!()` macro. This macro ensures the asset will be included in the final app bundle.
3030

3131
```rust
32-
static CSS: Asset = asset!("/assets/main.css");
32+
{{#include src/doc_examples/guide_assets.rs:css_asset}}
3333
```
3434

3535
We also need to load the asset into our app using the `document::Stylesheet` component. This component is equivalent to the `<link>` HTML element but also ensures the CSS will be pre-loaded during server-side-rendering.
3636

3737
```rust
38-
fn App() -> Element {
39-
rsx! {
40-
document::Stylesheet { href: CSS }
41-
// rest of the app
42-
}
43-
}
38+
{{#include src/doc_examples/guide_assets.rs:css_stylesheet}}
4439
```
4540

4641
Unlike Rust's `include_str!()` macro, the `asset!()` macro does not actually include the *contents* of the asset in our final executable. Instead, it generates a unique path so that the asset can be loaded at runtime. This is ideal for web apps where assets are loaded in parallel through different HTTP requests.
@@ -63,39 +58,27 @@ In Dioxus, you can include images in two ways:
6358
When including assets with a URL, simply fill the `src` attribute of `img {}`. Note that when the app is offline, URL-based images won't download.
6459

6560
```rust
66-
rsx! {
67-
// ...
68-
div {
69-
img { src: "https://images.dog.ceo/breeds/pitbull/dog-3981540_1280.jpg" }
70-
}
71-
// ...
72-
}
61+
{{#include src/doc_examples/guide_assets.rs:url_image}}
7362
```
7463

7564
For static images, you can use the same `asset!()` macro that we used to include the app's CSS.
7665

7766
```rust
78-
static ICON: Asset = asset!("/assets/icon.png");
79-
80-
rsx! {
81-
img { src: ICON }
82-
}
67+
{{#include src/doc_examples/guide_assets.rs:asset_image}}
8368
```
8469

8570
## Optimizations
8671

8772
By default, the `asset!()` macro will lightly optimize CSS, JavaScript, JSON, and images. The name of the asset will also be modified to include a content hash.
8873

8974
```rust
90-
// would output main-j1238nask123.css
91-
asset!("/assets/main.css").to_string()
75+
{{#include src/doc_examples/guide_assets.rs:asset_optimization}}
9276
```
9377

9478
You can optimize assets even further, with an optional `Options` struct. For example, `dx` can automatically convert `.png` images to a more optimized `.avif` format:
9579

9680
```rust
97-
// outputs image-j1238jd2.avif
98-
asset!("/assets/image.png", ImageAssetOptions::new().with_avif())
81+
{{#include src/doc_examples/guide_assets.rs:image_asset_expansion}}
9982
```
10083
For many apps, asset optimization is the most effective way of improving load times. As developers, we frequently overlook the size of images and accidentally make our sites load slower.
10184

0 commit comments

Comments
 (0)