File tree 4 files changed +46
-48
lines changed 4 files changed +46
-48
lines changed Original file line number Diff line number Diff line change 1
- .vscode /
1
+ .vscode /
2
+ main.ua
Original file line number Diff line number Diff line change 1
1
# Experimental!
2
- ~ "../lib.ua"
3
- ~ ! A B Body Br Button Div Em Form Head Html H₁ H₂ H₃ H₄ H₅ H₆ I Li Meta Ol P Script Span Strong Style Table Title Ul
4
- ~ HXGet HXSwap HXTarget NotFound ResHTML Response Serve!
2
+ Html ~ "../lib.ua" ~ HtmlResp NotFound Serve!
5
3
6
- Item ← Div {
7
- ⊓(
8
- | Button {HXSwap "outerHTML" HXTarget "closest div" ⊃(HXGet $"/item-tog/_"|$"Item: _")}
9
- | Br {}
10
- Br {}
11
- )
12
- }
4
+ Item ← Html!(
5
+ Div{⊓(
6
+ Button {HXSwap "outerHTML" HXTarget "closest div" ⊃(HXGet $"/item-tog/_"|$"Item: _")}
7
+ | Br {}
8
+ )}
9
+ )
13
10
14
- Index ← (
11
+ Index ← Html! (
15
12
Html {
16
13
Head {
17
14
Title "Webua"
15
+ Meta {!charset "utf-8"}
18
16
Script {!src "https://unpkg.com/
[email protected] "}
19
17
}
20
18
Body {
21
19
H₁ "Webua Example"
22
- P "This is a simple example of Webua templating. "
20
+ P "This is a simple example of Webua templating with HTMX! "
23
21
Item "a"
24
22
Item "b"
25
23
Item "c"
26
24
}
27
25
}
28
- ResHTML
29
- )
30
-
31
- RespondItem ← (
32
- Item
33
- ResHTML
34
26
)
35
27
36
28
Route ← ⍣(
37
- ⍩Index°"/"
38
- | ⍩RespondItem¯ ? °$"/item-tog/_"
29
+ ⍩(HtmlResp Index) °"/"
30
+ | ⍩(HtmlResp Item) ¯ °$"/item-tog/_"
39
31
| NotFound
40
32
)
41
33
42
- Serve!( Route)
34
+ Serve!Route 8080
Original file line number Diff line number Diff line change 1
1
Xml ~ "xml" ~ ! Tags!
2
2
~ "xml" ~ ! Tags!
3
3
4
- Listener ← &tcpl "0.0.0.0:8080"
5
-
6
4
HXGet ← $$ hx-get="_"
7
5
HXPost ← $$ hx-post="_"
8
6
HXSwap ← $$ hx-swap="_"
9
7
HXTarget ← $$ hx-target="_"
10
8
11
- # ? Status Mime Bytes
9
+ # Construct an HTTP response
10
+ # ResponseBytes ? Status Mime Bytes
12
11
Response ← (
13
- ⊙⊙(⧻.)
12
+ ⊙⊙⊸⧻
14
13
$$ HTTP/1.1 _
15
14
$$ Content-Type: _
16
15
$$ Content-Length: _
17
16
$$
18
17
$$
19
18
⊂ utf₈
20
19
)
20
+ # Construct a simple text HTTP response
21
+ TextResp ← Response "200 OK" "text/html" utf₈
22
+ # A simple not found HTTP response
23
+ NotFound ← (Response "404 Not Found" "text/plain" utf₈"Not Found")
24
+ # Construct a simple HTML HTTP response
25
+ HtmlResp ← Response "200 OK" "text/html" utf₈
21
26
22
- ResHTML ← (Response "200 OK" "text/html" utf₈)
23
-
24
- Respond! ← ◌pool(
25
- &p $"Request from _" &tcpaddr.
26
- # Extract path from request
27
- °□⊡1 ⊜□≠@\s . &ru "\r\n\r\n".
28
- &p $"Request:\n_".
29
-
30
- ^0
31
- &p⊸($"Response: _ bytes" ⧻)
32
-
33
- # Send response
34
- ⊃⋅&cl&w
27
+ Respond! ← (
28
+ &w⊸(
29
+ ⟜(&p $"Request from _" &tcpaddr)
30
+ °□⊡1 ⊜□⊸≠@\s &ru "\r\n\r\n"
31
+ ⟜(&p $"Request:\n_")
32
+ ^0
33
+ ⟜(&p $"Response: _ bytes" ⧻)
34
+ )
35
35
)
36
36
37
- Serve! ← ⍢(⍣Respond!(^0)⋅&p &tcpa Listener)1
37
+ Sig! ↚^ ⋅⊢
38
38
39
- NotFound ← (
40
- Response "404 Not Found" "text/plain" utf₈"Not Found"
39
+ # Start a server on the given port.
40
+ # The function will be called on the TCP socket for each incoming connection.
41
+ # ? Port
42
+ Serve! ← (
43
+ &tcpl $"0.0.0.0:_"
44
+ ⟜(&p $"Server started on _" &tcpaddr)
45
+ ⍢(⍜&tcpa(⍣Respond!^0⋅&p))1
41
46
)
42
47
43
48
Tags!(
Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ Templating is done with tag functions. A tag function is passed a list of attrib
9
9
The ` ! ` macro makes it easy to define attributes.
10
10
11
11
``` uiua
12
- ~ "git: github.com/uiua-lang/webua" ~ ! Html Head Body P Br H₁ Title Meta Style
12
+ Html ~ "git: github.com/uiua-lang/webua"
13
13
14
- Html {
14
+ Html!(Html {
15
15
Head {
16
16
Title "Example"
17
17
Meta {!charset "utf-8"}
@@ -22,19 +22,19 @@ Html {
22
22
P "This is a simple example of Webua templating."
23
23
Br {}
24
24
}
25
- }
25
+ })
26
26
```
27
27
28
28
You can use normal Uiua primitives to fill out data.
29
29
30
30
``` uiua
31
- ~ "git: github.com/uiua-lang/webua" ~ Div H₁ Ul Li
31
+ ~ "git: github.com/uiua-lang/webua"
32
32
33
33
$Users {"Alice" "Bob" "Carol"}
34
- Div {
34
+ Html!( Div {
35
35
H₁ "Users"
36
36
Ul ⍚Li
37
- }
37
+ })
38
38
## "<div><h1>Users</h1><ul><li>Alice</li><li>Bob</li><li>Carol</li></ul></div>"
39
39
```
40
40
You can’t perform that action at this time.
0 commit comments