From 22200b910b99be538245ab700012740e5c1ae8a1 Mon Sep 17 00:00:00 2001 From: Greg Weber Date: Sun, 26 Feb 2012 15:31:03 -0800 Subject: [PATCH] add widgetFileJsCss for exact cs/js specification I can set it to coffeescript. widgetFile = Yesod.Default.Util.widgetFileJsCss $ globFile ("coffee", coffeeFileReload) ("cassius", cassiusFileReload) Should we put code like this as the scaffold default? Obviously, we can keep it defaulted to "julius" --- yesod-default/Yesod/Default/Util.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/yesod-default/Yesod/Default/Util.hs b/yesod-default/Yesod/Default/Util.hs index fd3c4614..1b7bbe87 100644 --- a/yesod-default/Yesod/Default/Util.hs +++ b/yesod-default/Yesod/Default/Util.hs @@ -7,6 +7,7 @@ module Yesod.Default.Util , globFile , widgetFileNoReload , widgetFileReload + , widgetFileJsCss ) where import Control.Monad.IO.Class (liftIO) @@ -72,8 +73,21 @@ widgetFileReload x = do let l = whenExists x "lucius" luciusFileReload [|$h >> addCassius $c >> addJulius $j >> addLucius $l|] +widgetFileJsCss :: (String, FilePath -> Q Exp) -- ^ Css file extenstion and loading function. example: ("cassius", cassiusFileReload) + -> (String, FilePath -> Q Exp) -- ^ Css file extenstion and loading function. example: ("julius", juliusFileReload) + -> FilePath -> Q Exp +widgetFileJsCss (jsExt, jsLoad) (csExt, csLoad) x = do + let h = whenExists x "hamlet" whamletFile + let c = whenExists x csExt csLoad + let j = whenExists x jsExt jsLoad + [|$h >> addCassius $c >> addJulius $j|] + whenExists :: String -> String -> (FilePath -> Q Exp) -> Q Exp -whenExists x glob f = do +whenExists = warnUnlessExists False + +warnUnlessExists :: Bool -> String -> String -> (FilePath -> Q Exp) -> Q Exp +warnUnlessExists shouldWarn x glob f = do let fn = globFile glob x e <- qRunIO $ doesFileExist fn + unless (shouldWarn && e) $ qRunIO $ putStrLn $ "widget file not found: " ++ fn if e then f fn else [|mempty|]