Skip to content

Instantly share code, notes, and snippets.

let AboutUsPage =
View.Page "About Us" [
Div [Text "TODO: describe us."]
Div [new Client.ButtonControl("Click me!")]
]
|> Sitelet.Content "/about" AboutUs
namespace WebSharperSiteletsProject
open System
open System.IO
open System.Web
open IntelliFactory.Html
open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.Sitelets
type Action =
type Id = int
type Action =
| ShowRecentBlogs
| CreateBlog
| ReadBlog of Id
| UpdateBlog of Id
| DeleteBlog of Id
let Router : Router<Action> =
let route = function
| GET (_, SPLIT_BY '/' []) ->
Some ShowRecentBlogs
| GET (_, SPLIT_BY '/' ["create"]) ->
Some CreateBlog
| GET (_, SPLIT_BY '/' ["read"; INT id]) ->
Some (ReadBlog id)
| GET (_, SPLIT_BY '/' ["update"; INT id]) ->
Some (UpdateBlog id)
let Router : Router<Action> = Router.Infer()
ShowRecentBlogs <=> /ShowRecentBlogs
CreateBlog <=> /CreateBlog
ReadBlog $x <=> /ReadBlog/$x
UpdateBlog $x <=> /UpdateBlog/$x
DeleteBlog $x <=> /DeleteBlog/$x
let Router : Router<Action> =
Router.Table [ShowRecentBlogs, "/"]
<|> Router.Infer()
let Controller =
let handle = function
| ShowRecentBlogs ->
let blogs = Model.WithBlogs <| fun db -> db.GetRecentBlogs()
View.ShowRecentBlogs blogs
| CreateBlog ->
View.CreateBlog ()
| ReadBlog id ->
let blog = Model.WithBlogs <| fun db -> db.ReadBlog id
match blog with
let Main : Sitelet<Action> =
{
Controller = Controller
Router = Router
}
module Client =
open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.Formlet
[<Rpc>]
let CreateBlog blog =
Model.WithBlogs <| fun db ->
db.CreateBlog { blog with Date = DateTime.UtcNow }
[<Rpc>]