Skip to content

Instantly share code, notes, and snippets.

@jbpotonnier
Created April 20, 2015 22:32
Show Gist options
  • Save jbpotonnier/36576a969e90bd2a522c to your computer and use it in GitHub Desktop.
Save jbpotonnier/36576a969e90bd2a522c to your computer and use it in GitHub Desktop.
intercooler.js + Spock + Lucid
{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules, DataKinds #-}
import Web.Spock.Safe
import Lucid
import Lucid.Base (makeAttribute)
import Data.Text.Lazy (toStrict)
import Data.Text (Text)
import Network.Wai.Middleware.Static
page :: Html () -> Html ()
page content =
doctypehtml_ $ do
content
script_ [src_ "vendor/javascript/jquery-2.1.3.min.js"] ("" :: String)
script_ [src_ "vendor/javascript/intercooler-0.4.10.min.js"] ("" :: String)
icPostTo_ :: Text -> Attribute
icPostTo_ = makeAttribute "ic-post-to"
renderLucid :: Html () -> ActionT IO a
renderLucid = html . toStrict . renderText
buttonClickR :: Path '[]
buttonClickR = "/button_click"
main :: IO ()
main =
runSpock 3000 $ spockT id $ do
middleware $ staticPolicy (noDots >-> addBase "static")
get "test" $
renderLucid . page $
span_ [icPostTo_ (renderRoute buttonClickR)] "click me"
post buttonClickR $
renderLucid "button clicked"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment