@@ -1,46 +1,19 @@
11module Hakyll.Web.Template
22 ( Template
3− , readTemplate
43 , applyTemplate
54 , applySelf
65 ) where
76
8−import Data.List (isPrefixOf)
9−import Data.Char (isAlphaNum)
107import Data.Maybe (fromMaybe)
118import qualified Data.Map as M
129
1310import Hakyll.Web.Template.Internal
11+import Hakyll.Web.Template.Read.Hakyll (readTemplate)
1412import Hakyll.Web.Page
1513
16−-- | Construct a @Template@ from a string.
17−--
18−readTemplate :: String -> Template
19−readTemplate = Template . readTemplate'
20− where
21− readTemplate' [] = []
22− readTemplate' string
23− | "$$" `isPrefixOf` string =
24− Escaped : readTemplate' (drop 2 string)
25− | "$" `isPrefixOf` string =
26− case readIdentifier (drop 1 string) of
27− Just (key, rest) -> Identifier key : readTemplate' rest
28− Nothing -> Chunk "$" : readTemplate' (drop 1 string)
29− | otherwise =
30− let (chunk, rest) = break (== '$') string
31− in Chunk chunk : readTemplate' rest
32−
33− -- Parse an identifier into (identifier, rest) if it's valid, and return
34− -- Nothing otherwise
35− readIdentifier string =
36− let (identifier, rest) = span isAlphaNum string
37− in if not (null identifier) && "$" `isPrefixOf` rest
38− then Just (identifier, drop 1 rest)
39− else Nothing
40−
4114-- | Substitutes @$identifiers@ in the given @Template@ by values from the given
42−-- "Page". When a key is not found, it is left as it is. You can specify
43−-- the characters used to replace escaped dollars (@$$@) here.
15+-- "Page". When a key is not found, it is left as it is. You can specify
16+-- the characters used to replace escaped dollars (@$$@) here.
4417--
4518applyTemplate :: Template -> Page String -> Page String
4619applyTemplate template page =