Merge remote-tracking branch 'origin/master' into persistent2-simpler-dispatch
This commit is contained in:
commit
827b1d4bd2
@ -2,17 +2,31 @@
|
|||||||
module HsFile (mkHsFile) where
|
module HsFile (mkHsFile) where
|
||||||
import Text.ProjectTemplate (createTemplate)
|
import Text.ProjectTemplate (createTemplate)
|
||||||
import Data.Conduit
|
import Data.Conduit
|
||||||
( ($$), (=$), runResourceT, ResourceT, ConduitM, awaitForever, yield )
|
( ($$), (=$), runResourceT, ResourceT, ConduitM, awaitForever, yield, Source )
|
||||||
import qualified Data.Conduit.List as CL
|
import qualified Data.Conduit.List as CL
|
||||||
import Data.Conduit.Filesystem (traverse, sourceFile)
|
|
||||||
import Prelude hiding (FilePath)
|
import Prelude hiding (FilePath)
|
||||||
import Filesystem.Path ( FilePath )
|
import Filesystem.Path ( FilePath )
|
||||||
import Filesystem.Path.CurrentOS ( encodeString )
|
import Filesystem.Path.CurrentOS ( encodeString )
|
||||||
|
import qualified Filesystem as F
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import Control.Monad.IO.Class (liftIO)
|
import Control.Monad.IO.Class (liftIO)
|
||||||
|
|
||||||
|
traverse :: FilePath -> Source (ResourceT IO) FilePath
|
||||||
|
traverse dir = do
|
||||||
|
liftIO (F.listDirectory dir) >>= mapM_ go
|
||||||
|
where
|
||||||
|
go fp = do
|
||||||
|
isFile' <- liftIO $ F.isFile fp
|
||||||
|
if isFile'
|
||||||
|
then yield fp
|
||||||
|
else do
|
||||||
|
isDir <- liftIO $ F.isDirectory fp
|
||||||
|
if isDir
|
||||||
|
then traverse fp
|
||||||
|
else return ()
|
||||||
|
|
||||||
mkHsFile :: IO ()
|
mkHsFile :: IO ()
|
||||||
mkHsFile = runResourceT $ traverse False "."
|
mkHsFile = runResourceT $ traverse "."
|
||||||
$$ readIt
|
$$ readIt
|
||||||
=$ createTemplate
|
=$ createTemplate
|
||||||
=$ awaitForever (liftIO . BS.putStr)
|
=$ awaitForever (liftIO . BS.putStr)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-bin
|
name: yesod-bin
|
||||||
version: 1.2.7.2
|
version: 1.2.7.3
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
@ -90,7 +90,6 @@ executable yesod
|
|||||||
, warp >= 1.3.7.5
|
, warp >= 1.3.7.5
|
||||||
, wai >= 1.4
|
, wai >= 1.4
|
||||||
, data-default-class
|
, data-default-class
|
||||||
, filesystem-conduit >= 1.0 && < 2.0
|
|
||||||
|
|
||||||
ghc-options: -Wall -threaded
|
ghc-options: -Wall -threaded
|
||||||
main-is: main.hs
|
main-is: main.hs
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
{-# LANGUAGE TupleSections #-}
|
{-# LANGUAGE TupleSections #-}
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
{-# LANGUAGE RankNTypes #-}
|
{-# LANGUAGE RankNTypes #-}
|
||||||
|
{-# LANGUAGE DeriveDataTypeable #-}
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
--
|
--
|
||||||
-- Module : Yesod.Handler
|
-- Module : Yesod.Handler
|
||||||
@ -74,6 +75,7 @@ module Yesod.Core.Handler
|
|||||||
, redirect
|
, redirect
|
||||||
, redirectWith
|
, redirectWith
|
||||||
, redirectToPost
|
, redirectToPost
|
||||||
|
, Fragment(..)
|
||||||
-- ** Errors
|
-- ** Errors
|
||||||
, notFound
|
, notFound
|
||||||
, badMethod
|
, badMethod
|
||||||
@ -188,6 +190,7 @@ import Data.Dynamic (fromDynamic, toDyn)
|
|||||||
import qualified Data.IORef.Lifted as I
|
import qualified Data.IORef.Lifted as I
|
||||||
import Data.Maybe (listToMaybe, mapMaybe)
|
import Data.Maybe (listToMaybe, mapMaybe)
|
||||||
import Data.Typeable (Typeable, typeOf)
|
import Data.Typeable (Typeable, typeOf)
|
||||||
|
import Web.PathPieces (PathPiece(..))
|
||||||
import Yesod.Core.Class.Handler
|
import Yesod.Core.Class.Handler
|
||||||
import Yesod.Core.Types
|
import Yesod.Core.Types
|
||||||
import Yesod.Routes.Class (Route)
|
import Yesod.Routes.Class (Route)
|
||||||
@ -758,6 +761,18 @@ instance (key ~ Text, val ~ Text) => RedirectUrl master (Route master, [(key, va
|
|||||||
instance (key ~ Text, val ~ Text) => RedirectUrl master (Route master, Map.Map key val) where
|
instance (key ~ Text, val ~ Text) => RedirectUrl master (Route master, Map.Map key val) where
|
||||||
toTextUrl (url, params) = toTextUrl (url, Map.toList params)
|
toTextUrl (url, params) = toTextUrl (url, Map.toList params)
|
||||||
|
|
||||||
|
-- | Add a fragment identifier to a route to be used when
|
||||||
|
-- redirecting. For example:
|
||||||
|
--
|
||||||
|
-- > redirect (NewsfeedR :#: storyId)
|
||||||
|
--
|
||||||
|
-- Since 1.2.9.
|
||||||
|
data Fragment a b = a :#: b deriving (Show, Typeable)
|
||||||
|
|
||||||
|
instance (RedirectUrl master a, PathPiece b) => RedirectUrl master (Fragment a b) where
|
||||||
|
toTextUrl (a :#: b) = (\ua -> T.concat [ua, "#", toPathPiece b]) <$> toTextUrl a
|
||||||
|
|
||||||
|
|
||||||
-- | Lookup for session data.
|
-- | Lookup for session data.
|
||||||
lookupSession :: MonadHandler m => Text -> m (Maybe Text)
|
lookupSession :: MonadHandler m => Text -> m (Maybe Text)
|
||||||
lookupSession = (liftM . fmap) (decodeUtf8With lenientDecode) . lookupSessionBS
|
lookupSession = (liftM . fmap) (decodeUtf8With lenientDecode) . lookupSessionBS
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-core
|
name: yesod-core
|
||||||
version: 1.2.8
|
version: 1.2.9
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
|
|||||||
@ -23,7 +23,8 @@ mkYesod "HelloForms" [parseRoutes|
|
|||||||
/file FileR GET POST
|
/file FileR GET POST
|
||||||
|]
|
|]
|
||||||
|
|
||||||
myForm = fixType $ runFormGet $ renderDivs $ pure (,,,,,,,,,)
|
myForm = fixType $ runFormGet $ renderDivs $ pure (,,,,,,,,,,)
|
||||||
|
<*> pure "pure works!"
|
||||||
<*> areq boolField "Bool field" Nothing
|
<*> areq boolField "Bool field" Nothing
|
||||||
<*> aopt boolField "Opt bool field" Nothing
|
<*> aopt boolField "Opt bool field" Nothing
|
||||||
<*> areq textField "Text field" Nothing
|
<*> areq textField "Text field" Nothing
|
||||||
|
|||||||
@ -28,8 +28,7 @@ import Control.Monad.Trans.Reader (ReaderT, runReaderT)
|
|||||||
import Yesod.Core
|
import Yesod.Core
|
||||||
import Data.Conduit
|
import Data.Conduit
|
||||||
import Blaze.ByteString.Builder (Builder)
|
import Blaze.ByteString.Builder (Builder)
|
||||||
import Data.IORef.Lifted
|
import Data.Pool
|
||||||
import Data.Conduit.Pool
|
|
||||||
import Control.Monad.Trans.Resource
|
import Control.Monad.Trans.Resource
|
||||||
import Control.Exception (throwIO)
|
import Control.Exception (throwIO)
|
||||||
import Yesod.Core.Types (HandlerContents (HCError))
|
import Yesod.Core.Types (HandlerContents (HCError))
|
||||||
@ -103,24 +102,23 @@ defaultGetDBRunner :: YesodPersistBackend site ~ SqlPersistT
|
|||||||
=> (site -> Pool SQL.Connection)
|
=> (site -> Pool SQL.Connection)
|
||||||
-> HandlerT site IO (DBRunner site, HandlerT site IO ())
|
-> HandlerT site IO (DBRunner site, HandlerT site IO ())
|
||||||
defaultGetDBRunner getPool = do
|
defaultGetDBRunner getPool = do
|
||||||
ididSucceed <- newIORef False
|
|
||||||
|
|
||||||
pool <- fmap getPool getYesod
|
pool <- fmap getPool getYesod
|
||||||
managedConn <- takeResource pool
|
let withPrep conn f = f conn (SQL.connPrepare conn)
|
||||||
let conn = mrValue managedConn
|
(relKey, (conn, local)) <- allocate
|
||||||
|
(do
|
||||||
|
(conn, local) <- takeResource pool
|
||||||
|
withPrep conn SQL.connBegin
|
||||||
|
return (conn, local)
|
||||||
|
)
|
||||||
|
(\(conn, local) -> do
|
||||||
|
withPrep conn SQL.connRollback
|
||||||
|
destroyResource pool local conn)
|
||||||
|
|
||||||
let withPrep f = f conn (SQL.connPrepare conn)
|
let cleanup = liftIO $ do
|
||||||
(finishTransaction, ()) <- allocate (withPrep SQL.connBegin) $ \() -> do
|
withPrep conn SQL.connCommit
|
||||||
didSucceed <- readIORef ididSucceed
|
putResource local conn
|
||||||
withPrep $ if didSucceed
|
_ <- unprotect relKey
|
||||||
then SQL.connCommit
|
return ()
|
||||||
else SQL.connRollback
|
|
||||||
|
|
||||||
let cleanup = do
|
|
||||||
writeIORef ididSucceed True
|
|
||||||
release finishTransaction
|
|
||||||
mrReuse managedConn True
|
|
||||||
mrRelease managedConn
|
|
||||||
|
|
||||||
return (DBRunner $ \x -> runReaderT (unSqlPersistT x) conn, cleanup)
|
return (DBRunner $ \x -> runReaderT (unSqlPersistT x) conn, cleanup)
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-persistent
|
name: yesod-persistent
|
||||||
version: 1.2.2.1
|
version: 1.2.2.2
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
@ -20,9 +20,8 @@ library
|
|||||||
, transformers >= 0.2.2 && < 0.4
|
, transformers >= 0.2.2 && < 0.4
|
||||||
, blaze-builder
|
, blaze-builder
|
||||||
, conduit
|
, conduit
|
||||||
, lifted-base
|
, resourcet >= 0.4.5
|
||||||
, pool-conduit
|
, resource-pool
|
||||||
, resourcet
|
|
||||||
exposed-modules: Yesod.Persist
|
exposed-modules: Yesod.Persist
|
||||||
Yesod.Persist.Core
|
Yesod.Persist.Core
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-test
|
name: yesod-test
|
||||||
version: 1.2.1
|
version: 1.2.1.1
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Nubis <nubis@woobiz.com.ar>
|
author: Nubis <nubis@woobiz.com.ar>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user