From b73a95c8b6532f23051fe6b12ccbfec18b4ca7f2 Mon Sep 17 00:00:00 2001 From: David Hewson Date: Fri, 7 Aug 2020 13:20:51 +0100 Subject: [PATCH 1/3] globFilePackage which provides absolute globFile paths within package --- yesod/Yesod/Default/Util.hs | 6 ++++++ yesod/yesod.cabal | 1 + 2 files changed, 7 insertions(+) diff --git a/yesod/Yesod/Default/Util.hs b/yesod/Yesod/Default/Util.hs index 1edfcdfe..f0f1ef82 100644 --- a/yesod/Yesod/Default/Util.hs +++ b/yesod/Yesod/Default/Util.hs @@ -5,6 +5,7 @@ module Yesod.Default.Util ( addStaticContentExternal , globFile + , globFilePackage , widgetFileNoReload , widgetFileReload , TemplateLanguage (..) @@ -15,6 +16,7 @@ module Yesod.Default.Util ) where import qualified Data.ByteString.Lazy as L +import Data.FileEmbed (makeRelativeToProject) import Data.Text (Text, pack, unpack) import Yesod.Core -- purposely using complete import so that Haddock will see addStaticContent import Control.Monad (when, unless) @@ -64,6 +66,10 @@ addStaticContentExternal minify hash staticDir toRoute ext' _ content = do globFile :: String -> String -> FilePath globFile kind x = "templates/" ++ x ++ "." ++ kind +-- | `globFile` but returned path is absolute and within the package the Q Exp is evaluated +globFilePackage :: String -> String -> Q FilePath +globFilePackage = (makeRelativeToProject <$>) . globFile + data TemplateLanguage = TemplateLanguage { tlRequiresToWidget :: Bool , tlExtension :: String diff --git a/yesod/yesod.cabal b/yesod/yesod.cabal index 395ba575..aabb3105 100644 --- a/yesod/yesod.cabal +++ b/yesod/yesod.cabal @@ -25,6 +25,7 @@ library , data-default-class , directory , fast-logger + , file-embed , monad-logger , shakespeare , streaming-commons From 8069d42d90bb6b3e42a4304bcc89ac7b8f39c2b2 Mon Sep 17 00:00:00 2001 From: David Hewson Date: Fri, 7 Aug 2020 13:22:55 +0100 Subject: [PATCH 2/3] use globFilePackage in widgetFileReload and widgetFileNoReload this will mean that files can be build from another directory whilst still finding the package's templates --- yesod/Yesod/Default/Util.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod/Yesod/Default/Util.hs b/yesod/Yesod/Default/Util.hs index f0f1ef82..6e3f21a4 100644 --- a/yesod/Yesod/Default/Util.hs +++ b/yesod/Yesod/Default/Util.hs @@ -130,7 +130,7 @@ warnUnlessExists :: Bool -> Bool -- ^ requires toWidget wrap -> String -> (FilePath -> Q Exp) -> Q (Maybe Exp) warnUnlessExists shouldWarn x wrap glob f = do - let fn = globFile glob x + fn <- globFilePackage glob x e <- qRunIO $ doesFileExist fn when (shouldWarn && not e) $ qRunIO $ putStrLn $ "widget file not found: " ++ fn if e From 8585893b1db3f900b1df861bc64f60982dd0ee74 Mon Sep 17 00:00:00 2001 From: David Hewson Date: Fri, 7 Aug 2020 13:29:29 +0100 Subject: [PATCH 3/3] bump yesod version --- yesod/ChangeLog.md | 4 ++++ yesod/Yesod/Default/Util.hs | 1 + yesod/yesod.cabal | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/yesod/ChangeLog.md b/yesod/ChangeLog.md index a55f556c..42a429e2 100644 --- a/yesod/ChangeLog.md +++ b/yesod/ChangeLog.md @@ -1,3 +1,7 @@ +## 1.6.1.0 + +* `widgetFileReload` and `widgetFileNoReload` now use absolute paths via the new `globFilePackage` Q Exp which can provide absolute templates paths within the project [#1691](https://github.com/yesodweb/yesod/pull/1691) + ## 1.6.0.2 * Replace deprecated decodeFile with decodeFileEither. This should have no semantic impact, but silences a deprecation warning. [#1658](https://github.com/yesodweb/yesod/pull/1658) diff --git a/yesod/Yesod/Default/Util.hs b/yesod/Yesod/Default/Util.hs index 6e3f21a4..e0d6ae1a 100644 --- a/yesod/Yesod/Default/Util.hs +++ b/yesod/Yesod/Default/Util.hs @@ -67,6 +67,7 @@ globFile :: String -> String -> FilePath globFile kind x = "templates/" ++ x ++ "." ++ kind -- | `globFile` but returned path is absolute and within the package the Q Exp is evaluated +-- @since 1.6.1.0 globFilePackage :: String -> String -> Q FilePath globFilePackage = (makeRelativeToProject <$>) . globFile diff --git a/yesod/yesod.cabal b/yesod/yesod.cabal index aabb3105..42e36729 100644 --- a/yesod/yesod.cabal +++ b/yesod/yesod.cabal @@ -1,5 +1,5 @@ name: yesod -version: 1.6.0.2 +version: 1.6.1.0 license: MIT license-file: LICENSE author: Michael Snoyman