2013-02-10 58 views
1

此代碼與海斯特在0.10.0變化如何使用loadTemplates更新代碼以用於新的Heist API?

main = do 
     Right ts <- loadTemplates "templates" $ 
      bindSplices mySplices defaultHeistState 
     etc.. 

現在我得到的錯誤

testdb.hs:59:33: Not in scope: `defaultHeistState' 

我知道loadTemplates類型簽名已改爲

loadTemplates :: FilePath -> EitherT [String] IO TemplateRepoSource 
之前工作

但是我很難搞清楚如何調整我的舊代碼來使它工作。

回答

1

確定我得到它的這個工作,但我願意這樣做

load baseDir splices = do 
    tmap <- runEitherT $ do 
     templates <- loadTemplates baseDir 
     let hc = HeistConfig mySplices [] [] [] templates 
     initHeist hc 
    either (error . concat) return tmap 

main = do 
     ts <- load "templates" $ bindSplices mySplices 
     renderWithArgs [("test", T.pack "hello world")] ts "index" >>= 
     B.putStr . maybe "Page not found" (toByteString . fst) 
+0

這是正確的做法更優雅的方式。隨着編譯拼接的添加,我們不得不在Heist初始化之前指定要綁定的東西。這就是爲什麼有一個單獨的HeistConfig和initHeist。 – mightybyte 2013-02-11 16:35:19

+0

謝謝maybyte – dan 2013-02-11 16:37:54

+0

如果你能接受你的回答,所以這個問題不會顯示爲沒有答案,那將是很棒的。 – mightybyte 2013-02-11 17:10:12