2014-12-13 2 views
1

분명히하기 위해, 나는 단지 heist를 사용하는 것에 흥미가있다. 나는 ocharles의 튜토리얼 (https://ocharles.org.uk/blog/posts/2013-12-11-24-days-of-hackage-heist.html)을 읽고 그의 첫번째 예제를 적용하려고합니다. 이것은 단순한 바인드 태그입니다.heist를 얻기 위해서 0.14.0.1 to

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

내가 볼 수없는 이유 바인드 태그 아무튼 다음과 같이 내 코드는 일하지 마라. 실제로 새로운 렌즈 스타일의 heist config를 사용하기 위해 코드를 업데이트했습니다. 최근에 heist에서 소개 된 네임 스페이스 속임수에 대해 알고 있지만이 예제가 작동하려면 다른 것을 변경해야하는지 알 수 없습니다. 여기

+0

수입품을 모두 보여줄 수 있습니까? – ErikR

답변

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은로드 시간 스플 라이스 아닌 해석 스플 라이스입니다.

관련 문제