snap 0.11.0 → 0.11.1
raw patch · 11 files changed
+109/−50 lines, 11 filesdep −eitherdep ~errorsdep ~lensdep ~logictPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: either
Dependency ranges changed: errors, lens, logict
API changes (from Hackage documentation)
- Snap.Snaplet.Config: appConfigTyCon :: TyCon
+ Snap.Snaplet: loadAppConfig :: FileName -> FilePath -> IO Config
- Snap.Snaplet: snapletConfig :: Lens' (Snaplet s_aAOM) SnapletConfig
+ Snap.Snaplet: snapletConfig :: Lens' (Snaplet s_aB07) SnapletConfig
- Snap.Snaplet: snapletValue :: Lens (Snaplet s_aAOM) (Snaplet s_aAPO) s_aAOM s_aAPO
+ Snap.Snaplet: snapletValue :: Lens (Snaplet s_aB07) (Snaplet s_aB19) s_aB07 s_aB19
- Snap.Snaplet: type SnapletLens s a = SimpleLoupe s (Snaplet a)
+ Snap.Snaplet: type SnapletLens s a = ALens' s (Snaplet a)
Files
- project_template/default/foo.cabal +3/−3
- project_template/tutorial/foo.cabal +2/−2
- snap.cabal +4/−5
- src/Snap/Snaplet.hs +1/−0
- src/Snap/Snaplet/Config.hs +1/−11
- src/Snap/Snaplet/Heist/Compiled.hs +8/−5
- src/Snap/Snaplet/Heist/Interpreted.hs +8/−5
- src/Snap/Snaplet/Internal/Initializer.hs +55/−2
- src/Snap/Snaplet/Internal/LensT.hs +6/−7
- src/Snap/Snaplet/Internal/Lensed.hs +8/−9
- src/Snap/Snaplet/Internal/Types.hs +13/−1
project_template/default/foo.cabal view
@@ -21,11 +21,11 @@ Build-depends: base >= 4 && < 5, bytestring >= 0.9.1 && < 0.11,- heist >= 0.10 && < 0.11,- lens >= 3.7.0.1 && < 3.8,+ heist >= 0.11 && < 0.12,+ lens >= 3.7.0.1 && < 3.9, MonadCatchIO-transformers >= 0.2.1 && < 0.4, mtl >= 2 && < 3,- snap >= 0.10 && < 0.11,+ snap >= 0.11 && < 0.12, snap-core >= 0.9 && < 0.11, snap-server >= 0.9 && < 0.11, snap-loader-static >= 0.9 && < 0.10,
project_template/tutorial/foo.cabal view
@@ -17,10 +17,10 @@ Build-depends: base >= 4 && < 5, bytestring >= 0.9.1 && < 0.11,- lens >= 3.7.0.1 && < 3.8,+ lens >= 3.7.0.1 && < 3.9, MonadCatchIO-transformers >= 0.2.1 && < 0.4, mtl >= 2 && < 3,- snap >= 0.10 && < 0.11,+ snap >= 0.11 && < 0.12, snap-core >= 0.9 && < 0.11, snap-server >= 0.9 && < 0.11
snap.cabal view
@@ -1,5 +1,5 @@ name: snap-version: 0.11.0+version: 0.11.1 synopsis: Top-level package for the Snap Web Framework description: This is the top-level package for the official Snap Framework libraries.@@ -150,13 +150,12 @@ directory >= 1.0 && < 1.3, directory-tree >= 0.10 && < 0.12, dlist >= 0.5 && < 0.6,- either >= 3.1 && < 3.2,- errors >= 1.3 && < 1.4,+ errors >= 1.4 && < 1.5, filepath >= 1.1 && < 1.4, hashable >= 1.1 && < 1.3, heist >= 0.11 && < 0.12,- lens >= 3.7.0.1 && < 3.9,- logict >= 0.4.2 && < 0.6,+ lens >= 3.8.5 && < 3.9,+ logict >= 0.4.2 && < 0.7, mtl > 2.0 && < 2.2, mwc-random >= 0.8 && < 0.13, pwstore-fast >= 2.2 && < 2.4,
src/Snap/Snaplet.hs view
@@ -106,6 +106,7 @@ , runSnaplet , combineConfig , serveSnaplet+ , loadAppConfig -- * Snaplet Lenses , SnapletLens
src/Snap/Snaplet/Config.hs view
@@ -15,17 +15,7 @@ -- | AppConfig contains the config options for command line arguments in -- snaplet-based apps. newtype AppConfig = AppConfig { appEnvironment :: Maybe String }------------------------------------------------------------------------------------ | The Typeable instance is here so Snap can be dynamically executed with--- Hint.-appConfigTyCon :: TyCon-appConfigTyCon = mkTyCon "Snap.Snaplet.Config.AppConfig"-{-# NOINLINE appConfigTyCon #-}--instance Typeable AppConfig where- typeOf _ = mkTyConApp appConfigTyCon []+ deriving (Typeable) ------------------------------------------------------------------------------
src/Snap/Snaplet/Heist/Compiled.hs view
@@ -1,8 +1,11 @@-{- | A module exporting only functions for using compiled templates. If you- - import the main Snap.Snaplet.Heist module, it's easy to accidentally use- - the interpreted render function even when you're using compiled Heist.- - Importing only this module will make it harder to make mistakes like that.- -}+{-|++A module exporting only functions for using compiled templates. If you+import the main Snap.Snaplet.Heist module, it's easy to accidentally use+the interpreted render function even when you're using compiled Heist.+Importing only this module will make it harder to make mistakes like that.++-} module Snap.Snaplet.Heist.Compiled ( H.Heist , H.HasHeist(..)
src/Snap/Snaplet/Heist/Interpreted.hs view
@@ -1,8 +1,11 @@-{- | A module exporting only functions for using interpreted templates. If- - you import the main Snap.Snaplet.Heist module, it's easy to accidentally- - use the compiled render function even when you're using interpreted Heist.- - Importing only this module will make it harder to make mistakes like that.- -}+{-|++A module exporting only functions for using interpreted templates. If+you import the main Snap.Snaplet.Heist module, it's easy to accidentally+use the compiled render function even when you're using interpreted Heist.+Importing only this module will make it harder to make mistakes like that.++-} module Snap.Snaplet.Heist.Interpreted ( Heist , HasHeist(..)
src/Snap/Snaplet/Internal/Initializer.hs view
@@ -1,5 +1,6 @@-{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TupleSections #-} module Snap.Snaplet.Internal.Initializer ( addPostInitHook@@ -18,6 +19,7 @@ , runSnaplet , combineConfig , serveSnaplet+ , loadAppConfig , printInfo ) where @@ -34,6 +36,7 @@ import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Configurator+import qualified Data.Configurator.Types as C import Data.IORef import Data.Maybe import Data.Text (Text)@@ -121,7 +124,7 @@ ------------------------------------------------------------------------------ -- | Helper function for transforming hooks.-upHook' :: Monad m => SimpleLoupe b a -> (a -> m a) -> b -> m b+upHook' :: Monad m => ALens' b a -> (a -> m a) -> b -> m b upHook' l h b = do v <- h (b ^# l) return $ storing l v b@@ -568,4 +571,54 @@ :: IO (Either SomeException ()) doCleanup ++------------------------------------------------------------------------------+-- | Allows you to get all of your app's config data in the IO monad without+-- the web server infrastructure.+loadAppConfig :: FileName+ -- ^ The name of the config file to look for. In snap+ -- applications, this is something based on the+ -- environment...i.e. @devel.cfg@.+ -> FilePath+ -- ^ Path to the root directory of your project.+ -> IO C.Config+loadAppConfig cfg root = do+ tree <- buildL root+ let groups = loadAppConfig' cfg "" $ dirTree tree+ loadGroups groups+++------------------------------------------------------------------------------+-- | Recursive worker for loadAppConfig.+loadAppConfig' :: FileName -> Text -> DirTree a -> [(Text, Worth a)]+loadAppConfig' cfg _prefix d@(Dir _ c) =+ (map ((_prefix,) . Required) $ getCfg cfg d) +++ concatMap (\a -> loadAppConfig' cfg (nextPrefix $ name a) a) snaplets+ where+ nextPrefix p = T.concat [_prefix, T.pack p, "."]+ snapletsDirs = filter isSnapletsDir c+ snaplets = concatMap (filter isDir . contents) snapletsDirs+loadAppConfig' _ _ _ = []+++isSnapletsDir :: DirTree t -> Bool+isSnapletsDir (Dir "snaplets" _) = True+isSnapletsDir _ = False+++isDir :: DirTree t -> Bool+isDir (Dir _ _) = True+isDir _ = False+++isCfg :: FileName -> DirTree t -> Bool+isCfg cfg (File n _) = cfg == n+isCfg _ _ = False+++getCfg :: FileName -> DirTree b -> [b]+getCfg cfg (Dir _ c) = map file $ filter (isCfg cfg) c+getCfg _ _ = []++
src/Snap/Snaplet/Internal/LensT.hs view
@@ -7,7 +7,6 @@ import Control.Applicative import Control.Category-import Control.Lens (cloneLens) import Control.Lens.Loupe import Control.Monad.CatchIO import Control.Monad.Reader@@ -18,7 +17,7 @@ import Snap.Snaplet.Internal.RST -newtype LensT b v s m a = LensT (RST (SimpleLoupe b v) s m a)+newtype LensT b v s m a = LensT (RST (ALens' b v) s m a) deriving ( Monad , MonadTrans , Functor@@ -27,7 +26,7 @@ , MonadPlus , MonadCatchIO , Alternative- , MonadReader (SimpleLoupe b v)+ , MonadReader (ALens' b v) , MonadSnap ) @@ -68,14 +67,14 @@ -------------------------------------------------------------------------------runLensT :: Monad m => LensT b v s m a -> SimpleLoupe b v -> s -> m (a, s)+runLensT :: Monad m => LensT b v s m a -> ALens' b v -> s -> m (a, s) runLensT (LensT m) l = runRST m l {-# INLINE runLensT #-} ------------------------------------------------------------------------------ withLensT :: Monad m- => (SimpleLoupe b' v' -> SimpleLoupe b v)+ => (ALens' b' v' -> ALens' b v) -> LensT b v s m a -> LensT b' v' s m a withLensT f (LensT m) = LensT $ withRST f m@@ -84,7 +83,7 @@ ------------------------------------------------------------------------------ withTop :: Monad m- => SimpleLoupe b v'+ => ALens' b v' -> LensT b v' s m a -> LensT b v s m a withTop subLens = withLensT (const subLens)@@ -92,6 +91,6 @@ -------------------------------------------------------------------------------with :: Monad m => SimpleLoupe v v' -> LensT b v' s m a -> LensT b v s m a+with :: Monad m => ALens' v v' -> LensT b v' s m a -> LensT b v s m a with subLens = withLensT (\l -> cloneLens l . subLens)
src/Snap/Snaplet/Internal/Lensed.hs view
@@ -5,7 +5,6 @@ module Snap.Snaplet.Internal.Lensed where import Control.Applicative-import Control.Lens (cloneLens) import Control.Lens.Loupe import Control.Monad import Control.Monad.Reader.Class@@ -19,7 +18,7 @@ ------------------------------------------------------------------------------ newtype Lensed b v m a = Lensed- { unlensed :: SimpleLoupe b v -> v -> b -> m (a, v, b) }+ { unlensed :: ALens' b v -> v -> b -> m (a, v, b) } ------------------------------------------------------------------------------@@ -50,12 +49,12 @@ put v' = Lensed $ \_ _ s -> return ((), v', s) -instance Monad m => MonadReader (SimpleLoupe b v) (Lensed b v m) where+instance Monad m => MonadReader (ALens' b v) (Lensed b v m) where ask = Lensed $ \l v s -> return (l, v, s) local = lensedLocal -------------------------------------------------------------------------------lensedLocal :: Monad m => (SimpleLoupe b v -> SimpleLoupe b v') -> Lensed b v' m a -> Lensed b v m a+lensedLocal :: Monad m => (ALens' b v -> ALens' b v') -> Lensed b v' m a -> Lensed b v m a lensedLocal f g = do l <- ask withTop (f l) g@@ -107,7 +106,7 @@ -------------------------------------------------------------------------------lensedAsState :: Monad m => Lensed b v m a -> SimpleLoupe b v -> StateT b m a+lensedAsState :: Monad m => Lensed b v m a -> ALens' b v -> StateT b m a lensedAsState (Lensed f) l = StateT $ \s -> do (a, v', s') <- f l (s ^# l) s return (a, storing l v' s')@@ -119,19 +118,19 @@ -------------------------------------------------------------------------------withTop :: Monad m => SimpleLoupe b v' -> Lensed b v' m a -> Lensed b v m a+withTop :: Monad m => ALens' b v' -> Lensed b v' m a -> Lensed b v m a withTop l m = globally $ lensedAsState m l -------------------------------------------------------------------------------with :: Monad m => SimpleLoupe v v' -> Lensed b v' m a -> Lensed b v m a+with :: Monad m => ALens' v v' -> Lensed b v' m a -> Lensed b v m a with l g = do l' <- ask withTop (cloneLens l' . l) g -------------------------------------------------------------------------------embed :: Monad m => SimpleLoupe v v' -> Lensed v v' m a -> Lensed b v m a+embed :: Monad m => ALens' v v' -> Lensed v v' m a -> Lensed b v m a embed l m = locally $ lensedAsState m l @@ -144,7 +143,7 @@ ------------------------------------------------------------------------------ runLensed :: Monad m => Lensed t1 b m t- -> SimpleLoupe t1 b+ -> ALens' t1 b -> t1 -> m (t, t1) runLensed (Lensed f) l s = do
src/Snap/Snaplet/Internal/Types.hs view
@@ -112,7 +112,7 @@ snapletValue :: SimpleLens (Snaplet a) a -} -type SnapletLens s a = SimpleLoupe s (Snaplet a)+type SnapletLens s a = ALens' s (Snaplet a) ------------------------------------------------------------------------------ -- | Transforms a lens of the type you get from makeLenses to an similar lens@@ -275,6 +275,18 @@ instance MonadState v (Handler b v) where get = getsSnapletState _snapletValue put v = modifySnapletState (set snapletValue v)+++------------------------------------------------------------------------------+-- | The MonadState instance gives you access to the current snaplet's state.+instance MonadReader v (Handler b v) where+ ask = getsSnapletState _snapletValue+ local f m = do+ cur <- ask+ put (f cur)+ res <- m+ put cur+ return res instance MonadSnaplet Handler where