0 people like it.

F# syntax for creating HTML/XML

 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: 
let products = 
  [ 1, "Tea", 2.3M; 
    2, "Coffee", 5.0M; 
    3, "Lemonade", 1.5M ]


[<View>]
let footer () = 
  h.contentTemplate {
    h?hr
    h?div.set("id", "footer") {
      h.content
    }
  }

[<View>]
let item (id, name, price) str = 
  h.template {
    h?li { 
      h?strong { 
        html.ActionLink(name, "details", route [ "id", id ])
      }
      !> " - Price: %s%f" str price 
    }
  }

[<View>]
let index () = 
  let title = "Product Listing"
  h?html {
    h?head {
      h?title { 
        !> "%s - View Engine Sample" title
      }
      h?link.set("typ", "text/css").set("rel", "stylesheet").set("href", "/Content/Site.css")
    }
    h?div.set("id", "main") {
      h?h1 { title }
      h?hr.set("cssclass", "heading")

      h?div { 
        h?ul.set("cssclass", "listing") {
          for prod in products do
            item prod "$"
        }
      }

      footer() {
        "This is an example of using "
        h?a.set("href", "http://fsharp.net") { 
          "the amazing F# language" 
        }
        @" for writing a simple an elegant view engine 
            for the ASP.NET MVC framework"
      }
    }
  }
val products : (int * string * decimal) list

Full name: Script.products
val footer : unit -> 'a

Full name: Script.footer
val set : elements:seq<'T> -> Set<'T> (requires comparison)

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.set
val item : id:'a * name:'b * price:'c -> str:'d -> 'e

Full name: Script.item
val id : 'a
val name : 'b
val price : 'c
val str : 'd
val index : unit -> 'a

Full name: Script.index
val title : string
Raw view Test code New version

More information

Link:http://fssnip.net/9p
Posted:14 years ago
Author:
Tags: