Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 70 lines (56 sloc) 2.093 kb
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 58 59 60 61 62 63 64 65 66 67 68 69
{-# OPTIONS_GHC -F -pgmF trhsx #-}
{-# LANGUAGE FlexibleInstances, OverloadedStrings, QuasiQuotes, TemplateHaskell, TypeOperators, TypeSynonymInstances #-}

module Main where

import Prelude hiding ((.), id)

import Control.Category
import Control.Monad
import Control.Monad.Trans
import Data.Unique
import HSX.JMacro
import Happstack.Server
import Happstack.Server.HSP.HTML
import Happstack.Server.YUI (YUISitemap(..), showCSSComboURL, createNode, fontSize, gridUnit)
import Language.Javascript.JMacro
import Text.Boomerang.TH
import Web.Routes
import Web.Routes.Boomerang
import Web.Routes.Happstack
import Web.Routes.XMLGenT ()

import qualified Happstack.Server.YUI as Y

type Application = RouteT Sitemap (ServerPartT IO)

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

data Sitemap = YUI YUISitemap | DemoURL

derivePrinterParsers ''Sitemap

sitemap :: Router () (Sitemap :- ())
sitemap = (rYUI . ("yui" </> Y.sitemap)) <> rDemoURL

site :: Site Sitemap (ServerPart Response)
site = boomerangSiteRouteT route sitemap

route :: Sitemap -> Application Response
route (YUI url) = nestURL YUI (Y.route url)
route DemoURL = liftM toResponse $ unXMLGenT demo

demo :: XMLGenT Application XML
demo = do
    title <- <h1>Set from <a href="http://yuilibrary.com/">YUI</a>!</h1>
    cssURL <- showCSSComboURL YUI ["reset", "base", "fonts", "grids"]
    <html>
      <head>
        <title>Demo application for happstack-yui</title>
        <link href=cssURL rel="stylesheet"/>
        <script src=(YUI SeedURL)/>
        <% [jmacro| YUI().use "node" \y -> y.one("h1").replace(`(y `createNode` title)`) |] %>
        <style>
          h1 { font-size: <% fontSize 36 %> }
        </style>
      </head>
      <body>
        <div class="yui3-g">
          <div class=(gridUnit 2 24)/>
          <div class="yui3-u">
            <h1>Boring unscripted title</h1>
          </div>
        </div>
      </body>
    </html>

main :: IO ()
main = simpleHTTP nullConf $ implSite "http://localhost:8000" "" site
Something went wrong with that request. Please try again.