Created
April 5, 2015 19:08
-
-
Save int-index/a6f121f6023cb91195a0 to your computer and use it in GitHub Desktop.
snap-problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<something/> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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