2014-12-13 77 views
1

要清楚,我只用搶劫興趣,不折斷。我讀通過ocharles的教程(https://ocharles.org.uk/blog/posts/2013-12-11-24-days-of-hackage-heist.html),並努力適應他的第一個例子。這是一個簡單的綁定標籤。我的代碼如下:四處搶劫0.14.0.1工作

-- main.hs 
main :: IO() 
main = billy 

billy :: IO() 
billy = do 
    heistState <- either (error . concat) id <$> 
     (runEitherT $ initHeist myConfig) 
    builder <- maybe (error "oops2") fst $ 
     renderTemplate heistState "billy" 
    toByteStringIO BS.putStr builder 
    BS.putStr "\n" 

myConfig = (set hcNamespace "") $ 
      (set hcInterpretedSplices defaultInterpretedSplices) $ 
      (set hcTemplateLocations [loadTemplates "templates"]) $ 
      emptyHeistConfig 

而且模板我使用:

<bind tag="kiddo">Billy</bind> 
Merry Christmas, <kiddo/>! 

輸出我得到的是這樣的:

<bind tag='kiddo'>Billy</bind>&#10; 
Merry Christmas, <kiddo></kiddo>! 

我看不出爲什麼綁定標籤沒有按沒有工作。其實我已經更新了他的代碼,以使用新的鏡頭風格搶劫配置,而且我知道,這是最近有點介紹了搶劫的命名空間掛羊頭賣狗肉,但我看不出還有什麼需要改變,以得到這個例子的工作。

+0

你能告訴你所有的進口? – ErikR 2014-12-13 16:38:07

回答

1

這是我能得到工作:

{-# LANGUAGE OverloadedStrings #-} 

import qualified Data.ByteString as B 
import Blaze.ByteString.Builder (toByteStringIO) 
import Control.Applicative 
import Control.Monad.Trans.Either (runEitherT) 
import Heist 
import Heist.Compiled (renderTemplate) 
import Control.Lens 

heistConfig = 
    (set hcNamespace "") $ 
    -- (set hcInterpretedSplices defaultInterpretedSplices) $ 
    (set hcLoadTimeSplices defaultLoadTimeSplices) $ 
    (set hcTemplateLocations [loadTemplates "."]) $ 
    emptyHeistConfig 

main = do 
    heistState <- either (error "oops") id <$> 
     (runEitherT $ initHeist heistConfig) 
    builder <- maybe (error "oops") fst $ 
     renderTemplate heistState "billy" 
    toByteStringIO B.putStr builder 

顯然bind是一個加載時間拼接,而不是解釋拼接。