Skip to content
Browse files

Refactor defaultApp to be more readable

  • Loading branch information...
1 parent f5cfd43 commit b01a8ba63e6118b6e8baf6c8c3327401894b438d Josh Hoyt committed Jan 30, 2011
Showing with 14 additions and 10 deletions.
  1. +14 −10 src/Alpacas.hs
View
24 src/Alpacas.hs
@@ -39,16 +39,20 @@ defaultApp :: Dyre.Params Config -> Config -> Snap ()
defaultApp params cfg =
let r = renderer cfg . defaultStyles
r' = r . addEditJS
- in ifTop (respondPage r' (statusPage cfg)) <|>
- path "reload" reloadServer <|>
- path "find-file" (editFileParam r') <|>
- do q <- liftIO $ configPath params
- let editPfx fn = editFile (q </> fn) >>= respondPage r'
- path "edit-config" (editPfx "alpacas.hs") <|>
- path "edit-css" (editPfx ("css" </> "default.css")) <|>
- path "edit-js" (editPfx ("js" </> "alpacas.js")) <|>
- dir "css" (fileServe $ q </> "css") <|>
- dir "js" (fileServe (q </> "js"))
+ choice = foldr1 (<|>)
+ app = choice [ ifTop $ respondPage r' $ statusPage cfg
+ , path "reload" reloadServer
+ , path "find-file" $ editFileParam r'
+ , do q <- liftIO $ configPath params
+ let editPfx fn = editFile (q </> fn) >>= respondPage r'
+ choice [ path "edit-config" $ editPfx "alpacas.hs"
+ , path "edit-css" $ editPfx $ "css" </> "default.css"
+ , path "edit-js" $ editPfx $ "js" </> "alpacas.js"
+ , dir "css" $ fileServe $ q </> "css"
+ , dir "js" $ fileServe $ q </> "js"
+ ]
+ ]
+ in app
configPath :: Dyre.Params a -> IO FilePath
configPath p = do (_,_,fn,_) <- Dyre.getPaths p

0 comments on commit b01a8ba

Please sign in to comment.
Something went wrong with that request. Please try again.