Skip to content

Commit

Permalink
templateBodyCompiler compiles resource body only
Browse files Browse the repository at this point in the history
and becomes the new default, instead of templateCompiler

fixes jaspervdj#378
  • Loading branch information
bergus committed Oct 24, 2015
1 parent 8dec0a5 commit 5a4ae41
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion data/example/site.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ main = hakyll $ do
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls

match "templates/*" $ compile templateCompiler
match "templates/*" $ compile templateBodyCompiler


--------------------------------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion src/Hakyll/Web/Template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
module Hakyll.Web.Template
( Template
, templateBodyCompiler
, templateCompiler
, applyTemplate
, loadAndApplyTemplate
Expand All @@ -143,7 +144,14 @@ import Hakyll.Web.Template.Internal


--------------------------------------------------------------------------------
-- | Read a template.
-- | Read a template, without metadata header
templateBodyCompiler :: Compiler (Item Template)
templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
item <- getResourceBody
return $ fmap readTemplate item

--------------------------------------------------------------------------------
-- | Read complete file contents as a template
templateCompiler :: Compiler (Item Template)
templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
item <- getResourceString
Expand Down
2 changes: 1 addition & 1 deletion tests/Hakyll/Web/Template/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ case01 = do

out <- resourceString provider "template.html.out"
tpl <- testCompilerDone store provider "template.html" $
templateCompiler
templateBodyCompiler
item <- testCompilerDone store provider "example.md" $
pandocCompiler >>= applyTemplate (itemBody tpl) testContext

Expand Down
4 changes: 2 additions & 2 deletions web/tutorials/04-compilers.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ when the template is applied. If you want an actual dollar sign in the output,
use `$$`.

You usually compile the templates from disk using the aptly named
`templateCompiler`:
`templateBodyCompiler`:

```haskell
match "templates/*" $ compile templateCompiler
match "templates/*" $ compile templateBodyCompiler
```

Notice the lack of `route` here: this is because we don't need to write the
Expand Down

0 comments on commit 5a4ae41

Please sign in to comment.