@@ -1,8 +1,10 @@
1−module Text.Hakyll.Template
1+module Text.Hakyll.Internal.Template
3 , fromString
3 , fromString
4 , readTemplate
4 , readTemplate
5 , substitute
5 , substitute
8import qualified Data.Map as M
10import qualified Data.Map as M
@@ -46,9 +48,9 @@ readTemplate path = do
47 fileName = "templates" </> path
49 fileName = "templates" </> path
49−-- | Substitutes @$identifiers@ in the given string by values from the given
51+-- | Substitutes @$identifiers@ in the given "Template" by values from the given
50−-- "Context". When a key is not found, it is left as it is. You can here
52+-- "Context". When a key is not found, it is left as it is. You can specify
51−-- specify the characters used to replace escaped dollars (@$$@).
53+-- the characters used to replace escaped dollars (@$$@) here.
52substitute :: String -> Template -> Context -> String
54substitute :: String -> Template -> Context -> String
53substitute escaper (Chunk chunk template) context =
55substitute escaper (Chunk chunk template) context =
54 chunk ++ substitute escaper template context
56 chunk ++ substitute escaper template context
@@ -59,6 +61,16 @@ substitute escaper (Identifier key template) context =
59substitute escaper (EscapeCharacter template) context =
61substitute escaper (EscapeCharacter template) context =
60 escaper ++ substitute escaper template context
62 escaper ++ substitute escaper template context
61substitute _ End _ = []
63substitute _ End _ = []
65+-- | "substitute" for use during a chain. This will leave escaped characters as
67+regularSubstitute :: Template -> Context -> String
68+regularSubstitute = substitute "$$"
70+-- | "substitute" for the end of a chain (just before writing). This renders
71+-- escaped characters.
72+finalSubstitute :: Template -> Context -> String
73+finalSubstitute = substitute "$"
63instance Binary Template where
75instance Binary Template where
64 put (Chunk string template) = put (0 :: Word8) >> put string >> put template
76 put (Chunk string template) = put (0 :: Word8) >> put string >> put template