gpt4 book ai didi

haskell - 快照框架 : Compiled splices and processing forms with digestive functors

转载 作者:行者123 更新时间:2023-12-04 20:46:51 26 4
gpt4 key购买 nike

我试图了解编译的拼接以及如何将它们与消化仿函数形式一起使用。有人有任何代码示例吗?

最佳答案

以下工作用于处理已编译拼接中的表格...

bookFormSplice :: C.Splice (Handler App App)
bookFormSplice = formSplice $ do
(view,result) <- DFS.runForm "bookForm" bookForm -- runForm is in Text.Digestive.Snap
case result of Just x -> redirect "/" --valid result, redirect to the home page
--can also insert into DB here
Nothing -> return view --no result or invalid form data,
--return the view and render the form page

附加应用程序、数据、渲染代码...
data Book = Book { title :: T.Text
, description :: T.Text }


bookForm :: Monad m => Form T.Text m Book
bookForm = check "Cannot be blank" notBlank $ Book
<$> "title" .: text (Nothing)
<*> "description" .: text Nothing
where
notBlank (Book t d) = t /= "" && d /= ""




handleNewBook :: Handler App App ()
handleNewBook = cRender "newBook"



routes :: [(ByteString, Handler App App ())]
routes = [ ("/login", with auth handleLoginSubmit)
, ("/logout", with auth handleLogout)
, ("/new_user", with auth handleNewUser)
, ("/newBook", handleNewBook)
, ("", serveDirectory "static")
]


app :: SnapletInit App App
app = makeSnaplet "app" "An snaplet example application." Nothing $ do
h <- nestSnaplet "" heist $ heistInit "templates"
s <- nestSnaplet "sess" sess $
initCookieSessionManager "site_key.txt" "sess" (Just 3600)
a <- nestSnaplet "auth" auth $
initJsonFileAuthManager defAuthSettings sess "users.json"

let config = mempty { hcCompiledSplices = [("bookForm", bookFormSplice)]}
addConfig h config
addRoutes routes
addAuthSplices auth
return $ App h s a

“newBook”模板
New Book Entry:
<br>

<bookForm action="/newBook">

<dfChildErrorList ref="" />

<dfInputText ref="title"/>
<dfInputText ref="description"/>
<dfInputSubmit value="submit"/>
</bookForm>

关于haskell - 快照框架 : Compiled splices and processing forms with digestive functors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16245119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com