Merge pull request #1691 from dten/absolute-templates-path
Absolute templates path
This commit is contained in:
commit
eb5f7a95cd
@ -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)
|
||||
|
||||
@ -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,11 @@ 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
|
||||
-- @since 1.6.1.0
|
||||
globFilePackage :: String -> String -> Q FilePath
|
||||
globFilePackage = (makeRelativeToProject <$>) . globFile
|
||||
|
||||
data TemplateLanguage = TemplateLanguage
|
||||
{ tlRequiresToWidget :: Bool
|
||||
, tlExtension :: String
|
||||
@ -124,7 +131,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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: yesod
|
||||
version: 1.6.0.2
|
||||
version: 1.6.1.0
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Michael Snoyman <michael@snoyman.com>
|
||||
@ -25,6 +25,7 @@ library
|
||||
, data-default-class
|
||||
, directory
|
||||
, fast-logger
|
||||
, file-embed
|
||||
, monad-logger
|
||||
, shakespeare
|
||||
, streaming-commons
|
||||
|
||||
Loading…
Reference in New Issue
Block a user