Advertisement
Guest User

Untitled

a guest
Dec 16th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.82 KB | None | 0 0
  1. namespace HtmlSite1
  2.  
  3. open System
  4. open System.IO
  5. open System.Web
  6. open IntelliFactory.WebSharper.Sitelets
  7.  
  8. /// Defines a sample HTML site with nested pages
  9. module SampleSite =
  10.     open IntelliFactory.WebSharper
  11.     open IntelliFactory.Html
  12.  
  13.     // Action type
  14.     type Action =
  15.         | Index
  16.         | Page1
  17.         | Page2
  18.  
  19.     module Skin =
  20.  
  21.         type Page =
  22.             {
  23.                 Title : string
  24.                 Body : list<Content.HtmlElement>
  25.             }
  26.  
  27.         let MainTemplate =
  28.             let path = Path.Combine(__SOURCE_DIRECTORY__, "Main.html")
  29.             Content.Template<Page>(path)
  30.                 .With("title", fun x -> x.Title)
  31.                 .With("body", fun x -> x.Body)
  32.  
  33.         let WithTemplate title body : Content<Action> =
  34.             Content.WithTemplate MainTemplate <| fun context ->
  35.                 {
  36.                     Title = title
  37.                     Body = body context
  38.                 }
  39.  
  40.     // Module containing client-side controls
  41.     module Client =
  42.         open IntelliFactory.WebSharper.Html
  43.  
  44.         type MyControl() =
  45.             inherit IntelliFactory.WebSharper.Web.Control ()
  46.  
  47.             [<JavaScript>]
  48.             override this.Body =
  49.                 I [Text "Client control"] :> IPagelet
  50.  
  51.     let Index =
  52.         Skin.WithTemplate "Index page" <| fun ctx ->
  53.             [
  54.                 H1 [Text "Pages"]
  55.                 UL [
  56.                     LI [A [HRef (ctx.Link Action.Page1)] -< [Text "Page 1"]]
  57.                     LI [A [HRef (ctx.Link Action.Page2)] -< [Text "Page 2"]]
  58.                 ]
  59.             ]
  60.  
  61.     let Page1 =
  62.         Skin.WithTemplate "Title of Page1" <| fun ctx ->
  63.             let url =  ctx.Link Action.Page2
  64.             [
  65.                 H1 [Text "Page 1"]
  66.                 A [HRef url] -< [Text "Page 2"]
  67.             ]
  68.  
  69.     let Page2 =
  70.         Skin.WithTemplate "Title of Page2" <| fun ctx ->
  71.             [
  72.                 H1 [Text "Page 2"]
  73.                 A [HRef <| ctx.Link Action.Page1] -< [Text "Page 1"]
  74.                 Div [new Client.MyControl ()]
  75.             ]
  76.  
  77.     let MySitelet =
  78.         [
  79.             Sitelet.Content "/index" Action.Index Index
  80.             Sitelet.Folder "/pages" [
  81.                 Sitelet.Content "/page1" Action.Page1 Page1
  82.                 Sitelet.Content "/page2" Action.Page2 Page2
  83.             ]
  84.         ]
  85.         |> Sitelet.Sum
  86.  
  87.     // Actions to generate pages from
  88.     let MyActions =
  89.         [
  90.             Action.Index
  91.             Action.Page1
  92.             Action.Page2
  93.         ]
  94.  
  95. /// The class that contains the website
  96. type MySampleWebsite() =
  97.     interface IWebsite<SampleSite.Action> with
  98.         member this.Sitelet = SampleSite.MySitelet
  99.         member this.Actions = SampleSite.MyActions
  100.  
  101. [<assembly: WebsiteAttribute(typeof<MySampleWebsite>)>]
  102. do ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement