diff --git a/project_template/default/foo.cabal b/project_template/default/foo.cabal index fd497dcf..461a29b7 100644 --- a/project_template/default/foo.cabal +++ b/project_template/default/foo.cabal @@ -19,20 +19,20 @@ Executable projname main-is: Main.hs Build-depends: - base >= 4 && < 5, - bytestring >= 0.9.1 && < 0.10, - data-lens >= 2.0.1 && < 2.11, - data-lens-template >= 2.1 && < 2.2, - heist >= 0.8 && < 0.9, + base >= 4 && < 5, + bytestring >= 0.9.1 && < 0.10, + data-lens >= 2.0.1 && < 2.11, + data-lens-template >= 2.1 && < 2.2, + heist >= 0.10 && < 0.11, MonadCatchIO-transformers >= 0.2.1 && < 0.4, - mtl >= 2 && < 3, - snap == 0.9.*, - snap-core == 0.9.*, - snap-server == 0.9.*, - snap-loader-static == 0.9.*, - text >= 0.11 && < 0.12, - time >= 1.1 && < 1.5, - xmlhtml >= 0.1 + mtl >= 2 && < 3, + snap >= 0.10 && < 0.11, + snap-core == 0.9.*, + snap-server == 0.9.*, + snap-loader-static == 0.9.*, + text >= 0.11 && < 0.12, + time >= 1.1 && < 1.5, + xmlhtml >= 0.1 if flag(development) build-depends: diff --git a/project_template/default/src/Site.hs b/project_template/default/src/Site.hs index 41e4917c..fe83cc25 100644 --- a/project_template/default/src/Site.hs +++ b/project_template/default/src/Site.hs @@ -20,7 +20,8 @@ import Snap.Snaplet.Auth.Backends.JsonFile import Snap.Snaplet.Heist import Snap.Snaplet.Session.Backends.CookieSession import Snap.Util.FileServe -import Text.Templating.Heist +import Heist +import qualified Heist.Interpreted as I ------------------------------------------------------------------------------ import Application @@ -28,9 +29,9 @@ import Application ------------------------------------------------------------------------------ -- | Render login form handleLogin :: Maybe T.Text -> Handler App (AuthManager App) () -handleLogin authError = heistLocal (bindSplices errs) $ render "login" +handleLogin authError = heistLocal (I.bindSplices errs) $ render "login" where - errs = [("loginError", textSplice c) | c <- maybeToList authError] + errs = [("loginError", I.textSplice c) | c <- maybeToList authError] ------------------------------------------------------------------------------ diff --git a/project_template/tutorial/foo.cabal b/project_template/tutorial/foo.cabal index 1fd72dde..1142d358 100644 --- a/project_template/tutorial/foo.cabal +++ b/project_template/tutorial/foo.cabal @@ -19,7 +19,7 @@ Executable projname bytestring >= 0.9.1 && < 0.10, MonadCatchIO-transformers >= 0.2.1 && < 0.4, mtl >= 2 && < 3, - snap >= 0.9 && < 0.10, + snap >= 0.10 && < 0.11, snap-core >= 0.9 && < 0.10, snap-server >= 0.9 && < 0.10 diff --git a/src/Snap/Snaplet/Heist.hs b/src/Snap/Snaplet/Heist.hs index 8f7c225b..f25b33e0 100644 --- a/src/Snap/Snaplet/Heist.hs +++ b/src/Snap/Snaplet/Heist.hs @@ -95,7 +95,7 @@ class HasHeist b where -- this function to add their own templates. The templates are automatically -- read from the templates directory in the current snaplet's filesystem root. addTemplates :: HasHeist b - => Heist b + => Snaplet (Heist b) -> ByteString -- ^ The url prefix for the template routes -> Initializer b v () @@ -110,7 +110,7 @@ addTemplates h pfx = withTop' heistLens (Unclassed.addTemplates h pfx) -- getSnapletFilePath if you want your snaplet to use templates within its -- normal directory structure. addTemplatesAt :: HasHeist b - => Heist b + => Snaplet (Heist b) -> ByteString -- ^ URL prefix for template routes -> FilePath diff --git a/src/Snap/Snaplet/HeistNoClass.hs b/src/Snap/Snaplet/HeistNoClass.hs index 59d439e6..4ee42af1 100644 --- a/src/Snap/Snaplet/HeistNoClass.hs +++ b/src/Snap/Snaplet/HeistNoClass.hs @@ -301,7 +301,7 @@ finalLoadHook (Running _ _) = left "finalLoadHook called while running" -- | Adds templates to the Heist HeistConfig. Other snaplets should use -- this function to add their own templates. The templates are automatically -- read from the templates directory in the current snaplet's filesystem root. -addTemplates :: Heist b +addTemplates :: Snaplet (Heist b) -> ByteString -- ^ The url prefix for the template routes -> Initializer b (Heist b) () @@ -317,7 +317,7 @@ addTemplates h urlPrefix = do -- your templates are located, but means that you have to explicitly call -- getSnapletFilePath if you want your snaplet to use templates within its -- normal directory structure. -addTemplatesAt :: Heist b +addTemplatesAt :: Snaplet (Heist b) -> ByteString -- ^ URL prefix for template routes -> FilePath @@ -337,7 +337,7 @@ addTemplatesAt h urlPrefix templateDir = do , "with route prefix" , fullPrefix ++ "/" ] - liftIO $ atomicModifyIORef (_heistConfig h) + liftIO $ atomicModifyIORef (_heistConfig $ extract h) (\hc -> (hc `mappend` mempty { hcTemplates = ts }, ())) diff --git a/src/Snap/Snaplet/Internal/Types.hs b/src/Snap/Snaplet/Internal/Types.hs index d2652310..42cc8bf7 100644 --- a/src/Snap/Snaplet/Internal/Types.hs +++ b/src/Snap/Snaplet/Internal/Types.hs @@ -6,6 +6,10 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE FlexibleInstances #-} +#ifndef MIN_VERSION_comonad +#define MIN_VERSION_comonad(x,y,z) 1 +#endif + module Snap.Snaplet.Internal.Types where import Prelude hiding ((.), id) diff --git a/test/snap-testsuite.cabal b/test/snap-testsuite.cabal index a5f73a22..a9550086 100644 --- a/test/snap-testsuite.cabal +++ b/test/snap-testsuite.cabal @@ -1,7 +1,7 @@ name: snap-testsuite version: 0.0.1 build-type: Simple -cabal-version: >= 1.6 +cabal-version: >= 1.8 Executable snap-testsuite hs-source-dirs: ../src suite @@ -15,25 +15,36 @@ Executable snap-testsuite attoparsec >= 0.10 && <0.11, base >= 4 && < 5, bytestring >= 0.9 && < 0.10, + cereal >= 0.3 && < 0.4, + clientsession >= 0.7 && < 0.8, + comonad >= 3.0 && < 3.1, + configurator >= 0.1 && < 0.3, containers >= 0.3, data-lens >= 2.0.1 && < 2.11, data-lens-template >= 2.1.1 && < 2.2, directory, directory-tree >= 0.10 && < 0.11, + dlist >= 0.5 && < 0.6, + errors >= 1.3.1 && < 1.4, filepath, + hashable >= 1.1, heist >= 0.10 && < 0.11, http-conduit >= 1.4 && < 1.5, http-types >= 0.6 && < 0.7, mtl >= 2, + mwc-random >= 0.8, process == 1.*, snap-core >= 0.9 && < 0.10, snap-server >= 0.9 && < 0.10, + syb >= 0.1, test-framework >= 0.6 && <0.7, test-framework-hunit >= 0.2.7 && <0.3, test-framework-quickcheck2 >= 0.2.12.1 && <0.3, text >= 0.11 && < 0.12, + time >= 1.1, transformers >= 0.2, unix >= 2.2.0.0 && < 2.6, + unordered-containers >= 0.1.4, utf8-string >= 0.3 && < 0.4, template-haskell @@ -69,14 +80,17 @@ Executable app attoparsec >= 0.10 && < 0.11, base >= 4 && < 5, bytestring >= 0.9 && < 0.10, - cereal >= 0.3, + cereal >= 0.3 && < 0.4, clientsession >= 0.7.3.6 && < 0.8, + comonad >= 3.0 && < 3.1, configurator >= 0.1 && < 0.3, containers >= 0.3, data-lens >= 2.0.1 && < 2.11, data-lens-template >= 2.1.1 && < 2.2, directory, directory-tree >= 0.10 && < 0.11, + dlist >= 0.5 && < 0.6, + errors >= 1.3.1 && < 1.4, filepath, hashable >= 1.1, heist >= 0.10 && < 0.11, @@ -121,24 +135,44 @@ Executable nesttest main-is: NestTest.hs build-depends: - MonadCatchIO-transformers >= 0.2 && < 0.4, - attoparsec >= 0.10 && < 0.11, - base >= 4 && < 5, - bytestring >= 0.9 && < 0.10, + Glob >= 0.5 && < 0.8, + HUnit >= 1.2 && < 2, + MonadCatchIO-transformers >= 0.2 && < 0.4, + QuickCheck >= 2.3.0.2, + attoparsec >= 0.10 && <0.11, + base >= 4 && < 5, + bytestring >= 0.9 && < 0.10, + cereal >= 0.3 && < 0.4, + clientsession >= 0.7 && < 0.8, + comonad >= 3.0 && < 3.1, + configurator >= 0.1 && < 0.3, containers >= 0.3, - data-lens >= 2.0.1 && < 2.11, - data-lens-template >= 2.1 && < 2.2, + data-lens >= 2.0.1 && < 2.11, + data-lens-template >= 2.1.1 && < 2.2, directory, - directory-tree >= 0.10 && < 0.11, + directory-tree >= 0.10 && < 0.11, + dlist >= 0.5 && < 0.6, + errors >= 1.3.1 && < 1.4, filepath, - heist >= 0.10 && < 0.11, + hashable >= 1.1, + heist >= 0.10 && < 0.11, + http-conduit >= 1.4 && < 1.5, + http-types >= 0.6 && < 0.7, mtl >= 2, + mwc-random >= 0.8, process == 1.*, - snap-core >= 0.9 && < 0.10, - snap-server >= 0.9 && < 0.10, - text >= 0.11 && < 0.12, + snap-core >= 0.9 && < 0.10, + snap-server >= 0.9 && < 0.10, + syb >= 0.1, + test-framework >= 0.6 && <0.7, + test-framework-hunit >= 0.2.7 && <0.3, + test-framework-quickcheck2 >= 0.2.12.1 && <0.3, + text >= 0.11 && < 0.12, + time >= 1.1, transformers >= 0.2, - utf8-string >= 0.3 && < 0.4, + unix >= 2.2.0.0 && < 2.6, + unordered-containers >= 0.1.4, + utf8-string >= 0.3 && < 0.4, template-haskell extensions: diff --git a/test/suite/Blackbox/App.hs b/test/suite/Blackbox/App.hs index c5924924..cc292319 100644 --- a/test/suite/Blackbox/App.hs +++ b/test/suite/Blackbox/App.hs @@ -21,14 +21,14 @@ import Snap.Util.FileServe import Snap.Snaplet import Snap.Snaplet.Heist import qualified Snap.Snaplet.HeistNoClass as HNC -import Text.Templating.Heist +import Heist.Interpreted import Blackbox.Common import Blackbox.BarSnaplet import Blackbox.FooSnaplet import Blackbox.EmbeddedSnaplet import Blackbox.Types -import Snap.Snaplet.Session hiding (lookup) +import Snap.Snaplet.Session import Snap.Snaplet.Session.Backends.CookieSession @@ -75,8 +75,8 @@ fooMod f = f { fooField = fooField f ++ "z" } app :: SnapletInit App App app = makeSnaplet "app" "Test application" Nothing $ do hs <- nestSnaplet "heist" heist $ heistInit "templates" - fs <- nestSnaplet "foo" foo fooInit - bs <- nestSnaplet "" bar $ nameSnaplet "baz" $ barInit foo + fs <- nestSnaplet "foo" foo $ fooInit hs + bs <- nestSnaplet "" bar $ nameSnaplet "baz" $ barInit hs foo sm <- nestSnaplet "session" session $ initCookieSessionManager "sitekey.txt" "_session" (Just (30 * 60)) ns <- embedSnaplet "embed" embedded embeddedInit diff --git a/test/suite/Blackbox/BarSnaplet.hs b/test/suite/Blackbox/BarSnaplet.hs index e86f3e38..0c04267b 100644 --- a/test/suite/Blackbox/BarSnaplet.hs +++ b/test/suite/Blackbox/BarSnaplet.hs @@ -17,7 +17,8 @@ import Data.Text (Text) import Snap.Snaplet import Snap.Snaplet.Heist import Snap.Core -import Text.Templating.Heist +import Heist +import Heist.Interpreted import Blackbox.Common import Blackbox.FooSnaplet @@ -33,11 +34,12 @@ barsplice :: [(Text, SnapletHeist b v Template)] barsplice = [("barsplice", liftHeist $ textSplice "contents of the bar splice")] barInit :: HasHeist b - => Lens b (Snaplet FooSnaplet) + => Snaplet (Heist b) + -> Lens b (Snaplet FooSnaplet) -> SnapletInit b (BarSnaplet b) -barInit l = makeSnaplet "barsnaplet" "An example snaplet called bar." Nothing $ do +barInit h l = makeSnaplet "barsnaplet" "An example snaplet called bar." Nothing $ do config <- getSnapletUserConfig - addTemplates "" + addTemplates h "" rootUrl <- getSnapletRootURL addRoutes [("barconfig", liftIO (lookup config "barSnapletField") >>= writeLBS . fromJust) ,("barrooturl", writeBS $ "url" `B.append` rootUrl) diff --git a/test/suite/Blackbox/Common.hs b/test/suite/Blackbox/Common.hs index 2b7d3e7f..0b093a9f 100644 --- a/test/suite/Blackbox/Common.hs +++ b/test/suite/Blackbox/Common.hs @@ -4,7 +4,7 @@ import qualified Data.Text as T import Snap.Core import Snap.Snaplet import Snap.Snaplet.Heist -import Text.Templating.Heist +import Heist.Interpreted genericConfigString :: (MonadSnaplet m, Monad (m b v)) => m b v T.Text genericConfigString = do @@ -18,6 +18,6 @@ genericConfigString = do handlerConfig :: Handler b v () handlerConfig = writeText =<< genericConfigString -shConfigSplice :: SnapletSplice b v +shConfigSplice :: SnapletISplice b v shConfigSplice = liftHeist . textSplice =<< genericConfigString diff --git a/test/suite/Blackbox/EmbeddedSnaplet.hs b/test/suite/Blackbox/EmbeddedSnaplet.hs index 30d302b6..97e36492 100644 --- a/test/suite/Blackbox/EmbeddedSnaplet.hs +++ b/test/suite/Blackbox/EmbeddedSnaplet.hs @@ -19,7 +19,8 @@ import System.FilePath.Posix import Snap.Snaplet import Snap.Snaplet.Heist -import Text.Templating.Heist +import Heist +import Heist.Interpreted -- If we universally quantify EmbeddedSnaplet to get rid of the type parameter -- mkLabels throws an error "Can't reify a GADT data constructor" @@ -40,7 +41,7 @@ embeddedInit = makeSnaplet "embedded" "embedded snaplet" Nothing $ do -- This is the implementation of addTemplates, but we do it here manually -- to test coverage for addTemplatesAt. snapletPath <- getSnapletFilePath - addTemplatesAt "onemoredir" (snapletPath "extra-templates") + addTemplatesAt hs "onemoredir" (snapletPath "extra-templates") embeddedLens <- getLens addRoutes [("aoeuhtns", withSplices diff --git a/test/suite/Blackbox/FooSnaplet.hs b/test/suite/Blackbox/FooSnaplet.hs index 9d5eb959..03e95715 100644 --- a/test/suite/Blackbox/FooSnaplet.hs +++ b/test/suite/Blackbox/FooSnaplet.hs @@ -11,17 +11,17 @@ import qualified Data.Text as T import Snap.Snaplet import Snap.Snaplet.Heist import Snap.Core -import Text.Templating.Heist +import Heist.Interpreted import Blackbox.Common data FooSnaplet = FooSnaplet { fooField :: String } -fooInit :: HasHeist b => SnapletInit b FooSnaplet -fooInit = makeSnaplet "foosnaplet" "A demonstration snaplet called foo." +fooInit :: HasHeist b => Snaplet (Heist b) -> SnapletInit b FooSnaplet +fooInit h = makeSnaplet "foosnaplet" "A demonstration snaplet called foo." (Just $ return "../foosnaplet") $ do config <- getSnapletUserConfig - addTemplates "" + addTemplates h "" addSplices [("foosplice", liftHeist $ textSplice "contents of the foo splice")] rootUrl <- getSnapletRootURL diff --git a/test/suite/Blackbox/Tests.hs b/test/suite/Blackbox/Tests.hs index 40693f1c..a15c5161 100644 --- a/test/suite/Blackbox/Tests.hs +++ b/test/suite/Blackbox/Tests.hs @@ -14,6 +14,7 @@ import Control.Monad.Trans import qualified Data.ByteString.Char8 as S import qualified Data.ByteString.Lazy.Char8 as L import Data.Text.Lazy (Text) +import qualified Data.Text.Lazy as T import qualified Data.Text.Lazy.Encoding as T import qualified Network.HTTP.Conduit as HTTP import Network.HTTP.Types (Status(..)) @@ -259,19 +260,19 @@ reloadTest = testCase "internal/reload-test" $ do testWithCwd' "admin/reload" $ \cwd' b -> do let cwd = S.pack cwd' let response = - L.fromChunks [ "Error reloading site!\n\nInitializer " + T.concat [ "Error reloading site!\n\nInitializer " , "threw an exception...\n" - , cwd + , T.pack cwd' , "/non-cabal-appdir/snaplets/heist" , "/templates/bad.tpl \"" - , cwd + , T.pack cwd' , "/non-cabal-appdir/snaplets/heist/templates" , "/bad.tpl\" (line 2, column 1):\nunexpected " , "end of input\nexpecting \"=\", \"/\" or " - , "\">\"\n\n\n...but before it died it generated " + , "\">\"\n\n...but before it died it generated " , "the following output:\nInitializing app @ /\n" , "Initializing heist @ /heist\n\n" ] - assertEqual "admin/reload" response b + assertEqual "admin/reload" response (T.decodeUtf8 b) remove badTplNew copyFile goodTplOrig goodTplNew diff --git a/test/suite/NestTest.hs b/test/suite/NestTest.hs index 97285a6d..2d27041e 100644 --- a/test/suite/NestTest.hs +++ b/test/suite/NestTest.hs @@ -21,7 +21,8 @@ import Snap.Util.FileServe import Snap.Snaplet import Snap.Snaplet.Heist -import Text.Templating.Heist +import Heist +import Heist.Interpreted -- If we universally quantify FooSnaplet to get rid of the type parameter -- mkLabels throws an error "Can't reify a GADT data constructor" @@ -38,7 +39,7 @@ instance HasHeist FooSnaplet where fooInit :: SnapletInit FooSnaplet FooSnaplet fooInit = makeSnaplet "foosnaplet" "foo snaplet" Nothing $ do hs <- nestSnaplet "heist" fooHeist $ heistInit "templates" - addTemplates "foo" + addTemplates hs "foo" rootUrl <- getSnapletRootURL fooLens <- getLens addRoutes [("fooRootUrl", writeBS rootUrl)