wai-handler-devel 0.2.0.1 → 0.2.1
raw patch · 2 files changed
+45/−3 lines, 2 filesdep +attoparsec-text
Dependencies added: attoparsec-text
Files
- wai-handler-devel.cabal +2/−1
- wai-handler-devel.hs +43/−2
wai-handler-devel.cabal view
@@ -1,5 +1,5 @@ Name: wai-handler-devel-Version: 0.2.0.1+Version: 0.2.1 Synopsis: WAI server that automatically reloads code after modification. Description: This handler automatically reloads your source code upon any changes. It works by using the hint package, essentially embedding GHC inside the handler. The handler (both the executable and library) takes three arguments: the port to listen on, the module name containing the application function, and the name of the function. .@@ -33,6 +33,7 @@ , old-time >= 1.0 && < 1.1 , enumerator >= 0.4.6 && < 0.5 , transformers >= 0.2.2 && < 0.3+ , attoparsec-text >= 0.8.2 && < 0.9 Exposed-modules: Network.Wai.Handler.DevelServer Network.Wai.Application.Devel ghc-options: -Wall
wai-handler-devel.hs view
@@ -1,19 +1,60 @@ {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE OverloadedStrings #-} import Network.Wai.Handler.DevelServer (runQuit) import System.Console.CmdArgs+import qualified Data.Attoparsec.Text.Lazy as A+import qualified Data.Text.Lazy.IO as TIO+import Control.Applicative ((<|>))+import Data.Char (isSpace)+import Data.Maybe (mapMaybe) data Devel = Devel { port :: Int , moduleName :: String , function :: String+ , yesod :: Bool } deriving (Show, Data, Typeable) main :: IO () main = do- Devel p m f <- cmdArgs Devel+ Devel p m f y <- cmdArgs Devel { port = 3000 &= argPos 0 &= typ "PORT" , moduleName = "" &= argPos 1 &= typ "MODULE" , function = "" &= argPos 2 &= typ "FUNCTION"+ , yesod = False } &= summary "WAI development web server"- runQuit p m f $ const $ return []+ runQuit p m f $ if y then determineHamletDeps else (const $ return [])++data TempType = Hamlet | Cassius | Lucius | Julius | Widget+ deriving Show++determineHamletDeps :: FilePath -> IO [FilePath]+determineHamletDeps x = do+ y <- TIO.readFile x+ let z = A.parse (A.many $ (parser <|> (A.anyChar >> return Nothing))) y+ case z of+ A.Fail{} -> return []+ A.Done _ r -> return $ mapMaybe go r+ where+ go (Just (Hamlet, f)) = Just $ "hamlet/" ++ f ++ ".hamlet"+ go (Just (Widget, f)) = Just $ "hamlet/" ++ f ++ ".hamlet"+ go _ = Nothing+ parser = do+ ty <- (A.string "$(hamletFile " >> return Hamlet)+ <|> (A.string "$(cassiusFile " >> return Cassius)+ <|> (A.string "$(luciusFile " >> return Lucius)+ <|> (A.string "$(juliusFile " >> return Julius)+ <|> (A.string "$(widgetFile " >> return Widget)+ <|> (A.string "$(Settings.hamletFile " >> return Hamlet)+ <|> (A.string "$(Settings.cassiusFile " >> return Cassius)+ <|> (A.string "$(Settings.luciusFile " >> return Lucius)+ <|> (A.string "$(Settings.juliusFile " >> return Julius)+ <|> (A.string "$(Settings.widgetFile " >> return Widget)+ A.skipWhile isSpace+ _ <- A.char '"'+ y <- A.many1 $ A.satisfy (/= '"')+ _ <- A.char '"'+ A.skipWhile isSpace+ _ <- A.char ')'+ return $ Just (ty, y)