[interesting behavior for happsbrowse when viewing templates, they're colored. i kind of like it even though it's not quite right thomashartman1@gmail.com**20081004121116] hunk ./src/Controller.hs 31 +import HAppSBrowse hunk ./src/Controller.hs 148 - , browsedir "templates" - , browsedirWith (ifHaskellFile [withRequest colorize]) "src" + , browsedir "templates"-- current directory + , browsedirWith (ifHaskellFile [withRequest colorize]) "src" hunk ./src/Controller.hs 152 -browsedirWith sp d = multi [ - sp - , browsedir d - ] - - hunk ./src/Controller.hs 177 --- getpath "mee" ["mah","moh.txt"] --- "mee/mah/moh.txt" (and uses os-appropriate directory separator) ---getpath topdir pathparts = - addfile ./src/HAppSBrowse.hs hunk ./src/HAppSBrowse.hs 1 +module HAppSBrowse (browsedir, browsedirWith) where + +import HAppS.Server +import Control.Monad.Trans +import System.Directory +import System.FilePath +import Data.List +import qualified Data.ByteString.Char8 as B +import qualified Data.ByteString.Lazy.Char8 as L + +-- Directory browsing for happs, suggest including this in head, as replacement for fileserve +-- eg: browsedir "templates" +browsedir :: String -> ServerPartT IO Response +browsedir d = multi [ + ServerPartT $ \rq -> do + let rqp = ( pathstring $ rqPaths rq ) + if (not $ isInfixOf d rqp) + then noHandle + else do + isDir <- liftIO $ doesDirectoryExist rqp + if isDir + then do + fs <- liftIO $ getDirectoryContents rqp + + let + flinks = map g . filter (not . boringfile ) . sort $ fs + where g f = simpleLink ('/' : (combine rqp f)) f + return . toResponse . HtmlString $ "