From 972efd0ca4bbb0fa891bef6738298bd3fe4e5441 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 15 Jul 2014 19:06:27 +0300 Subject: [PATCH] Scaffold update --- yesod-bin/hsfiles/mongo.hsfiles | 53 ++++++++++++++++--------- yesod-bin/hsfiles/mysql.hsfiles | 54 +++++++++++++++++--------- yesod-bin/hsfiles/postgres-fay.hsfiles | 54 +++++++++++++++++--------- yesod-bin/hsfiles/postgres.hsfiles | 54 +++++++++++++++++--------- yesod-bin/hsfiles/simple.hsfiles | 53 ++++++++++++++++--------- yesod-bin/hsfiles/sqlite.hsfiles | 54 +++++++++++++++++--------- 6 files changed, 208 insertions(+), 114 deletions(-) diff --git a/yesod-bin/hsfiles/mongo.hsfiles b/yesod-bin/hsfiles/mongo.hsfiles index a802792a..ed261fe2 100644 --- a/yesod-bin/hsfiles/mongo.hsfiles +++ b/yesod-bin/hsfiles/mongo.hsfiles @@ -211,6 +211,13 @@ instance Yesod App where -- The page to be redirected to when authentication is required. authRoute _ = Just $ AuthR LoginR + -- Routes not requiring authenitcation. + isAuthorized (AuthR _) _ = return Authorized + isAuthorized FaviconR _ = return Authorized + isAuthorized RobotsR _ = return Authorized + -- Default to Authorized for now. + isAuthorized _ _ = return Authorized + -- This function creates static content files in the static folder -- and names them based on a hash of their content. This allows -- expiration dates to be set far in the future without worry of @@ -609,17 +616,21 @@ combineScripts = combineScripts' development combineSettings -- -- cabal repl --ghc-options="-O0 -fobject-code" -- +-- run with: +-- +-- :l DevelMain +-- DevelMain.update +-- -- You will need to add these packages to your .cabal file --- * foreign-store (very light-weight) +-- * foreign-store >= 0.1 (very light-weight) -- * warp (you already depend on this, it just isn't in your .cabal file) -- -- If you don't use cabal repl, you will need --- to run the following in GHCi or to add it to --- your .ghci file. +-- to add settings to your .ghci file. -- -- :set -DDEVELOPMENT -- --- There is more information about this approach, +-- There is more information about using ghci -- on the wiki: https://github.com/yesodweb/yesod/wiki/ghci module DevelMain where @@ -633,27 +644,31 @@ import Foreign.Store import Network.Wai.Handler.Warp -- | Start or restart the server. +-- A Store holds onto some data across ghci reloads update :: IO () update = do - mtidStore <- lookupStore tid_1 + mtidStore <- lookupStore tidStoreNum case mtidStore of + -- no server running Nothing -> do - done <- newEmptyMVar - _done_0 <- newStore done + done <- storeAction doneStore newEmptyMVar tid <- start done - tidRef <- newIORef tid - _tid_1 <- newStore tidRef + _ <- storeAction (Store tidStoreNum) (newIORef tid) return () - Just tidStore -> do - tidRef <- readStore tidStore - tid <- readIORef tidRef - done <- readStore (Store done_0) - killThread tid - takeMVar done - newTid <- start done - writeIORef tidRef newTid - where tid_1 = 1 - done_0 = 0 + -- server is already running + Just tidStore -> + -- shut the server down with killThread and wait for the done signal + modifyStoredIORef tidStore $ \tid -> do + killThread tid + withStore doneStore takeMVar >> readStore doneStore >>= start + where + doneStore = Store 0 + tidStoreNum = 1 + + modifyStoredIORef :: Store (IORef a) -> (a -> IO a) -> IO () + modifyStoredIORef store f = withStore store $ \ref -> do + v <- readIORef ref + f v >>= writeIORef ref -- | Start the server in a separate thread. start :: MVar () -- ^ Written to when the thread is killed. diff --git a/yesod-bin/hsfiles/mysql.hsfiles b/yesod-bin/hsfiles/mysql.hsfiles index 30eafe13..9d6b7b9a 100644 --- a/yesod-bin/hsfiles/mysql.hsfiles +++ b/yesod-bin/hsfiles/mysql.hsfiles @@ -218,6 +218,13 @@ instance Yesod App where -- The page to be redirected to when authentication is required. authRoute _ = Just $ AuthR LoginR + -- Routes not requiring authenitcation. + isAuthorized (AuthR _) _ = return Authorized + isAuthorized FaviconR _ = return Authorized + isAuthorized RobotsR _ = return Authorized + -- Default to Authorized for now. + isAuthorized _ _ = return Authorized + -- This function creates static content files in the static folder -- and names them based on a hash of their content. This allows -- expiration dates to be set far in the future without worry of @@ -365,6 +372,7 @@ import Yesod import Data.Text (Text) import Database.Persist.Quasi import Data.Typeable (Typeable) +import Prelude -- You can define all of your database entities in the entities file. -- You can find more information on persistent and how to declare entities @@ -612,17 +620,21 @@ combineScripts = combineScripts' development combineSettings -- -- cabal repl --ghc-options="-O0 -fobject-code" -- +-- run with: +-- +-- :l DevelMain +-- DevelMain.update +-- -- You will need to add these packages to your .cabal file --- * foreign-store (very light-weight) +-- * foreign-store >= 0.1 (very light-weight) -- * warp (you already depend on this, it just isn't in your .cabal file) -- -- If you don't use cabal repl, you will need --- to run the following in GHCi or to add it to --- your .ghci file. +-- to add settings to your .ghci file. -- -- :set -DDEVELOPMENT -- --- There is more information about this approach, +-- There is more information about using ghci -- on the wiki: https://github.com/yesodweb/yesod/wiki/ghci module DevelMain where @@ -636,27 +648,31 @@ import Foreign.Store import Network.Wai.Handler.Warp -- | Start or restart the server. +-- A Store holds onto some data across ghci reloads update :: IO () update = do - mtidStore <- lookupStore tid_1 + mtidStore <- lookupStore tidStoreNum case mtidStore of + -- no server running Nothing -> do - done <- newEmptyMVar - _done_0 <- newStore done + done <- storeAction doneStore newEmptyMVar tid <- start done - tidRef <- newIORef tid - _tid_1 <- newStore tidRef + _ <- storeAction (Store tidStoreNum) (newIORef tid) return () - Just tidStore -> do - tidRef <- readStore tidStore - tid <- readIORef tidRef - done <- readStore (Store done_0) - killThread tid - takeMVar done - newTid <- start done - writeIORef tidRef newTid - where tid_1 = 1 - done_0 = 0 + -- server is already running + Just tidStore -> + -- shut the server down with killThread and wait for the done signal + modifyStoredIORef tidStore $ \tid -> do + killThread tid + withStore doneStore takeMVar >> readStore doneStore >>= start + where + doneStore = Store 0 + tidStoreNum = 1 + + modifyStoredIORef :: Store (IORef a) -> (a -> IO a) -> IO () + modifyStoredIORef store f = withStore store $ \ref -> do + v <- readIORef ref + f v >>= writeIORef ref -- | Start the server in a separate thread. start :: MVar () -- ^ Written to when the thread is killed. diff --git a/yesod-bin/hsfiles/postgres-fay.hsfiles b/yesod-bin/hsfiles/postgres-fay.hsfiles index 287a4212..64387842 100644 --- a/yesod-bin/hsfiles/postgres-fay.hsfiles +++ b/yesod-bin/hsfiles/postgres-fay.hsfiles @@ -222,6 +222,13 @@ instance Yesod App where -- The page to be redirected to when authentication is required. authRoute _ = Just $ AuthR LoginR + -- Routes not requiring authenitcation. + isAuthorized (AuthR _) _ = return Authorized + isAuthorized FaviconR _ = return Authorized + isAuthorized RobotsR _ = return Authorized + -- Default to Authorized for now. + isAuthorized _ _ = return Authorized + -- This function creates static content files in the static folder -- and names them based on a hash of their content. This allows -- expiration dates to be set far in the future without worry of @@ -397,6 +404,7 @@ import Yesod import Data.Text (Text) import Database.Persist.Quasi import Data.Typeable (Typeable) +import Prelude -- You can define all of your database entities in the entities file. -- You can find more information on persistent and how to declare entities @@ -661,17 +669,21 @@ combineScripts = combineScripts' development combineSettings -- -- cabal repl --ghc-options="-O0 -fobject-code" -- +-- run with: +-- +-- :l DevelMain +-- DevelMain.update +-- -- You will need to add these packages to your .cabal file --- * foreign-store (very light-weight) +-- * foreign-store >= 0.1 (very light-weight) -- * warp (you already depend on this, it just isn't in your .cabal file) -- -- If you don't use cabal repl, you will need --- to run the following in GHCi or to add it to --- your .ghci file. +-- to add settings to your .ghci file. -- -- :set -DDEVELOPMENT -- --- There is more information about this approach, +-- There is more information about using ghci -- on the wiki: https://github.com/yesodweb/yesod/wiki/ghci module DevelMain where @@ -685,27 +697,31 @@ import Foreign.Store import Network.Wai.Handler.Warp -- | Start or restart the server. +-- A Store holds onto some data across ghci reloads update :: IO () update = do - mtidStore <- lookupStore tid_1 + mtidStore <- lookupStore tidStoreNum case mtidStore of + -- no server running Nothing -> do - done <- newEmptyMVar - _done_0 <- newStore done + done <- storeAction doneStore newEmptyMVar tid <- start done - tidRef <- newIORef tid - _tid_1 <- newStore tidRef + _ <- storeAction (Store tidStoreNum) (newIORef tid) return () - Just tidStore -> do - tidRef <- readStore tidStore - tid <- readIORef tidRef - done <- readStore (Store done_0) - killThread tid - takeMVar done - newTid <- start done - writeIORef tidRef newTid - where tid_1 = 1 - done_0 = 0 + -- server is already running + Just tidStore -> + -- shut the server down with killThread and wait for the done signal + modifyStoredIORef tidStore $ \tid -> do + killThread tid + withStore doneStore takeMVar >> readStore doneStore >>= start + where + doneStore = Store 0 + tidStoreNum = 1 + + modifyStoredIORef :: Store (IORef a) -> (a -> IO a) -> IO () + modifyStoredIORef store f = withStore store $ \ref -> do + v <- readIORef ref + f v >>= writeIORef ref -- | Start the server in a separate thread. start :: MVar () -- ^ Written to when the thread is killed. diff --git a/yesod-bin/hsfiles/postgres.hsfiles b/yesod-bin/hsfiles/postgres.hsfiles index e6482c6f..5ea0d5fb 100644 --- a/yesod-bin/hsfiles/postgres.hsfiles +++ b/yesod-bin/hsfiles/postgres.hsfiles @@ -218,6 +218,13 @@ instance Yesod App where -- The page to be redirected to when authentication is required. authRoute _ = Just $ AuthR LoginR + -- Routes not requiring authenitcation. + isAuthorized (AuthR _) _ = return Authorized + isAuthorized FaviconR _ = return Authorized + isAuthorized RobotsR _ = return Authorized + -- Default to Authorized for now. + isAuthorized _ _ = return Authorized + -- This function creates static content files in the static folder -- and names them based on a hash of their content. This allows -- expiration dates to be set far in the future without worry of @@ -365,6 +372,7 @@ import Yesod import Data.Text (Text) import Database.Persist.Quasi import Data.Typeable (Typeable) +import Prelude -- You can define all of your database entities in the entities file. -- You can find more information on persistent and how to declare entities @@ -612,17 +620,21 @@ combineScripts = combineScripts' development combineSettings -- -- cabal repl --ghc-options="-O0 -fobject-code" -- +-- run with: +-- +-- :l DevelMain +-- DevelMain.update +-- -- You will need to add these packages to your .cabal file --- * foreign-store (very light-weight) +-- * foreign-store >= 0.1 (very light-weight) -- * warp (you already depend on this, it just isn't in your .cabal file) -- -- If you don't use cabal repl, you will need --- to run the following in GHCi or to add it to --- your .ghci file. +-- to add settings to your .ghci file. -- -- :set -DDEVELOPMENT -- --- There is more information about this approach, +-- There is more information about using ghci -- on the wiki: https://github.com/yesodweb/yesod/wiki/ghci module DevelMain where @@ -636,27 +648,31 @@ import Foreign.Store import Network.Wai.Handler.Warp -- | Start or restart the server. +-- A Store holds onto some data across ghci reloads update :: IO () update = do - mtidStore <- lookupStore tid_1 + mtidStore <- lookupStore tidStoreNum case mtidStore of + -- no server running Nothing -> do - done <- newEmptyMVar - _done_0 <- newStore done + done <- storeAction doneStore newEmptyMVar tid <- start done - tidRef <- newIORef tid - _tid_1 <- newStore tidRef + _ <- storeAction (Store tidStoreNum) (newIORef tid) return () - Just tidStore -> do - tidRef <- readStore tidStore - tid <- readIORef tidRef - done <- readStore (Store done_0) - killThread tid - takeMVar done - newTid <- start done - writeIORef tidRef newTid - where tid_1 = 1 - done_0 = 0 + -- server is already running + Just tidStore -> + -- shut the server down with killThread and wait for the done signal + modifyStoredIORef tidStore $ \tid -> do + killThread tid + withStore doneStore takeMVar >> readStore doneStore >>= start + where + doneStore = Store 0 + tidStoreNum = 1 + + modifyStoredIORef :: Store (IORef a) -> (a -> IO a) -> IO () + modifyStoredIORef store f = withStore store $ \ref -> do + v <- readIORef ref + f v >>= writeIORef ref -- | Start the server in a separate thread. start :: MVar () -- ^ Written to when the thread is killed. diff --git a/yesod-bin/hsfiles/simple.hsfiles b/yesod-bin/hsfiles/simple.hsfiles index d49118b5..11a3e6f6 100644 --- a/yesod-bin/hsfiles/simple.hsfiles +++ b/yesod-bin/hsfiles/simple.hsfiles @@ -196,6 +196,13 @@ instance Yesod App where Just $ uncurry (joinPath y (Settings.staticRoot $ settings y)) $ renderRoute s urlRenderOverride _ _ = Nothing + -- Routes not requiring authenitcation. + isAuthorized (AuthR _) _ = return Authorized + isAuthorized FaviconR _ = return Authorized + isAuthorized RobotsR _ = return Authorized + -- Default to Authorized for now. + isAuthorized _ _ = return Authorized + -- This function creates static content files in the static folder -- and names them based on a hash of their content. This allows -- expiration dates to be set far in the future without worry of @@ -531,17 +538,21 @@ combineScripts = combineScripts' development combineSettings -- -- cabal repl --ghc-options="-O0 -fobject-code" -- +-- run with: +-- +-- :l DevelMain +-- DevelMain.update +-- -- You will need to add these packages to your .cabal file --- * foreign-store (very light-weight) +-- * foreign-store >= 0.1 (very light-weight) -- * warp (you already depend on this, it just isn't in your .cabal file) -- -- If you don't use cabal repl, you will need --- to run the following in GHCi or to add it to --- your .ghci file. +-- to add settings to your .ghci file. -- -- :set -DDEVELOPMENT -- --- There is more information about this approach, +-- There is more information about using ghci -- on the wiki: https://github.com/yesodweb/yesod/wiki/ghci module DevelMain where @@ -555,27 +566,31 @@ import Foreign.Store import Network.Wai.Handler.Warp -- | Start or restart the server. +-- A Store holds onto some data across ghci reloads update :: IO () update = do - mtidStore <- lookupStore tid_1 + mtidStore <- lookupStore tidStoreNum case mtidStore of + -- no server running Nothing -> do - done <- newEmptyMVar - _done_0 <- newStore done + done <- storeAction doneStore newEmptyMVar tid <- start done - tidRef <- newIORef tid - _tid_1 <- newStore tidRef + _ <- storeAction (Store tidStoreNum) (newIORef tid) return () - Just tidStore -> do - tidRef <- readStore tidStore - tid <- readIORef tidRef - done <- readStore (Store done_0) - killThread tid - takeMVar done - newTid <- start done - writeIORef tidRef newTid - where tid_1 = 1 - done_0 = 0 + -- server is already running + Just tidStore -> + -- shut the server down with killThread and wait for the done signal + modifyStoredIORef tidStore $ \tid -> do + killThread tid + withStore doneStore takeMVar >> readStore doneStore >>= start + where + doneStore = Store 0 + tidStoreNum = 1 + + modifyStoredIORef :: Store (IORef a) -> (a -> IO a) -> IO () + modifyStoredIORef store f = withStore store $ \ref -> do + v <- readIORef ref + f v >>= writeIORef ref -- | Start the server in a separate thread. start :: MVar () -- ^ Written to when the thread is killed. diff --git a/yesod-bin/hsfiles/sqlite.hsfiles b/yesod-bin/hsfiles/sqlite.hsfiles index d314c06a..30436df7 100644 --- a/yesod-bin/hsfiles/sqlite.hsfiles +++ b/yesod-bin/hsfiles/sqlite.hsfiles @@ -218,6 +218,13 @@ instance Yesod App where -- The page to be redirected to when authentication is required. authRoute _ = Just $ AuthR LoginR + -- Routes not requiring authenitcation. + isAuthorized (AuthR _) _ = return Authorized + isAuthorized FaviconR _ = return Authorized + isAuthorized RobotsR _ = return Authorized + -- Default to Authorized for now. + isAuthorized _ _ = return Authorized + -- This function creates static content files in the static folder -- and names them based on a hash of their content. This allows -- expiration dates to be set far in the future without worry of @@ -365,6 +372,7 @@ import Yesod import Data.Text (Text) import Database.Persist.Quasi import Data.Typeable (Typeable) +import Prelude -- You can define all of your database entities in the entities file. -- You can find more information on persistent and how to declare entities @@ -612,17 +620,21 @@ combineScripts = combineScripts' development combineSettings -- -- cabal repl --ghc-options="-O0 -fobject-code" -- +-- run with: +-- +-- :l DevelMain +-- DevelMain.update +-- -- You will need to add these packages to your .cabal file --- * foreign-store (very light-weight) +-- * foreign-store >= 0.1 (very light-weight) -- * warp (you already depend on this, it just isn't in your .cabal file) -- -- If you don't use cabal repl, you will need --- to run the following in GHCi or to add it to --- your .ghci file. +-- to add settings to your .ghci file. -- -- :set -DDEVELOPMENT -- --- There is more information about this approach, +-- There is more information about using ghci -- on the wiki: https://github.com/yesodweb/yesod/wiki/ghci module DevelMain where @@ -636,27 +648,31 @@ import Foreign.Store import Network.Wai.Handler.Warp -- | Start or restart the server. +-- A Store holds onto some data across ghci reloads update :: IO () update = do - mtidStore <- lookupStore tid_1 + mtidStore <- lookupStore tidStoreNum case mtidStore of + -- no server running Nothing -> do - done <- newEmptyMVar - _done_0 <- newStore done + done <- storeAction doneStore newEmptyMVar tid <- start done - tidRef <- newIORef tid - _tid_1 <- newStore tidRef + _ <- storeAction (Store tidStoreNum) (newIORef tid) return () - Just tidStore -> do - tidRef <- readStore tidStore - tid <- readIORef tidRef - done <- readStore (Store done_0) - killThread tid - takeMVar done - newTid <- start done - writeIORef tidRef newTid - where tid_1 = 1 - done_0 = 0 + -- server is already running + Just tidStore -> + -- shut the server down with killThread and wait for the done signal + modifyStoredIORef tidStore $ \tid -> do + killThread tid + withStore doneStore takeMVar >> readStore doneStore >>= start + where + doneStore = Store 0 + tidStoreNum = 1 + + modifyStoredIORef :: Store (IORef a) -> (a -> IO a) -> IO () + modifyStoredIORef store f = withStore store $ \ref -> do + v <- readIORef ref + f v >>= writeIORef ref -- | Start the server in a separate thread. start :: MVar () -- ^ Written to when the thread is killed.