[英]Heist example not working: ‘hcCompiledSplices’ is not a record selector
我试图理解如何使用Heist,但我发现的任何一个例子似乎都没有用,而且我似乎找不到其他任何与我有同样问题的人。 我在这里找到了一些示例代码:
但是,当我尝试运行第一个示例时,我收到以下错误:
Main.hs:20:15:
‘hcCompiledSplices’ is not a record selector
In the expression:
mempty
{hcCompiledSplices = "foo" ## splice,
hcTemplateLocations = [loadTemplates "."]}
In an equation for ‘heistConfig’:
heistConfig
= mempty
{hcCompiledSplices = "foo" ## splice,
hcTemplateLocations = [loadTemplates "."]}
In the expression:
do { let heistConfig = ...;
heistState <- either (error "oops") id
<$> (runEitherT $ initHeist heistConfig);
builder <- maybe (error "oops") fst
$ renderTemplate heistState "simple";
toByteStringIO B.putStr builder }
Main.hs:22:15:
‘hcTemplateLocations’ is not a record selector
In the expression:
mempty
{hcCompiledSplices = "foo" ## splice,
hcTemplateLocations = [loadTemplates "."]}
In an equation for ‘heistConfig’:
heistConfig
= mempty
{hcCompiledSplices = "foo" ## splice,
hcTemplateLocations = [loadTemplates "."]}
In the expression:
do { let heistConfig = ...;
heistState <- either (error "oops") id
<$> (runEitherT $ initHeist heistConfig);
builder <- maybe (error "oops") fst
$ renderTemplate heistState "simple";
toByteStringIO B.putStr builder }
我究竟做错了什么?
使用镜头似乎是现在做事的方式。
另外,我更改模板simple.tpl
以使用标签<h:foo>...</h:foo>
而不仅仅是<foo>...</foo>
。
{-# LANGUAGE OverloadedStrings #-}
module Lib2 where
-- import Data.Monoid
import qualified Data.Text as T
import qualified Data.ByteString as B
import Blaze.ByteString.Builder
import Control.Monad
import Control.Monad.IO.Class
import Control.Applicative
import Control.Monad.Trans.Either
import Heist
import Heist.Compiled as C
import Control.Lens
runtime :: RuntimeSplice IO T.Text
runtime = liftIO $ do
putStrLn "Write something:"
T.pack <$> getLine
splice :: Splice IO
splice = return $ C.yieldRuntimeText $ runtime
main = do
let heistConfig = emptyHeistConfig
& hcTemplateLocations .~ [ loadTemplates "." ]
& hcCompiledSplices .~ ( "foo" ## splice )
reportErrors errs = error ("errors: " ++ unlines errs)
heistState <- either reportErrors id <$>
(runEitherT $ initHeist heistConfig)
builder <- maybe (error "oops") fst $
renderTemplate heistState "simple"
toByteStringIO B.putStr builder
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.