HTML Table
The table at the bottom of the page (Welcome to 1997!) was created on the fly by the following Fay:
colors :: [[String]]
colors = go [ (r,g,b) | r <- s, g <- s, b <- s]
where s = [0, 0x33 .. 0xff]
go [] = []
go xs = map rgb (take 24 xs) : go (drop 24 xs)
tableMU :: Markup
tableMU = markup ! table !+ foldl1 (!+) (map row colors) ! Complete
where row x = markup ! tr !+ foldl1 (!+) (map box x) ! Complete
box x = markup ! td ! sty x ! inner "λ" ! Complete
sty x = style ("height:20px;width:20px;background-color:" ++ x)
htex :: Fay ()
htex = root >>= byTag "body" >>= zipWithM_ insert [tableMU]
(If you don't understand the !
and !+
stuff, look at the SVG examples and the README. This example just demonstrates the applicability to HTML.)
I won't bother to explain the HTML or the Haskell to you, as, if you're reading this, you're probably more expert than I am at both.
The are only a few points of note as regards Cinder:
- The λ is injected via
inner
, which is a convenience forProperty "innerHTML"
, as opposed to just adding the lambda as content using!:
orContent
.inner
adds the unescaped entity while!:
would insert the string "λ". zipWithM_ insert
is used becausebyTag
returns aNode
list. Here, we bump our one element list ofMarkup
against what we hope to be the only 'body' element. Note thatzipWithM_
is not in the (Fay)Prelude
, but is provided in Cinder'sControl.Fay
.- The λ could have been injected into all the
td
s by several different methods, even after the initialMarkup
insertion, e.g.:root >>= byTag "td" >>= mapM_ (setProperty "innerHTML" "λ")
And, after the footer, behold our amazing technicolor dreamtable: