Permalink
Browse files

Removed the Timer extension related code

  • Loading branch information...
1 parent da03a73 commit 718c1e73bbf63790214f561dbccecf709068ceba @Palmik committed Apr 18, 2011
Showing with 2 additions and 132 deletions.
  1. +2 −12 src/Application.hs
  2. +0 −53 src/Snap/Extension/Timer.hs
  3. +0 −67 src/Snap/Extension/Timer/Impl.hs
View
@@ -21,18 +21,15 @@ import Snap.Extension.DB.MongoDB
------------------------------------------------------------------------------
-- | 'Application' is our application's monad. It uses 'SnapExtend' from
-- 'Snap.Extension' to provide us with an extended 'MonadSnap' making use of
--- the Heist and Timer Snap extensions.
+-- the Heist and MongoDB Snap extensions.
type Application = SnapExtend ApplicationState
------------------------------------------------------------------------------
-- | 'ApplicationState' is a record which contains the state needed by the Snap
--- extensions we're using. We're using Heist so we can easily render Heist
--- templates, and Timer simply to illustrate the config loading differences
--- between development and production modes.
+-- extensions we're using.
data ApplicationState = ApplicationState
{ templateState :: HeistState Application
- , timerState :: TimerState
, databaseState :: MongoDBState
}
@@ -42,12 +39,6 @@ instance HasHeistState Application ApplicationState where
getHeistState = templateState
setHeistState s a = a { templateState = s }
-
-------------------------------------------------------------------------------
-instance HasTimerState ApplicationState where
- getTimerState = timerState
- setTimerState s a = a { timerState = s }
-
------------------------------------------------------------------------------
instance HasMongoDBState ApplicationState where
getMongoDBState = databaseState
@@ -62,6 +53,5 @@ instance HasMongoDBState ApplicationState where
applicationInitializer :: Initializer ApplicationState
applicationInitializer = do
heist <- heistInitializer "resources/templates"
- timer <- timerInitializer
database <- mongoDBInitializer (Host "127.0.0.1" $ PortNumber 27017) 1 "pastie"
return $ ApplicationState heist timer database
@@ -1,53 +0,0 @@
-{-|
-
-'Snap.Extension.Timer' exports the 'MonadTimer' interface which allows you to
-keep track of the time at which your application was started. The interface's
-only operation is 'startTime'.
-
-Two splices, 'startTimeSplice' and 'currentTimeSplice' are also provided, for
-your convenience.
-
-'Snap.Extension.Timer.Timer' contains the only implementation of this
-interface and can be used to turn your application's monad into a
-'MonadTimer'.
-
-More than anything else, this is intended to serve as an example Snap
-Extension to any developer wishing to write their own Snap Extension.
-
--}
-
-module Snap.Extension.Timer
- ( MonadTimer(..)
- , startTimeSplice
- , currentTimeSplice
- ) where
-
-import Control.Monad.Trans
-import Data.Time.Clock
-import qualified Data.Text as T
-import Snap.Types
-import Text.Templating.Heist
-import Text.XmlHtml
-
-
-------------------------------------------------------------------------------
--- | The 'MonadTimer' type class. Minimal complete definition: 'startTime'.
-class MonadSnap m => MonadTimer m where
- -- | The time at which your application was last loaded.
- startTime :: m UTCTime
-
-
-------------------------------------------------------------------------------
--- | For your convenience, a splice which shows the start time.
-startTimeSplice :: MonadTimer m => Splice m
-startTimeSplice = do
- time <- lift startTime
- return $ [TextNode $ T.pack $ show $ time]
-
-
-------------------------------------------------------------------------------
--- | For your convenience, a splice which shows the current time.
-currentTimeSplice :: MonadTimer m => Splice m
-currentTimeSplice = do
- time <- lift $ liftIO getCurrentTime
- return $ [TextNode $ T.pack $ show $ time]
@@ -1,67 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-
-{-|
-
-'Snap.Extension.Timer.Impl' is an implementation of the 'MonadTimer'
-interface defined in 'Snap.Extension.Timer'.
-
-As always, to use, add 'TimerState' to your application's state, along with an
-instance of 'HasTimerState' for your application's state, making sure to use a
-'timerInitializer' in your application's 'Initializer', and then you're ready to go.
-
-This implementation does not require that your application's monad implement
-interfaces from any other Snap Extension.
-
--}
-
-module Snap.Extension.Timer.Impl
- ( TimerState
- , HasTimerState(..)
- , timerInitializer
- , module Snap.Extension.Timer
- ) where
-
-import Control.Monad.Reader
-import Data.Time.Clock
-import Snap.Extension
-import Snap.Extension.Timer
-import Snap.Types
-
-------------------------------------------------------------------------------
--- | Your application's state must include a 'TimerState' in order for your
--- application to be a 'MonadTimer'.
-newtype TimerState = TimerState
- { _startTime :: UTCTime
- }
-
-
-------------------------------------------------------------------------------
--- | For your application's monad to be a 'MonadTimer', your application's
--- state needs to be an instance of 'HasTimerState'. Minimal complete
--- definition: 'getTimerState', 'setTimerState'.
-class HasTimerState s where
- getTimerState :: s -> TimerState
- setTimerState :: TimerState -> s -> s
-
-
-------------------------------------------------------------------------------
--- | The Initializer for 'TimerState'. No arguments are required.
-timerInitializer :: Initializer TimerState
-timerInitializer = liftIO getCurrentTime >>= mkInitializer . TimerState
-
-
-------------------------------------------------------------------------------
-instance InitializerState TimerState where
- extensionId = const "Timer/Timer"
- mkCleanup = const $ return ()
- mkReload = const $ return ()
-
-
-------------------------------------------------------------------------------
-instance HasTimerState s => MonadTimer (SnapExtend s) where
- startTime = fmap _startTime $ asks getTimerState
-
-
-------------------------------------------------------------------------------
-instance (MonadSnap m, HasTimerState s) => MonadTimer (ReaderT s m) where
- startTime = fmap _startTime $ asks getTimerState

0 comments on commit 718c1e7

Please sign in to comment.