on master help sign in
Hamlet dependency tracking
da67338Michael Snoyman
wai-handler-devel.cabal+2−1
@@ -1,5 +1,5 @@
1Name: wai-handler-devel
1Name: wai-handler-devel
2−Version: 0.2.0.1
2+Version: 0.2.1
3Synopsis: WAI server that automatically reloads code after modification.
3Synopsis: WAI server that automatically reloads code after modification.
4Description: 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.
4Description: 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.
5 .
5 .
@@ -33,6 +33,7 @@ Library
33 , old-time >= 1.0 && < 1.1
33 , old-time >= 1.0 && < 1.1
34 , enumerator >= 0.4.6 && < 0.5
34 , enumerator >= 0.4.6 && < 0.5
35 , transformers >= 0.2.2 && < 0.3
35 , transformers >= 0.2.2 && < 0.3
36+ , attoparsec-text >= 0.8.2 && < 0.9
36 Exposed-modules: Network.Wai.Handler.DevelServer
37 Exposed-modules: Network.Wai.Handler.DevelServer
37 Network.Wai.Application.Devel
38 Network.Wai.Application.Devel
38 ghc-options: -Wall
39 ghc-options: -Wall
wai-handler-devel.hs+43−2
@@ -1,19 +1,60 @@
1{-# LANGUAGE DeriveDataTypeable #-}
1{-# LANGUAGE DeriveDataTypeable #-}
2+{-# LANGUAGE OverloadedStrings #-}
2import Network.Wai.Handler.DevelServer (runQuit)
3import Network.Wai.Handler.DevelServer (runQuit)
3import System.Console.CmdArgs
4import System.Console.CmdArgs
5+import qualified Data.Attoparsec.Text.Lazy as A
6+import qualified Data.Text.Lazy.IO as TIO
7+import Control.Applicative ((<|>))
8+import Data.Char (isSpace)
9+import Data.Maybe (mapMaybe)
4
10
5data Devel = Devel
11data Devel = Devel
6 { port :: Int
12 { port :: Int
7 , moduleName :: String
13 , moduleName :: String
8 , function :: String
14 , function :: String
15+ , yesod :: Bool
9 }
16 }
10 deriving (Show, Data, Typeable)
17 deriving (Show, Data, Typeable)
11
18
12main :: IO ()
19main :: IO ()
13main = do
20main = do
14− Devel p m f <- cmdArgs Devel
21+ Devel p m f y <- cmdArgs Devel
15 { port = 3000 &= argPos 0 &= typ "PORT"
22 { port = 3000 &= argPos 0 &= typ "PORT"
16 , moduleName = "" &= argPos 1 &= typ "MODULE"
23 , moduleName = "" &= argPos 1 &= typ "MODULE"
17 , function = "" &= argPos 2 &= typ "FUNCTION"
24 , function = "" &= argPos 2 &= typ "FUNCTION"
25+ , yesod = False
18 } &= summary "WAI development web server"
26 } &= summary "WAI development web server"
19− runQuit p m f $ const $ return []
27+ runQuit p m f $ if y then determineHamletDeps else (const $ return [])
28+
29+data TempType = Hamlet | Cassius | Lucius | Julius | Widget
30+ deriving Show
31+
32+determineHamletDeps :: FilePath -> IO [FilePath]
33+determineHamletDeps x = do
34+ y <- TIO.readFile x
35+ let z = A.parse (A.many $ (parser <|> (A.anyChar >> return Nothing))) y
36+ case z of
37+ A.Fail{} -> return []
38+ A.Done _ r -> return $ mapMaybe go r
39+ where
40+ go (Just (Hamlet, f)) = Just $ "hamlet/" ++ f ++ ".hamlet"
41+ go (Just (Widget, f)) = Just $ "hamlet/" ++ f ++ ".hamlet"
42+ go _ = Nothing
43+ parser = do
44+ ty <- (A.string "$(hamletFile " >> return Hamlet)
45+ <|> (A.string "$(cassiusFile " >> return Cassius)
46+ <|> (A.string "$(luciusFile " >> return Lucius)
47+ <|> (A.string "$(juliusFile " >> return Julius)
48+ <|> (A.string "$(widgetFile " >> return Widget)
49+ <|> (A.string "$(Settings.hamletFile " >> return Hamlet)
50+ <|> (A.string "$(Settings.cassiusFile " >> return Cassius)
51+ <|> (A.string "$(Settings.luciusFile " >> return Lucius)
52+ <|> (A.string "$(Settings.juliusFile " >> return Julius)
53+ <|> (A.string "$(Settings.widgetFile " >> return Widget)
54+ A.skipWhile isSpace
55+ _ <- A.char '"'
56+ y <- A.many1 $ A.satisfy (/= '"')
57+ _ <- A.char '"'
58+ A.skipWhile isSpace
59+ _ <- A.char ')'
60+ return $ Just (ty, y)