diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-01-02 12:49:43 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-01-02 12:49:43 +0100 |
commit | 220e4b484cb460df0e0a0cb50a309788349745b2 (patch) | |
tree | 19df2bfe2c6376b3aaa899eb2fe8e647e7f473a8 /src/Hakyll | |
parent | 2d1225104cb5a050a84bc70916e1aadfff25fb00 (diff) | |
download | hakyll-220e4b484cb460df0e0a0cb50a309788349745b2.tar.gz |
Escaped carries allong it's escaped value
Diffstat (limited to 'src/Hakyll')
-rw-r--r-- | src/Hakyll/Web/Template.hs | 10 | ||||
-rw-r--r-- | src/Hakyll/Web/Template/Internal.hs | 8 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/Hakyll/Web/Template.hs b/src/Hakyll/Web/Template.hs index 586d0b6..b4f2ea5 100644 --- a/src/Hakyll/Web/Template.hs +++ b/src/Hakyll/Web/Template.hs @@ -21,14 +21,18 @@ readTemplate = Template . readTemplate' readTemplate' [] = [] readTemplate' string | "$$" `isPrefixOf` string = - EscapeCharacter : (readTemplate' $ drop 2 string) + let (key, rest) = readIdentifier $ drop 2 string + in Escaped key : readTemplate' rest | "$" `isPrefixOf` string = - let (key, rest) = span isAlphaNum $ drop 1 string + let (key, rest) = readIdentifier $ drop 1 string in Identifier key : readTemplate' rest | otherwise = let (chunk, rest) = break (== '$') string in Chunk chunk : readTemplate' rest + -- Parse an identifier into (identifier, rest) + readIdentifier = span isAlphaNum + -- | Substitutes @$identifiers@ in the given @Template@ by values from the given -- "Page". When a key is not found, it is left as it is. You can specify -- the characters used to replace escaped dollars (@$$@) here. @@ -40,7 +44,7 @@ applyTemplate template page = substitute (Chunk chunk) = chunk substitute (Identifier key) = fromMaybe ('$' : key) $ M.lookup key $ toMap page - substitute (EscapeCharacter) = "$" + substitute (Escaped key) = '$' : key -- | Apply a page as it's own template. This is often very useful to fill in -- certain keys like @$root@ and @$url@. diff --git a/src/Hakyll/Web/Template/Internal.hs b/src/Hakyll/Web/Template/Internal.hs index 43df1db..be10881 100644 --- a/src/Hakyll/Web/Template/Internal.hs +++ b/src/Hakyll/Web/Template/Internal.hs @@ -29,16 +29,16 @@ instance Writable Template where data TemplateElement = Chunk String | Identifier String - | EscapeCharacter + | Escaped String deriving (Show, Eq, Typeable) instance Binary TemplateElement where put (Chunk string) = putWord8 0 >> put string put (Identifier key) = putWord8 1 >> put key - put (EscapeCharacter) = putWord8 2 + put (Escaped key) = putWord8 2 >> put key get = getWord8 >>= \tag -> case tag of - 0 -> Chunk <$> get + 0 -> Chunk <$> get 1 -> Identifier <$> get - 2 -> return EscapeCharacter + 2 -> Escaped <$> get _ -> error "Error reading cached template" |