[英]Getting heist 0.14.0.1 to work
需要明确的是,我只对使用抢劫感兴趣,而不是对抢劫感兴趣。 我正在阅读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>
Merry Christmas, <kiddo></kiddo>!
我看不到为什么bind标签不起作用。 实际上,我已经更新了他的代码,以使用新的镜头样式的抢劫配置,而且我知道抢劫中最近引入了一些名称空间技巧,但是我看不到要使此示例正常工作还需要更改什么。
这是我能够开始工作的地方:
{-# 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
是加载时间接头,而不是解释的接头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.