Skip to content

Instantly share code, notes, and snippets.

@int-index
Created April 5, 2015 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save int-index/a6f121f6023cb91195a0 to your computer and use it in GitHub Desktop.
Save int-index/a6f121f6023cb91195a0 to your computer and use it in GitHub Desktop.
snap-problem
{-# LANGUAGE TemplateHaskell #-}
module Application where
import Control.Lens
import Snap.Snaplet
import Snap.Snaplet.Heist (Heist, HasHeist(..))
data App = App
{ _heist :: Snaplet (Heist App)
}
makeLenses ''App
instance HasHeist App where
heistLens = subSnaplet heist
<html>
<body>
<something/>
</body>
</html>
module Main where
import Control.Exception (SomeException, try)
import System.IO (stderr)
import qualified Data.Text.IO as Text
import Snap (runSnaplet)
import Snap.Http.Server (defaultConfig, getOther, httpServe)
import qualified Snap.Snaplet.Config as Config
import qualified Site
main :: IO ()
main = do
conf <- Config.commandLineAppConfig defaultConfig
(msgs, site, cleanup) <- runSnaplet
(getOther conf >>= Config.appEnvironment)
Site.app
Text.hPutStrLn stderr msgs
_ <- try (httpServe conf site) :: IO (Either SomeException ())
cleanup
{-# LANGUAGE OverloadedStrings #-}
module Site where
import qualified Data.ByteString as BS
import Control.Lens
import Snap
import Snap.Snaplet
import Snap.Snaplet.Heist
import Heist
import Heist.Interpreted
import Application
routes :: [(BS.ByteString, Handler App App ())]
routes = [("", handle)]
handle :: Handler App App ()
handle = do
renderWithSplices "example-template" $ do
"something" ## textSplice "Hello, world!"
app :: SnapletInit App App
app = makeSnaplet "example" "Example" Nothing $ do
let heistConfig = emptyHeistConfig & hcNamespace .~ "h"
h <- nestSnaplet "heist" heist (heistInit' "templates" heistConfig)
addRoutes routes
return (App h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment