File: example.hs

package info (click to toggle)
haskell-hsx-jmacro 7.3.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 88 kB
  • sloc: haskell: 252; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download | duplicates (5)
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
{-# LANGUAGE FlexibleInstances, QuasiQuotes #-}
{-# OPTIONS_GHC -F -pgmFtrhsx #-}
module Main where

import Language.Javascript.JMacro
import HSX.JMacro
import HSP
import HSP.Identity
import HSP.ServerPartT
import Happstack.Server
import Happstack.Server.HSP.HTML
import Happstack.Server.JMacro
import Data.Unique
import Control.Monad.Trans

instance IntegerSupply (ServerPartT IO) where
    nextInteger = fmap (fromIntegral . (`mod` 1024) . hashUnique) (liftIO newUnique)

main :: IO ()
main =
    do let html :: DOMNode
           html = <p>Generate javascript from <span class="foo" id="h">HTML & XML</span>.</p>

           js :: JStat
           js = [jmacro| document.getElementById('main').appendChild(`(html)`);
                       |]

           handler :: ServerPart XML
           handler = defaultTemplate "js-example" ()
                       <%>
                         <div id="main" />
                         <% js %>
                       </%>

       simpleHTTP nullConf handler