on master help sign in
Append missingField before applying templates

This gives better errror messages in some cases

commit4280b75ef67a0c2224198ad1b30bd100cc56f7a4 authorJasper Van der Jeugt <m@jaspervdj.be> dateMon 14 Jan 2013, 10:47 (14 years ago) parent82a725b
2 files changed+6−7
src/Hakyll/Core/Compiler.hs+1−1 src/Hakyll/Web/Template.hs+5−6
src/Hakyll/Core/Compiler.hs+1−1
@@ -48,7 +48,7 @@ import qualified Hakyll.Core.Store as Store
4848
4949
5050--------------------------------------------------------------------------------
51−-- | Get the underlying identifier. Only use this if you know what you're doing.
51+-- | Get the underlying identifier.
5252getUnderlying :: Compiler Identifier
5353getUnderlying = compilerUnderlying <$> compilerAsk
5454
src/Hakyll/Web/Template.hs+5−6
@@ -1,7 +1,7 @@
11-- | This module provides means for reading and applying 'Template's.
22--
3−-- Templates are tools to convert data (pages) into a string. They are
4−-- perfectly suited for laying out your site.
3+-- Templates are tools to convert items into a string. They are perfectly suited
4+-- for laying out your site.
55--
66-- Let's look at an example template:
77--
@@ -22,9 +22,6 @@
2222-- > </body>
2323-- > </html>
2424--
25−-- We can use this template to render a 'Page' which has a body and a @$title$@
26−-- metadata field.
27−--
2825-- As you can see, the format is very simple -- @$key$@ is used to render the
2926-- @$key$@ field from the page, everything else is literally copied. If you want
3027-- to literally insert @\"$key$\"@ into your page (for example, when you're
@@ -48,6 +45,7 @@ module Hakyll.Web.Template
4845
4946--------------------------------------------------------------------------------
5047import Control.Monad (forM, liftM)
48+import Data.Monoid (mappend)
5149import Prelude hiding (id)
5250
5351
@@ -74,7 +72,8 @@ applyTemplate :: Template -- ^ Template
7472 -> Item a -- ^ Page
7573 -> Compiler (Item String) -- ^ Resulting item
7674applyTemplate tpl context item = do
77− let context' k x = unContext context k x
75+ -- Appending missingField gives better error messages
76+ let context' k x = unContext (context `mappend` missingField) k x
7877 body <- applyTemplateWith context' tpl item
7978 return $ itemSetBody body item
8079