이 내 코드입니다 :Splice는 유니 코드를 지원합니까?
testSplice :: C.Splice Handler
testSplice = return $ C.yieldRuntimeText $ do
return "中文"
그리고 태그에 바인딩 :
splices :: Splices (C.Splice Handler)
splices =
"testSplice" ## testSplice
그리고 layout.tpl에 그것을 사용 :
<meta charset="UTF-8">
<testSplice/>
를 브라우저에 출력 is
내가 뭘 잘못 했니? 지연 죄송합니다
, 나는 잠시 동안 바쁘다 보니, 지금은 다시 와서 내가 질문을 여기에 특정 충분히 @mightybyte 문제가 발생하는 코드는 내가 희망입니다 만들 수 없습니다 생각
test.hs :
{-# LANGUAGE OverloadedStrings #-}
import Snap
import Heist
import qualified Heist.Compiled as C
import Data.Monoid
import Control.Monad.Trans.Either
import Data.Maybe
main :: IO()
main = quickHttpServe site
site :: Snap()
site =
route [("/", testSnap)]
testSnap :: Snap()
testSnap = do
hs <- liftIO $ load "template" splices
let runtime = fromJust $ C.renderTemplate hs "test"
builder <-liftIO (fst runtime)
writeBuilder builder
where
splices :: Splices (C.Splice IO)
splices =
"testSplice" ## testSplice
load :: MonadIO n
=> FilePath
-> Splices (C.Splice n)
-> IO (HeistState n)
load baseDir splices = do
tmap <- runEitherT $ do
let t = loadTemplates baseDir
hc = HeistConfig
defaultInterpretedSplices
defaultLoadTimeSplices
splices
mempty
[t]
initHeist hc
either (error . concat) return tmap
testSplice :: C.Splice IO
testSplice = return $ C.yieldRuntimeText $ do return "中文"
템플릿/test.tpl
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<testSplice/>
</body>
</html>
이 질문 더 지정자를 만들 것
이제 heist-0.13.0.2를 시도했는데 이제는 멋지게 작동합니다. Daniel!
해당 라이브러리의 소스에 대한 링크를 제공해야합니다. 나는 그것에 대해 들어 본 적이 없으며 google/google을 통해 찾을 수 없습니다. – jtobin
강도는 유니 코드를 지원합니다. [my answer here] (http : // stackoverflow.co/questions/18931786/how-to-show-utf8-text-with-snap-and-heist/18965748 # 18965748)를 참조하십시오. – mightybyte
@mightybyte 그러나 yieldRuntimeText는 Blaze.ByteString.Builder.Char8에서 오는 fromText를 사용하지 않습니까? 죄송합니다. 내가 잘못하면, 그 경우에 제 대답을 철회 할 것입니다. – danidiaz