Skip to content

Commit 9c95c1c

Browse files
authored
Merge pull request #15 from togglebyte/dev
section on `with`
2 parents bb06038 + 279b742 commit 9c95c1c

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

src/SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Loops](./templates/loops.md)
1515
- [If / Else](./templates/if-else.md)
1616
- [Switch / Case](./templates/switch-case.md)
17+
- [With](./templates/with.md)
1718
- [Functions](./templates/functions.md)
1819
- [Custom functions](./templates/functions/custom.md)
1920
- [Elements](./templates/elements.md)
@@ -35,3 +36,5 @@
3536
- [container](./templates/elements/container.md)
3637
- [Inputs and other components](./anathema-extras.md)
3738
- [Input](./anathema-extras/input.md)
39+
- [Recipes](./recipes.md)
40+
- [Routing](./recipes/routing.md)

src/recipes.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Recipes
2+
3+
* Themeing
4+
* Async
5+
* [Routing](./recipes/routing.md)
6+
7+
```rust,ignore
8+
#[derive(State)]
9+
struct MyState {
10+
value: Value<bool>,
11+
}
12+
```
13+
14+
```aml
15+
border
16+
vstack
17+
text "Hello world"
18+
```

src/recipes/routing.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Routing
2+
3+
Routing can be done with a combination of state and `switch`.
4+
5+
TODO
6+
THIS IS UNFINISHED
7+
8+
```rust,ignore
9+
struct Router;
10+
11+
impl Component for Router {
12+
State = String;
13+
Message = String;
14+
}
15+
```
16+
17+
```aml
18+
text "hello"
19+
span "sausage"
20+
```

src/templates/with.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# With
2+
3+
A `with` makes it possible to scope an expression for nodes
4+
5+
## Example
6+
7+
```
8+
let THEME = [
9+
{ fg: "red", bool: true },
10+
{ fg: "green", bool: false },
11+
{ fg: "blue", bool: true },
12+
];
13+
14+
15+
border
16+
with theme as colors[state.some_count % 2 == 0]
17+
// Refering to `theme` instead of repeating `colors[state.some_count % 2 == 0]`
18+
19+
text [foreground: theme.fg] "hello "
20+
span [bold: theme.bold] "world"
21+
22+
```

0 commit comments

Comments
 (0)