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 "hamlet"
mkDir "cassius"
mkDir "lucius"
mkDir "julius"
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' (project ++ ".cabal") $ if backendS == "m" then $(codegen "mini-cabal") else $(codegen "cabal")
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' "Handler/Root.hs" $ if backendS == "m" then $(codegen "mini-Root_hs") else $(codegen "Root_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' "StaticFiles.hs" $(codegen "StaticFiles_hs")
writeFile' "config/Settings.hs" $ if backendS == "m" then $(codegen "mini-Settings_hs") else $(codegen "Settings_hs")
writeFile' "config/StaticFiles.hs" $(codegen "StaticFiles_hs")
writeFile' "cassius/default-layout.cassius"
$(codegen "default-layout_cassius")
writeFile' "hamlet/default-layout.hamlet"
$(codegen "default-layout_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' "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
pack <- [|S.pack|]
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
-- very rarely need to modify this.
getFaviconR :: Handler ()
getFaviconR = sendFile "image/x-icon" "favicon.ico"
getFaviconR = sendFile "image/x-icon" "config/favicon.ico"
getRobotsR :: Handler RepPlain
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
-- at:
-- 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
, cassiusFile
, juliusFile
, luciusFile
, widgetFile
, connStr
, ConnectionPool
@ -23,9 +24,10 @@ module Settings
import qualified Text.Hamlet as H
import qualified Text.Cassius as H
import qualified Text.Julius as H
import qualified Text.Lucius as H
import Language.Haskell.TH.Syntax
~importDB~
import Yesod (MonadControlIO, addWidget, addCassius, addJulius)
import Yesod (MonadControlIO, addWidget, addCassius, addJulius, addLucius)
import Data.Monoid (mempty, mappend)
import System.Directory (doesFileExist)
import Data.Text (Text)
@ -104,10 +106,11 @@ connectionCount = 10
-- used; to get the same auto-loading effect, it is recommended that you
-- use the devel server.
toHamletFile, toCassiusFile, toJuliusFile :: String -> FilePath
toHamletFile, toCassiusFile, toJuliusFile, toLuciusFile :: String -> FilePath
toHamletFile x = "hamlet/" ++ x ++ ".hamlet"
toCassiusFile x = "cassius/" ++ x ++ ".cassius"
toJuliusFile x = "julius/" ++ x ++ ".julius"
toLuciusFile x = "lucius/" ++ x ++ ".lucius"
hamletFile :: FilePath -> Q Exp
hamletFile = H.hamletFile . toHamletFile
@ -119,6 +122,13 @@ cassiusFile = H.cassiusFile . toCassiusFile
cassiusFile = H.cassiusFileDebug . toCassiusFile
#endif
luciusFile :: FilePath -> Q Exp
#ifdef PRODUCTION
luciusFile = H.luciusFile . toLuciusFile
#else
luciusFile = H.luciusFileDebug . toLuciusFile
#endif
juliusFile :: FilePath -> Q Exp
#ifdef PRODUCTION
juliusFile = H.juliusFile . toJuliusFile
@ -131,7 +141,8 @@ widgetFile x = do
let h = unlessExists toHamletFile hamletFile
let c = unlessExists toCassiusFile cassiusFile
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
unlessExists tofn f = do
e <- qRunIO $ doesFileExist $ tofn x

View File

@ -26,6 +26,7 @@ library
else
Buildable: False
exposed-modules: Controller
hs-source-dirs: ., config
other-modules: ~sitearg~
Model
Settings
@ -42,7 +43,8 @@ executable ~project~
else
ghc-options: -Wall -threaded
main-is: ~project~.hs
main-is: config/~project~.hs
hs-source-dirs: ., config
build-depends: base >= 4 && < 5
, 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
-- very rarely need to modify this.
getFaviconR :: Handler ()
getFaviconR = sendFile "image/x-icon" "favicon.ico"
getFaviconR = sendFile "image/x-icon" "config/favicon.ico"
getRobotsR :: Handler RepPlain
getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString)

View File

@ -10,6 +10,7 @@ module Settings
( hamletFile
, cassiusFile
, juliusFile
, luciusFile
, widgetFile
, approot
, staticroot
@ -19,8 +20,9 @@ module Settings
import qualified Text.Hamlet as H
import qualified Text.Cassius as H
import qualified Text.Julius as H
import qualified Text.Lucius as H
import Language.Haskell.TH.Syntax
import Yesod.Widget (addWidget, addCassius, addJulius)
import Yesod.Widget (addWidget, addCassius, addJulius, addLucius)
import Data.Monoid (mempty, mappend)
import System.Directory (doesFileExist)
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
-- use the devel server.
toHamletFile, toCassiusFile, toJuliusFile :: String -> FilePath
toHamletFile, toCassiusFile, toJuliusFile, toLuciusFile :: String -> FilePath
toHamletFile x = "hamlet/" ++ x ++ ".hamlet"
toCassiusFile x = "cassius/" ++ x ++ ".cassius"
toJuliusFile x = "julius/" ++ x ++ ".julius"
toLuciusFile x = "lucius/" ++ x ++ ".lucius"
hamletFile :: FilePath -> Q Exp
hamletFile = H.hamletFile . toHamletFile
@ -91,6 +94,13 @@ cassiusFile = H.cassiusFile . toCassiusFile
cassiusFile = H.cassiusFileDebug . toCassiusFile
#endif
luciusFile :: FilePath -> Q Exp
#ifdef PRODUCTION
luciusFile = H.luciusFile . toLuciusFile
#else
luciusFile = H.luciusFileDebug . toLuciusFile
#endif
juliusFile :: FilePath -> Q Exp
#ifdef PRODUCTION
juliusFile = H.juliusFile . toJuliusFile
@ -103,7 +113,8 @@ widgetFile x = do
let h = unlessExists toHamletFile hamletFile
let c = unlessExists toCassiusFile cassiusFile
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
unlessExists tofn f = do
e <- qRunIO $ doesFileExist $ tofn x

View File

@ -26,6 +26,7 @@ library
else
Buildable: False
exposed-modules: Controller
hs-source-dirs: ., config
other-modules: ~sitearg~
Settings
StaticFiles
@ -41,7 +42,8 @@ executable ~project~
else
ghc-options: -Wall -threaded
main-is: ~project~.hs
main-is: config/~project~.hs
hs-source-dirs: ., config
build-depends: base >= 4 && < 5
, 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
-- usually require access to the ~sitearg~Route datatype. Therefore, we
-- 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
-- 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
-- usually require access to the ~sitearg~Route datatype. Therefore, we
-- 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
-- of settings which can be configured by overriding methods here.