From fe2e2a0eed1f0cb2cc4b09b144df0a08f66e294a Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sun, 21 Apr 2013 11:24:58 +0300 Subject: [PATCH] Combine CSS/JS yesodweb/yesod#517 --- Foundation.hs | 6 ++++-- Settings/StaticFiles.hs | 16 ++++++++++++++++ .../normalize.lucius => static/css/normalize.css | 0 3 files changed, 20 insertions(+), 2 deletions(-) rename templates/normalize.lucius => static/css/normalize.css (100%) diff --git a/Foundation.hs b/Foundation.hs index 5fa9fea..c9bc7a1 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -81,8 +81,10 @@ instance Yesod App where -- you to use normal widget features in default-layout. pc <- widgetToPageContent $ do - $(widgetFile "normalize") - addStylesheet $ StaticR css_bootstrap_css + $(combineStylesheets 'StaticR + [ css_normalize_css + , css_bootstrap_css + ]) $(widgetFile "default-layout") hamletToRepHtml $(hamletFile "templates/default-layout-wrapper.hamlet") diff --git a/Settings/StaticFiles.hs b/Settings/StaticFiles.hs index 2510795..3791f62 100644 --- a/Settings/StaticFiles.hs +++ b/Settings/StaticFiles.hs @@ -5,6 +5,8 @@ import Yesod.Static import qualified Yesod.Static as Static import Settings (staticDir) import Settings.Development +import Language.Haskell.TH (Q, Exp, Name) +import Data.Default (def) -- | use this to create your static file serving site staticSite :: IO Static.Static @@ -16,3 +18,17 @@ staticSite = if development then Static.staticDevel staticDir -- Warning: any files added to your static directory during run-time can't be -- accessed this way. You'll have to use their FilePath or URL to access them. $(staticFiles Settings.staticDir) + +combineSettings :: CombineSettings +combineSettings = def + +-- The following two functions can be used to combine multiple CSS or JS files +-- at compile time to decrease bandwidth usage. Sample usage (inside a Widget): +-- +-- $(combineStylesheets 'StaticR [style1_css, style2_css]) + +combineStylesheets :: Name -> [Route Static] -> Q Exp +combineStylesheets = combineStylesheets' development combineSettings + +combineScripts :: Name -> [Route Static] -> Q Exp +combineScripts = combineScripts' development combineSettings diff --git a/templates/normalize.lucius b/static/css/normalize.css similarity index 100% rename from templates/normalize.lucius rename to static/css/normalize.css