@@ -1,8 +1,10 @@
1−module Text.Hakyll.Template
1+module Text.Hakyll.Internal.Template
22 ( Template
33 , fromString
44 , readTemplate
55 , substitute
6+ , regularSubstitute
7+ , finalSubstitute
68 ) where
79
810import qualified Data.Map as M
@@ -46,9 +48,9 @@ readTemplate path = do
4648 where
4749 fileName = "templates" </> path
4850
49−-- | Substitutes @$identifiers@ in the given string by values from the given
50−-- "Context". When a key is not found, it is left as it is. You can here
51−-- specify the characters used to replace escaped dollars (@$$@).
51+-- | Substitutes @$identifiers@ in the given "Template" by values from the given
52+-- "Context". When a key is not found, it is left as it is. You can specify
53+-- the characters used to replace escaped dollars (@$$@) here.
5254substitute :: String -> Template -> Context -> String
5355substitute escaper (Chunk chunk template) context =
5456 chunk ++ substitute escaper template context
@@ -59,6 +61,16 @@ substitute escaper (Identifier key template) context =
5961substitute escaper (EscapeCharacter template) context =
6062 escaper ++ substitute escaper template context
6163substitute _ End _ = []
64+
65+-- | "substitute" for use during a chain. This will leave escaped characters as
66+-- they are.
67+regularSubstitute :: Template -> Context -> String
68+regularSubstitute = substitute "$$"
69+
70+-- | "substitute" for the end of a chain (just before writing). This renders
71+-- escaped characters.
72+finalSubstitute :: Template -> Context -> String
73+finalSubstitute = substitute "$"
6274
6375instance Binary Template where
6476 put (Chunk string template) = put (0 :: Word8) >> put string >> put template