Messages files support in yesod build

This commit is contained in:
Michael Snoyman 2011-05-16 22:04:35 +03:00
parent c406c50970
commit 350f0e947c
4 changed files with 38 additions and 29 deletions

View File

@ -23,6 +23,7 @@ import Data.Monoid (mappend)
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.Set as Set import qualified Data.Set as Set
import System.PosixCompat.Files (accessTime, modificationTime, getFileStatus, setFileTimes) import System.PosixCompat.Files (accessTime, modificationTime, getFileStatus, setFileTimes)
import Data.Text (unpack)
build :: IO () build :: IO ()
build = do build = do
@ -56,7 +57,7 @@ touchDeps =
mapM_ go . Map.toList mapM_ go . Map.toList
where where
go (x, ys) = do go (x, ys) = do
fs <- getFileStatus x fs <- getFileStatus x -- FIXME ignore exceptions
flip mapM_ (Set.toList ys) $ \y -> do flip mapM_ (Set.toList ys) $ \y -> do
fs' <- getFileStatus y fs' <- getFileStatus y
if modificationTime fs' < modificationTime fs if modificationTime fs' < modificationTime fs
@ -88,38 +89,47 @@ findHaskellFiles path = do
then return [y] then return [y]
else return [] else return []
data TempType = Hamlet | Cassius | Lucius | Julius | Widget | Verbatim data TempType = Hamlet | Verbatim | Messages FilePath
deriving Show deriving Show
determineHamletDeps :: FilePath -> IO [FilePath] determineHamletDeps :: FilePath -> IO [FilePath]
determineHamletDeps x = do determineHamletDeps x = do
y <- TIO.readFile x y <- TIO.readFile x -- FIXME catch IO exceptions
let z = A.parse (A.many $ (parser <|> (A.anyChar >> return Nothing))) y let z = A.parse (A.many $ (parser <|> (A.anyChar >> return Nothing))) y
case z of case z of
A.Fail{} -> return [] A.Fail{} -> return []
A.Done _ r -> return $ mapMaybe go r A.Done _ r -> return $ concatMap go r
where where
go (Just (Hamlet, f)) = Just $ "hamlet/" ++ f ++ ".hamlet" go (Just (Hamlet, f)) = [f, "hamlet/" ++ f ++ ".hamlet"]
go (Just (Widget, f)) = Just $ "hamlet/" ++ f ++ ".hamlet" go (Just (Verbatim, f)) = [f]
go (Just (Verbatim, f)) = Just f go (Just (Messages f, _)) = [f]
go _ = Nothing go Nothing = []
parser = do parser = do
ty <- (A.string "$(hamletFile " >> return Hamlet) ty <- (A.string "$(hamletFile " >> return Hamlet)
<|> (A.string "$(cassiusFile " >> return Cassius) <|> (A.string "$(ihamletFile " >> return Hamlet)
<|> (A.string "$(luciusFile " >> return Lucius) <|> (A.string "$(whamletFile " >> return Hamlet)
<|> (A.string "$(juliusFile " >> return Julius) <|> (A.string "$(html " >> return Hamlet)
<|> (A.string "$(widgetFile " >> return Widget) <|> (A.string "$(widgetFile " >> return Hamlet)
<|> (A.string "$(Settings.hamletFile " >> return Hamlet) <|> (A.string "$(Settings.hamletFile " >> return Hamlet)
<|> (A.string "$(Settings.cassiusFile " >> return Cassius) <|> (A.string "$(Settings.widgetFile " >> return Hamlet)
<|> (A.string "$(Settings.luciusFile " >> return Lucius)
<|> (A.string "$(Settings.juliusFile " >> return Julius)
<|> (A.string "$(Settings.widgetFile " >> return Widget)
<|> (A.string "$(persistFile " >> return Verbatim) <|> (A.string "$(persistFile " >> return Verbatim)
<|> (A.string "$(parseRoutesFile " >> return Verbatim) <|> (A.string "$(parseRoutesFile " >> return Verbatim)
A.skipWhile isSpace <|> (do
_ <- A.char '"' A.string "\nmkMessage \""
y <- A.many1 $ A.satisfy (/= '"') A.skipWhile (/= '"')
_ <- A.char '"' A.string "\" \""
A.skipWhile isSpace x <- A.many1 $ A.satisfy (/= '"')
_ <- A.char ')' A.string "\" \""
return $ Just (ty, y) y <- A.many1 $ A.satisfy (/= '"')
A.string "\""
return $ Messages $ concat [x, "/", y, ".msg"])
case ty of
Messages{} -> return $ Just (ty, "")
_ -> do
A.skipWhile isSpace
_ <- A.char '"'
y <- A.many1 $ A.satisfy (/= '"')
_ <- A.char '"'
A.skipWhile isSpace
_ <- A.char ')'
return $ Just (ty, y)

View File

@ -143,7 +143,6 @@ getFileList = do
loop :: FileList -> IO () -> IO () loop :: FileList -> IO () -> IO ()
loop oldList getNewApp = do loop oldList getNewApp = do
putStrLn "Testing files..."
newList <- getFileList newList <- getFileList
when (newList /= oldList) getNewApp when (newList /= oldList) getNewApp
threadDelay 1000000 threadDelay 1000000

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,5 +1,5 @@
name: yesod name: yesod
version: 0.8.0.1 version: 0.8.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>
@ -13,7 +13,7 @@ category: Web, Yesod
stability: Stable stability: Stable
cabal-version: >= 1.6 cabal-version: >= 1.6
build-type: Simple build-type: Simple
homepage: http://docs.yesodweb.com/ homepage: http://www.yesodweb.com/
extra-source-files: scaffold/*.cg extra-source-files: scaffold/*.cg
flag ghc7 flag ghc7
@ -24,8 +24,8 @@ library
cpp-options: -DGHC7 cpp-options: -DGHC7
else else
build-depends: base >= 4 && < 4.3 build-depends: base >= 4 && < 4.3
build-depends: yesod-core >= 0.8 && < 0.9 build-depends: yesod-core >= 0.8.1 && < 0.9
, yesod-auth >= 0.4 && < 0.5 , yesod-auth >= 0.4 && < 0.6
, yesod-json >= 0.1 && < 0.2 , yesod-json >= 0.1 && < 0.2
, yesod-persistent >= 0.1 && < 0.2 , yesod-persistent >= 0.1 && < 0.2
, yesod-static >= 0.1 && < 0.2 , yesod-static >= 0.1 && < 0.2
@ -34,7 +34,7 @@ library
, transformers >= 0.2 && < 0.3 , transformers >= 0.2 && < 0.3
, wai >= 0.4 && < 0.5 , wai >= 0.4 && < 0.5
, wai-extra >= 0.4 && < 0.5 , wai-extra >= 0.4 && < 0.5
, hamlet >= 0.8 && < 0.9 , hamlet >= 0.8.1 && < 0.9
, warp >= 0.4 && < 0.5 , warp >= 0.4 && < 0.5
, mime-mail >= 0.3 && < 0.4 , mime-mail >= 0.3 && < 0.4
, hjsmin >= 0.0.13 && < 0.1 , hjsmin >= 0.0.13 && < 0.1