1

需要明确的是,我只对使用抢劫感兴趣,而不是快照。我正在阅读 ocharles 的教程(https://ocharles.org.uk/blog/posts/2013-12-11-24-days-of-hackage-heist.html)并尝试修改他的第一个示例。这是一个简单的绑定标签。我的代码如下:

-- 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>!

我看不出为什么绑定标签不起作用。实际上,我已经更新了他的代码以使用新的镜头式抢劫配置,并且我知道最近在抢劫中引入的命名空间诡计,但我看不出还有什么需要更改才能使这个示例正常工作。

4

1 回答 1

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是加载时间拼接,而不是解释拼接。

于 2014-12-14T00:07:29.557 回答