For trimming
This commit is contained in:
parent
6c0be2e2d3
commit
6e14d33a10
2 changed files with 31 additions and 9 deletions
|
@ -141,7 +141,7 @@ template :: P.Parser Template
|
||||||
template = mconcat <$> P.many (P.choice [ lift chunk
|
template = mconcat <$> P.many (P.choice [ lift chunk
|
||||||
, lift escaped
|
, lift escaped
|
||||||
, conditional
|
, conditional
|
||||||
, lift for
|
, for
|
||||||
, lift partial
|
, lift partial
|
||||||
, lift expr
|
, lift expr
|
||||||
])
|
])
|
||||||
|
@ -222,15 +222,27 @@ conditional = P.try $ do
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
for :: P.Parser TemplateElement
|
for :: P.Parser Template
|
||||||
for = P.try $ do
|
for = P.try $ do
|
||||||
void $ P.string "$for("
|
trimLFor <- trimOpen
|
||||||
|
void $ P.string "for("
|
||||||
e <- expr'
|
e <- expr'
|
||||||
void $ P.string ")$"
|
void $ P.char ')'
|
||||||
|
trimRFor <- trimClose
|
||||||
|
|
||||||
body <- template
|
body <- template
|
||||||
sep <- P.optionMaybe $ P.try (P.string "$sep$") >> template
|
sep <- P.optionMaybe $ P.try (P.string "$sep$") >> template
|
||||||
void $ P.string "$endfor$"
|
|
||||||
return $ For e body sep
|
trimLEnd <- trimOpen
|
||||||
|
void $ P.string "endfor"
|
||||||
|
trimREnd <- trimClose
|
||||||
|
|
||||||
|
pure $ Template $ mconcat [ [TrimL | trimLFor]
|
||||||
|
, [TrimR | trimRFor]
|
||||||
|
, [For e body sep]
|
||||||
|
, [TrimL | trimLEnd]
|
||||||
|
, [TrimR | trimREnd]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
|
@ -6,7 +6,6 @@ module Hakyll.Web.Template.Tests
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
import Data.Monoid (mconcat)
|
|
||||||
import Test.Framework (Test, testGroup)
|
import Test.Framework (Test, testGroup)
|
||||||
import Test.Framework.Providers.HUnit (testCase)
|
import Test.Framework.Providers.HUnit (testCase)
|
||||||
import Test.HUnit (Assertion, (@=?), (@?=))
|
import Test.HUnit (Assertion, (@=?), (@?=))
|
||||||
|
@ -58,6 +57,17 @@ tests = testGroup "Hakyll.Core.Template.Tests" $ concat
|
||||||
, TrimR
|
, TrimR
|
||||||
]
|
]
|
||||||
@=? readTemplate "$-if(body)-$\n$body$\n$-else-$\n$body$\n$-endif-$"
|
@=? readTemplate "$-if(body)-$\n$body$\n$-else-$\n$body$\n$-endif-$"
|
||||||
|
-- 'For' trim check.
|
||||||
|
, Template
|
||||||
|
[ TrimL
|
||||||
|
, TrimR
|
||||||
|
, For (Ident (TemplateKey "authors"))
|
||||||
|
(Template [Chunk "\n body \n"])
|
||||||
|
Nothing
|
||||||
|
, TrimL
|
||||||
|
, TrimR
|
||||||
|
]
|
||||||
|
@=? readTemplate "$-for(authors)-$\n body \n$-endfor-$"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue