Skip to content

Commit fa58f53

Browse files
authored
Merge pull request #124 from Tuntii/docs-maintain-feb-15-8787861394030923173
docs: Fix SSR recipe and update cookbook index
2 parents dd502c2 + 28b5d33 commit fa58f53

File tree

5 files changed

+72
-33
lines changed

5 files changed

+72
-33
lines changed

docs/.agent/docs_coverage.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
| Job Queue (Crate) | `crates/rustapi_jobs.md` | `rustapi-jobs` | OK |
1919
| Background Jobs (Recipe) | `recipes/background_jobs.md` | `rustapi-jobs` | OK |
2020
| **Integrations** | | | |
21-
| gRPC | `recipes/grpc_integration.md` | `rustapi-grpc` | NEW |
22-
| SSR | `recipes/server_side_rendering.md` | `rustapi-view` | NEW |
23-
| AI / TOON | `recipes/ai_integration.md` | `rustapi-toon` | NEW |
21+
| gRPC | `recipes/grpc_integration.md` | `rustapi-grpc` | OK |
22+
| SSR | `recipes/server_side_rendering.md` | `rustapi-view` | OK |
23+
| AI / TOON | `recipes/ai_integration.md` | `rustapi-toon` | OK |
2424
| **Learning** | | | |
2525
| Structured Path | `learning/curriculum.md` | N/A | OK |
2626
| **Recipes** | | | |
2727
| File Uploads | `recipes/file_uploads.md` | `rustapi-core` | OK |
2828
| Deployment | `recipes/deployment.md` | `cargo-rustapi` | OK |
29+
| Testing | `recipes/testing.md` | `rustapi-testing` | OK |

docs/.agent/last_run.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"last_processed_ref": "v0.1.335",
3-
"date": "2025-02-24",
4-
"notes": "Added Phase 5 (Specialized Skills) to Learning Path, and created recipes for gRPC, SSR, and AI Integration."
3+
"date": "2026-02-15",
4+
"notes": "Fixed critical inaccuracy in SSR recipe. Updated recipes index to be comprehensive. Verified docs coverage."
55
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Run Report: 2026-02-15
2+
3+
## 1. Version Detection
4+
- **Target Version:** `v0.1.335`
5+
- **Previous Run:** `v0.1.335` (2025-02-24)
6+
- **Status:** No code changes detected since last run. Proceeding with Continuous Improvement Phase.
7+
8+
## 2. Discovery
9+
- **Date Gap:** Significant time has passed since the last run (almost 1 year).
10+
- **Cookbook Issues:**
11+
- `docs/cookbook/src/recipes/README.md` is outdated and missing many recipe links.
12+
- `docs/cookbook/src/recipes/server_side_rendering.md` contains incorrect instructions (claims auto-configuration that doesn't exist).
13+
- **Docs Coverage:** `rustapi-view` documentation is misleading and needs correction.
14+
15+
## 3. Plan
16+
- **Fix Recipes Index:** Populate `recipes/README.md` with all available recipes.
17+
- **Fix SSR Recipe:** Rewrite the Server-Side Rendering recipe to correctly show manual `Templates` initialization and state injection.
18+
- **Update Coverage:** Mark `rustapi-view` as corrected.
19+
20+
## 4. Improvements
21+
- Aligned documentation with actual code behavior for `rustapi-view`.
22+
- Improved discoverability of recipes by updating the index.

docs/cookbook/src/recipes/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ Each recipe follows a simple structure:
1212
## Table of Contents
1313

1414
- [Creating Resources](crud_resource.md)
15+
- [Pagination & HATEOAS](pagination.md)
1516
- [JWT Authentication](jwt_auth.md)
17+
- [CSRF Protection](csrf_protection.md)
1618
- [Database Integration](db_integration.md)
19+
- [Testing & Mocking](testing.md)
1720
- [File Uploads](file_uploads.md)
21+
- [Background Jobs](background_jobs.md)
1822
- [Custom Middleware](custom_middleware.md)
1923
- [Real-time Chat](websockets.md)
24+
- [Server-Side Rendering (SSR)](server_side_rendering.md)
25+
- [AI Integration (TOON)](ai_integration.md)
2026
- [Production Tuning](high_performance.md)
27+
- [Resilience Patterns](resilience.md)
28+
- [Time-Travel Debugging (Replay)](replay.md)
2129
- [Deployment](deployment.md)
2230
- [HTTP/3 (QUIC)](http3_quic.md)
31+
- [gRPC Integration](grpc_integration.md)
32+
- [Automatic Status Page](status_page.md)

docs/cookbook/src/recipes/server_side_rendering.md

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Create a `templates` directory in your project root.
2323
<head>
2424
<meta charset="UTF-8">
2525
<title>{% block title %}My App{% endblock %}</title>
26-
<link rel="stylesheet" href="/assets/style.css">
2726
</head>
2827
<body>
2928
<nav>
@@ -36,7 +35,7 @@ Create a `templates` directory in your project root.
3635
</main>
3736

3837
<footer>
39-
&copy; 2025 RustAPI
38+
&copy; 2026 RustAPI
4039
</footer>
4140
</body>
4241
</html>
@@ -66,11 +65,11 @@ Create a `templates` directory in your project root.
6665

6766
## Handling Requests
6867

69-
In your `main.rs`, use the `View` type and `Context`.
68+
In your `main.rs`, initialize the `Templates` engine and inject it into the application state. Handlers can then extract it using `State<Templates>`.
7069

7170
```rust,no_run
7271
use rustapi_rs::prelude::*;
73-
use rustapi_view::{View, Context};
72+
use rustapi_view::{View, Templates};
7473
use serde::Serialize;
7574
7675
#[derive(Serialize)]
@@ -79,35 +78,43 @@ struct User {
7978
is_admin: bool,
8079
}
8180
82-
#[rustapi_rs::get("/")]
83-
async fn index() -> View {
84-
// 1. Create context
85-
let mut ctx = Context::new();
86-
87-
// 2. Insert data
88-
ctx.insert("app_name", "My Awesome App");
81+
#[derive(Serialize)]
82+
struct HomeContext {
83+
app_name: String,
84+
user: User,
85+
items: Vec<String>,
86+
}
8987
90-
let user = User {
91-
name: "Alice".to_string(),
92-
is_admin: true,
88+
#[rustapi_rs::get("/")]
89+
async fn index(templates: State<Templates>) -> View<HomeContext> {
90+
let context = HomeContext {
91+
app_name: "My Awesome App".to_string(),
92+
user: User {
93+
name: "Alice".to_string(),
94+
is_admin: true,
95+
},
96+
items: vec!["Apple".to_string(), "Banana".to_string(), "Cherry".to_string()],
9397
};
94-
ctx.insert("user", &user);
9598
96-
ctx.insert("items", &vec!["Apple", "Banana", "Cherry"]);
97-
98-
// 3. Render template
99-
// RustAPI automatically loads templates from the "templates" directory
100-
View::new("index.html", ctx)
99+
// Render the "index.html" template with the context
100+
View::render(&templates, "index.html", context).await
101101
}
102102
103103
#[tokio::main]
104-
async fn main() {
105-
// No special setup needed for View, it's auto-configured if the crate is present
106-
// and the "templates" directory exists.
107-
let app = RustApi::new().route("/", get(index));
104+
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
105+
// 1. Initialize Template Engine
106+
// Loads all .html files from the "templates" directory
107+
let templates = Templates::new("templates/**/*.html")?;
108+
109+
// 2. Add to State
110+
let app = RustApi::new()
111+
.state(templates)
112+
.route("/", get(index));
108113
109114
println!("Listening on http://localhost:3000");
110115
app.run("0.0.0.0:3000").await.unwrap();
116+
117+
Ok(())
111118
}
112119
```
113120

@@ -119,12 +126,11 @@ In **Release** mode (`cargo run --release`), templates are compiled and cached f
119126

120127
## Asset Serving
121128

122-
To serve CSS, JS, and images, use `ServeDir` from `tower-http` (re-exported or available via `rustapi-extras` if configured, or just standard tower).
129+
To serve CSS, JS, and images, use `serve_static` on the `RustApi` builder.
123130

124131
```rust,ignore
125-
use tower_http::services::ServeDir;
126-
127132
let app = RustApi::new()
133+
.state(templates)
128134
.route("/", get(index))
129-
.nest_service("/assets", ServeDir::new("assets"));
135+
.serve_static("/assets", "assets"); // Serves files from ./assets at /assets
130136
```

0 commit comments

Comments
 (0)