From 4280b75ef67a0c2224198ad1b30bd100cc56f7a4 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 14 Jan 2013 10:47:04 +0100 Subject: Append missingField before applying templates This gives better errror messages in some cases --- src/Hakyll/Core/Compiler.hs | 2 +- src/Hakyll/Web/Template.hs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs index ca43201..dcaf2f0 100644 --- a/src/Hakyll/Core/Compiler.hs +++ b/src/Hakyll/Core/Compiler.hs @@ -48,7 +48,7 @@ import qualified Hakyll.Core.Store as Store -------------------------------------------------------------------------------- --- | Get the underlying identifier. Only use this if you know what you're doing. +-- | Get the underlying identifier. getUnderlying :: Compiler Identifier getUnderlying = compilerUnderlying <$> compilerAsk diff --git a/src/Hakyll/Web/Template.hs b/src/Hakyll/Web/Template.hs index 761c3ad..07a8ff3 100644 --- a/src/Hakyll/Web/Template.hs +++ b/src/Hakyll/Web/Template.hs @@ -1,7 +1,7 @@ -- | This module provides means for reading and applying 'Template's. -- --- Templates are tools to convert data (pages) into a string. They are --- perfectly suited for laying out your site. +-- Templates are tools to convert items into a string. They are perfectly suited +-- for laying out your site. -- -- Let's look at an example template: -- @@ -22,9 +22,6 @@ -- > -- > -- --- We can use this template to render a 'Page' which has a body and a @$title$@ --- metadata field. --- -- As you can see, the format is very simple -- @$key$@ is used to render the -- @$key$@ field from the page, everything else is literally copied. If you want -- to literally insert @\"$key$\"@ into your page (for example, when you're @@ -48,6 +45,7 @@ module Hakyll.Web.Template -------------------------------------------------------------------------------- import Control.Monad (forM, liftM) +import Data.Monoid (mappend) import Prelude hiding (id) @@ -74,7 +72,8 @@ applyTemplate :: Template -- ^ Template -> Item a -- ^ Page -> Compiler (Item String) -- ^ Resulting item applyTemplate tpl context item = do - let context' k x = unContext context k x + -- Appending missingField gives better error messages + let context' k x = unContext (context `mappend` missingField) k x body <- applyTemplateWith context' tpl item return $ itemSetBody body item -- cgit v1.2.3