HTML markup
It's time to replace plain text placeholders in containers with meaningful content.
First, define h2
in View
module to output HTML header of level 2:
View.fs
6:
|
|
and replace text
with a new h2
in each of the 4 containers.
We'd like the /store
route to output hyperlinks to all genres in our Music Store.
Let's add a helper function in Path
module, that will be responsible for formatting HTTP urls with a key-value parameter:
Path.fs
5:
|
|
The withParam
function takes a tuple (key,value)
as its first argument, path
as the second and returns a properly formatted url.
A tuple (or a pair) is a widely used structure in F#. It allows us to group two values into one in an easy manner.
Syntax for creating a tuple is as follows: (item1, item2)
- this might look like a standard parameter passing in many other languages including C#.
Follow this link to learn more about tuples.
Add also a string key for the url parameter "/store/browse" in Path.Store
module:
Path.fs
14:
|
|
We'll use it in App
module:
App.fs
13: 14: 15: 16: 17: |
|
Now, add the following for working with the unordered list (ul
) and list item (li
) elements in HTML:
View.fs
7: 8: |
|
The actual container for store
can now look like the following:
View.fs
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: |
|
Things worth commenting in the above snippet:
store
now takes a list of genres (again the type is inferred by the compiler)- the
[ for g in genres -> ... ]
syntax is known as "list comprehension". Here we map every genre string fromgenres
to a list item aHref
inside list item points to thePath.Store.browse
url with "genre" parameter - we use thePath.withParam
function defined earlier
To use View.store
from App
module, let's simply pass a hardcoded list for genres
like following:
App.fs
22:
|
|
Full name: SuaveMusicStore.Path.IntPath
type PrintfFormat<'Printer,'State,'Residue,'Result> =
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result>
member Value : string
Full name: Microsoft.FSharp.Core.PrintfFormat<_,_,_,_>
--------------------
type PrintfFormat<'Printer,'State,'Residue,'Result,'Tuple> =
inherit PrintfFormat<'Printer,'State,'Residue,'Result>
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result,'Tuple>
Full name: Microsoft.FSharp.Core.PrintfFormat<_,_,_,_,_>
--------------------
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result>
--------------------
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result,'Tuple>
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
Full name: Microsoft.FSharp.Core.unit
Full name: SuaveMusicStore.Path.withParam
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
Full name: SuaveMusicStore.Path.home
from SuaveMusicStore.Path
Full name: SuaveMusicStore.Path.Store.overview
Full name: SuaveMusicStore.Path.Store.browse
Full name: SuaveMusicStore.Path.Store.details
Full name: SuaveMusicStore.Path.Store.browseKey
from Suave
Full name: SuaveMusicStore.View.cssLink
Full name: Suave.Html.link
Full name: SuaveMusicStore.View.h2
Full name: Suave.Html.tag
Full name: SuaveMusicStore.View.ul
Full name: SuaveMusicStore.View.li
Full name: SuaveMusicStore.View.home
Full name: SuaveMusicStore.View.store
Full name: Suave.Html.p
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member GetSlice : startIndex:int option * endIndex:int option -> 'T list
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
Full name: Microsoft.FSharp.Collections.List.length
from SuaveMusicStore
Full name: Suave.Html.a
Full name: SuaveMusicStore.View.browse
Full name: SuaveMusicStore.View.details
Full name: SuaveMusicStore.View.index
Full name: Suave.Html.html
Full name: Suave.Html.head
Full name: Suave.Html.title
Full name: Suave.Html.body
Full name: Suave.Html.div
Full name: Suave.Html.htmlToString
from SuaveMusicStore
from Suave
from Suave
from Suave
from Suave
from Suave
Full name: SuaveMusicStore.App.html
Full name: Suave.Successful.OK
from SuaveMusicStore
Full name: SuaveMusicStore.View.index
Full name: SuaveMusicStore.App.browse
Full name: Suave.Http.request
Full name: SuaveMusicStore.View.browse
Full name: Suave.RequestErrors.BAD_REQUEST
Full name: SuaveMusicStore.App.webPart
Full name: Suave.WebPart.choose
Full name: Suave.Filters.path
Full name: SuaveMusicStore.View.home
Full name: SuaveMusicStore.View.store
Full name: Suave.Filters.pathScan
Full name: SuaveMusicStore.Path.Store.details
Full name: SuaveMusicStore.View.details
Full name: Suave.Filters.pathRegex
from Suave
Full name: Suave.Files.browseHome
Full name: Suave.Web.startWebServer
Full name: Suave.Web.defaultConfig
Show code from this section on GitHub