Better Lucius support, rearrange some files

This commit is contained in:
Michael Snoyman 2011-04-19 21:01:53 +03:00
parent 44e22e9261
commit 97ec67a8ba
10 changed files with 47 additions and 19 deletions

View File

@ -98,10 +98,12 @@ scaffold = do
mkDir "Handler" mkDir "Handler"
mkDir "hamlet" mkDir "hamlet"
mkDir "cassius" mkDir "cassius"
mkDir "lucius"
mkDir "julius" mkDir "julius"
mkDir "static" mkDir "static"
mkDir "config"
writeFile' (project ++ ".hs") $(codegen "test_hs") writeFile' ("config/" ++ project ++ ".hs") $(codegen "test_hs")
writeFile' "devel-server.hs" $(codegen "devel-server_hs") writeFile' "devel-server.hs" $(codegen "devel-server_hs")
writeFile' (project ++ ".cabal") $ if backendS == "m" then $(codegen "mini-cabal") else $(codegen "cabal") writeFile' (project ++ ".cabal") $ if backendS == "m" then $(codegen "mini-cabal") else $(codegen "cabal")
writeFile' "LICENSE" $(codegen "LICENSE") writeFile' "LICENSE" $(codegen "LICENSE")
@ -109,19 +111,19 @@ scaffold = do
writeFile' "Controller.hs" $ if backendS == "m" then $(codegen "mini-Controller_hs") else $(codegen "Controller_hs") writeFile' "Controller.hs" $ if backendS == "m" then $(codegen "mini-Controller_hs") else $(codegen "Controller_hs")
writeFile' "Handler/Root.hs" $ if backendS == "m" then $(codegen "mini-Root_hs") else $(codegen "Root_hs") writeFile' "Handler/Root.hs" $ if backendS == "m" then $(codegen "mini-Root_hs") else $(codegen "Root_hs")
when (backendS /= "m") $ writeFile' "Model.hs" $(codegen "Model_hs") when (backendS /= "m") $ writeFile' "Model.hs" $(codegen "Model_hs")
writeFile' "Settings.hs" $ if backendS == "m" then $(codegen "mini-Settings_hs") else $(codegen "Settings_hs") writeFile' "config/Settings.hs" $ if backendS == "m" then $(codegen "mini-Settings_hs") else $(codegen "Settings_hs")
writeFile' "StaticFiles.hs" $(codegen "StaticFiles_hs") writeFile' "config/StaticFiles.hs" $(codegen "StaticFiles_hs")
writeFile' "cassius/default-layout.cassius" writeFile' "cassius/default-layout.cassius"
$(codegen "default-layout_cassius") $(codegen "default-layout_cassius")
writeFile' "hamlet/default-layout.hamlet" writeFile' "hamlet/default-layout.hamlet"
$(codegen "default-layout_hamlet") $(codegen "default-layout_hamlet")
writeFile' "hamlet/homepage.hamlet" $ if backendS == "m" then $(codegen "mini-homepage_hamlet") else $(codegen "homepage_hamlet") writeFile' "hamlet/homepage.hamlet" $ if backendS == "m" then $(codegen "mini-homepage_hamlet") else $(codegen "homepage_hamlet")
writeFile' "routes" $ if backendS == "m" then $(codegen "mini-routes") else $(codegen "routes") writeFile' "config/routes" $ if backendS == "m" then $(codegen "mini-routes") else $(codegen "routes")
writeFile' "cassius/homepage.cassius" $(codegen "homepage_cassius") writeFile' "cassius/homepage.cassius" $(codegen "homepage_cassius")
writeFile' "julius/homepage.julius" $(codegen "homepage_julius") writeFile' "julius/homepage.julius" $(codegen "homepage_julius")
unless (backendS == "m") $ writeFile' "entities" $(codegen "entities") unless (backendS == "m") $ writeFile' "config/models" $(codegen "entities")
S.writeFile (dir ++ "/favicon.ico") S.writeFile (dir ++ "/config/favicon.ico")
$(runIO (S.readFile "scaffold/favicon_ico.cg") >>= \bs -> do $(runIO (S.readFile "scaffold/favicon_ico.cg") >>= \bs -> do
pack <- [|S.pack|] pack <- [|S.pack|]
return $ pack `AppE` LitE (StringL $ S.unpack bs)) return $ pack `AppE` LitE (StringL $ S.unpack bs))

View File

@ -26,7 +26,7 @@ mkYesodDispatch "~sitearg~" resources~sitearg~
-- Some default handlers that ship with the Yesod site template. You will -- Some default handlers that ship with the Yesod site template. You will
-- very rarely need to modify this. -- very rarely need to modify this.
getFaviconR :: Handler () getFaviconR :: Handler ()
getFaviconR = sendFile "image/x-icon" "favicon.ico" getFaviconR = sendFile "image/x-icon" "config/favicon.ico"
getRobotsR :: Handler RepPlain getRobotsR :: Handler RepPlain
getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString) getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString)

View File

@ -8,5 +8,5 @@ import Data.Text (Text)
-- You can find more information on persistent and how to declare entities -- You can find more information on persistent and how to declare entities
-- at: -- at:
-- http://www.yesodweb.com/book/persistent/ -- http://www.yesodweb.com/book/persistent/
share [mkPersist, mkMigrate "migrateAll"] $(persistFile "entities") share [mkPersist, mkMigrate "migrateAll"] $(persistFile "config/models")

View File

@ -10,6 +10,7 @@ module Settings
( hamletFile ( hamletFile
, cassiusFile , cassiusFile
, juliusFile , juliusFile
, luciusFile
, widgetFile , widgetFile
, connStr , connStr
, ConnectionPool , ConnectionPool
@ -23,9 +24,10 @@ module Settings
import qualified Text.Hamlet as H import qualified Text.Hamlet as H
import qualified Text.Cassius as H import qualified Text.Cassius as H
import qualified Text.Julius as H import qualified Text.Julius as H
import qualified Text.Lucius as H
import Language.Haskell.TH.Syntax import Language.Haskell.TH.Syntax
~importDB~ ~importDB~
import Yesod (MonadControlIO, addWidget, addCassius, addJulius) import Yesod (MonadControlIO, addWidget, addCassius, addJulius, addLucius)
import Data.Monoid (mempty, mappend) import Data.Monoid (mempty, mappend)
import System.Directory (doesFileExist) import System.Directory (doesFileExist)
import Data.Text (Text) import Data.Text (Text)
@ -104,10 +106,11 @@ connectionCount = 10
-- used; to get the same auto-loading effect, it is recommended that you -- used; to get the same auto-loading effect, it is recommended that you
-- use the devel server. -- use the devel server.
toHamletFile, toCassiusFile, toJuliusFile :: String -> FilePath toHamletFile, toCassiusFile, toJuliusFile, toLuciusFile :: String -> FilePath
toHamletFile x = "hamlet/" ++ x ++ ".hamlet" toHamletFile x = "hamlet/" ++ x ++ ".hamlet"
toCassiusFile x = "cassius/" ++ x ++ ".cassius" toCassiusFile x = "cassius/" ++ x ++ ".cassius"
toJuliusFile x = "julius/" ++ x ++ ".julius" toJuliusFile x = "julius/" ++ x ++ ".julius"
toLuciusFile x = "lucius/" ++ x ++ ".lucius"
hamletFile :: FilePath -> Q Exp hamletFile :: FilePath -> Q Exp
hamletFile = H.hamletFile . toHamletFile hamletFile = H.hamletFile . toHamletFile
@ -119,6 +122,13 @@ cassiusFile = H.cassiusFile . toCassiusFile
cassiusFile = H.cassiusFileDebug . toCassiusFile cassiusFile = H.cassiusFileDebug . toCassiusFile
#endif #endif
luciusFile :: FilePath -> Q Exp
#ifdef PRODUCTION
luciusFile = H.luciusFile . toLuciusFile
#else
luciusFile = H.luciusFileDebug . toLuciusFile
#endif
juliusFile :: FilePath -> Q Exp juliusFile :: FilePath -> Q Exp
#ifdef PRODUCTION #ifdef PRODUCTION
juliusFile = H.juliusFile . toJuliusFile juliusFile = H.juliusFile . toJuliusFile
@ -131,7 +141,8 @@ widgetFile x = do
let h = unlessExists toHamletFile hamletFile let h = unlessExists toHamletFile hamletFile
let c = unlessExists toCassiusFile cassiusFile let c = unlessExists toCassiusFile cassiusFile
let j = unlessExists toJuliusFile juliusFile let j = unlessExists toJuliusFile juliusFile
[|addWidget $h >> addCassius $c >> addJulius $j|] let l = unlessExists toLuciusFile luciusFile
[|addWidget $h >> addCassius $c >> addJulius $j >> addLucius $l|]
where where
unlessExists tofn f = do unlessExists tofn f = do
e <- qRunIO $ doesFileExist $ tofn x e <- qRunIO $ doesFileExist $ tofn x

View File

@ -26,6 +26,7 @@ library
else else
Buildable: False Buildable: False
exposed-modules: Controller exposed-modules: Controller
hs-source-dirs: ., config
other-modules: ~sitearg~ other-modules: ~sitearg~
Model Model
Settings Settings
@ -42,7 +43,8 @@ executable ~project~
else else
ghc-options: -Wall -threaded ghc-options: -Wall -threaded
main-is: ~project~.hs main-is: config/~project~.hs
hs-source-dirs: ., config
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, yesod >= 0.8 && < 0.9 , yesod >= 0.8 && < 0.9

View File

@ -25,7 +25,7 @@ mkYesodDispatch "~sitearg~" resources~sitearg~
-- Some default handlers that ship with the Yesod site template. You will -- Some default handlers that ship with the Yesod site template. You will
-- very rarely need to modify this. -- very rarely need to modify this.
getFaviconR :: Handler () getFaviconR :: Handler ()
getFaviconR = sendFile "image/x-icon" "favicon.ico" getFaviconR = sendFile "image/x-icon" "config/favicon.ico"
getRobotsR :: Handler RepPlain getRobotsR :: Handler RepPlain
getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString) getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString)

View File

@ -10,6 +10,7 @@ module Settings
( hamletFile ( hamletFile
, cassiusFile , cassiusFile
, juliusFile , juliusFile
, luciusFile
, widgetFile , widgetFile
, approot , approot
, staticroot , staticroot
@ -19,8 +20,9 @@ module Settings
import qualified Text.Hamlet as H import qualified Text.Hamlet as H
import qualified Text.Cassius as H import qualified Text.Cassius as H
import qualified Text.Julius as H import qualified Text.Julius as H
import qualified Text.Lucius as H
import Language.Haskell.TH.Syntax import Language.Haskell.TH.Syntax
import Yesod.Widget (addWidget, addCassius, addJulius) import Yesod.Widget (addWidget, addCassius, addJulius, addLucius)
import Data.Monoid (mempty, mappend) import Data.Monoid (mempty, mappend)
import System.Directory (doesFileExist) import System.Directory (doesFileExist)
import Data.Text (Text) import Data.Text (Text)
@ -76,10 +78,11 @@ staticroot = approot `mappend` "/static"
-- used; to get the same auto-loading effect, it is recommended that you -- used; to get the same auto-loading effect, it is recommended that you
-- use the devel server. -- use the devel server.
toHamletFile, toCassiusFile, toJuliusFile :: String -> FilePath toHamletFile, toCassiusFile, toJuliusFile, toLuciusFile :: String -> FilePath
toHamletFile x = "hamlet/" ++ x ++ ".hamlet" toHamletFile x = "hamlet/" ++ x ++ ".hamlet"
toCassiusFile x = "cassius/" ++ x ++ ".cassius" toCassiusFile x = "cassius/" ++ x ++ ".cassius"
toJuliusFile x = "julius/" ++ x ++ ".julius" toJuliusFile x = "julius/" ++ x ++ ".julius"
toLuciusFile x = "lucius/" ++ x ++ ".lucius"
hamletFile :: FilePath -> Q Exp hamletFile :: FilePath -> Q Exp
hamletFile = H.hamletFile . toHamletFile hamletFile = H.hamletFile . toHamletFile
@ -91,6 +94,13 @@ cassiusFile = H.cassiusFile . toCassiusFile
cassiusFile = H.cassiusFileDebug . toCassiusFile cassiusFile = H.cassiusFileDebug . toCassiusFile
#endif #endif
luciusFile :: FilePath -> Q Exp
#ifdef PRODUCTION
luciusFile = H.luciusFile . toLuciusFile
#else
luciusFile = H.luciusFileDebug . toLuciusFile
#endif
juliusFile :: FilePath -> Q Exp juliusFile :: FilePath -> Q Exp
#ifdef PRODUCTION #ifdef PRODUCTION
juliusFile = H.juliusFile . toJuliusFile juliusFile = H.juliusFile . toJuliusFile
@ -103,7 +113,8 @@ widgetFile x = do
let h = unlessExists toHamletFile hamletFile let h = unlessExists toHamletFile hamletFile
let c = unlessExists toCassiusFile cassiusFile let c = unlessExists toCassiusFile cassiusFile
let j = unlessExists toJuliusFile juliusFile let j = unlessExists toJuliusFile juliusFile
[|addWidget $h >> addCassius $c >> addJulius $j|] let l = unlessExists toLuciusFile luciusFile
[|addWidget $h >> addCassius $c >> addJulius $j >> addLucius $l|]
where where
unlessExists tofn f = do unlessExists tofn f = do
e <- qRunIO $ doesFileExist $ tofn x e <- qRunIO $ doesFileExist $ tofn x

View File

@ -26,6 +26,7 @@ library
else else
Buildable: False Buildable: False
exposed-modules: Controller exposed-modules: Controller
hs-source-dirs: ., config
other-modules: ~sitearg~ other-modules: ~sitearg~
Settings Settings
StaticFiles StaticFiles
@ -41,7 +42,8 @@ executable ~project~
else else
ghc-options: -Wall -threaded ghc-options: -Wall -threaded
main-is: ~project~.hs main-is: config/~project~.hs
hs-source-dirs: ., config
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, yesod-core >= 0.8 && < 0.9 , yesod-core >= 0.8 && < 0.9

View File

@ -60,7 +60,7 @@ type Widget = GWidget ~sitearg~ ~sitearg~
-- for our application to be in scope. However, the handler functions -- for our application to be in scope. However, the handler functions
-- usually require access to the ~sitearg~Route datatype. Therefore, we -- usually require access to the ~sitearg~Route datatype. Therefore, we
-- split these actions into two functions and place them in separate files. -- split these actions into two functions and place them in separate files.
mkYesodData "~sitearg~" $(parseRoutesFile "routes") mkYesodData "~sitearg~" $(parseRoutesFile "config/routes")
-- Please see the documentation for the Yesod typeclass. There are a number -- Please see the documentation for the Yesod typeclass. There are a number
-- of settings which can be configured by overriding methods here. -- of settings which can be configured by overriding methods here.

View File

@ -71,7 +71,7 @@ type Widget = GWidget ~sitearg~ ~sitearg~
-- for our application to be in scope. However, the handler functions -- for our application to be in scope. However, the handler functions
-- usually require access to the ~sitearg~Route datatype. Therefore, we -- usually require access to the ~sitearg~Route datatype. Therefore, we
-- split these actions into two functions and place them in separate files. -- split these actions into two functions and place them in separate files.
mkYesodData "~sitearg~" $(parseRoutesFile "routes") mkYesodData "~sitearg~" $(parseRoutesFile "config/routes")
-- Please see the documentation for the Yesod typeclass. There are a number -- Please see the documentation for the Yesod typeclass. There are a number
-- of settings which can be configured by overriding methods here. -- of settings which can be configured by overriding methods here.