Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation of wrapSite, runSnaplet and serveSnaplet #44

Merged
merged 2 commits into from
Sep 20, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/Snap/Snaplet/Internal/Initializer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,14 @@ addRoutes rs = do


------------------------------------------------------------------------------
-- | Wraps the snaplet's routing. When all is said and done, a snaplet's
-- routes end up getting combined into a single 'Handler' action. This
-- function allows you to modify that Handler before it actually gets served.
-- This allows you to do things that need to happen for every request handled
-- by your snaplet. Here are some examples of things you might do:
-- | Wraps the /base/ snaplet's routing in another handler, allowing you to run
-- code before and after all routes in an application.
--
-- Here are some examples of things you might do:
--
-- > wrapSite (\site -> logHandlerStart >> site >> logHandlerFinished)
-- > wrapSite (\site -> ensureAdminUser >> site)
--
-- @wrapSite (\site -> removePathTrailingSlashes >> site)@
-- @wrapSite (\site -> logHandlerStart >> site >> logHandlerFinished)@
-- @wrapSite (\site -> ensureAdminUser >> site)@
wrapSite :: (Handler b v () -> Handler b v ())
-- ^ Handler modifier function
-> Initializer b v ()
Expand Down Expand Up @@ -510,12 +509,12 @@ runInitializer' mvar env b@(Initializer i) cwd = do


------------------------------------------------------------------------------
-- | Given an envirnoment and a Snaplet initializer, produce the set of
-- messages generated during initialization, a snap handler, and a cleanup
-- action. The environment is an arbitrary string such as "devel" or
-- "production". This string is used to determine the name of the config
-- files used each snaplet. If an environment of Nothing is used, then
-- runSnaplet defaults to "devel".
-- | Given an environment and a Snaplet initializer, produce a concatenated log
-- of all messages generated during initialization, a snap handler, and a
-- cleanup action. The environment is an arbitrary string such as \"devel\" or
-- \"production\". This string is used to determine the name of the
-- configuration files used by each snaplet. If an environment of Nothing is
-- used, then runSnaplet defaults to \"devel\".
runSnaplet :: Maybe String -> SnapletInit b b -> IO (Text, Snap (), IO ())
runSnaplet env (SnapletInit b) = do
snapletMVar <- newEmptyMVar
Expand Down Expand Up @@ -546,9 +545,15 @@ combineConfig config handler = do


------------------------------------------------------------------------------
-- | Serves a top-level snaplet as a web application. Reads command-line
-- arguments. FIXME: document this.
serveSnaplet :: Config Snap AppConfig -> SnapletInit b b -> IO ()
-- | Initialize and run a Snaplet. This function parses command-line arguments,
-- runs the given Snaplet initializer, and starts an HTTP server running the
-- Snaplet's toplevel 'Handler'.
serveSnaplet :: Config Snap AppConfig
-- ^ The configuration of the server - you can usually pass a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snap code style is to put the "-- ^" on the same line as the argument , i.e.

serveSnaplet :: Config Snap AppConfig      -- ^ blah blah blah
             -> SnapletInit b b            -- ^ blah blah blah
             -> IO ()

Also, "the configuration of the server" can be "the server configuration", and "you can usually pass a default Config via" can be shortened to "this is normally" or "this is often"

P.S. thanks for working on this :)

-- default 'Config' via 'Snap.Http.Server.Config.defaultConfig'.
-> SnapletInit b b
-- ^ The snaplet initializer function.
-> IO ()
serveSnaplet startConfig initializer = do
config <- commandLineAppConfig startConfig
let env = appEnvironment =<< getOther config
Expand Down