-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSite.fs
58 lines (48 loc) · 1.55 KB
/
Site.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace ws_1044
open WebSharper
open WebSharper.Sitelets
open WebSharper.UI
open WebSharper.UI.Server
type EndPoint =
| [<EndPoint "/">] Home
| [<EndPoint "/about">] About
module Templating =
open WebSharper.UI.Html
type MainTemplate = Templating.Template<"Main.html">
// Compute a menubar where the menu item for the given endpoint is active
let MenuBar (ctx: Context<EndPoint>) endpoint : Doc list =
let ( => ) txt act =
li [if endpoint = act then yield attr.``class`` "active"] [
a [attr.href (ctx.Link act)] [text txt]
]
[
"Home" => EndPoint.Home
"About" => EndPoint.About
]
let Main ctx action (title: string) (body: Doc list) =
Content.Page(
MainTemplate()
.Title(title)
.MenuBar(MenuBar ctx action)
.Body(body)
.Doc()
)
module Site =
open WebSharper.UI.Html
let HomePage ctx =
Templating.Main ctx EndPoint.Home "Home" [
h1 [] [text "Say Hi to the server!"]
div [] [client <@ Client.Main() @>]
]
let AboutPage ctx =
Templating.Main ctx EndPoint.About "About" [
h1 [] [text "About"]
p [] [text "This is a template WebSharper client-server application."]
]
[<Website>]
let Main =
Application.MultiPage (fun ctx endpoint ->
match endpoint with
| EndPoint.Home -> HomePage ctx
| EndPoint.About -> AboutPage ctx
)