Haskell Snap框架:编译拼接和处理带有函数的表单

Haskell Snap框架:编译拼接和处理带有函数的表单,haskell,haskell-snap-framework,digestive-functors,Haskell,Haskell Snap Framework,Digestive Functors,我试图理解编译后的拼接,以及如何将它们与消化函子形式一起使用。有人有任何代码示例吗?以下是在编译的拼接中处理表单的工作 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

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

以下是在编译的拼接中处理表单的工作

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
bookFormSplice::C.Splice(处理程序应用程序)
bookFormSplice=formSplice$do
(查看,结果)重定向“/”--有效结果,重定向到主页
--也可以在这里插入数据库
Nothing->return view--没有结果或表单数据无效,
--返回视图并呈现表单页面
其他应用程序、数据、渲染代码

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
databook=Book{title::T.Text
,description::T.Text}
bookForm::Monad m=>Form T.Text m Book
bookForm=勾选“不能为空”而非空$Book
“标题”。:文本(无)
“说明”。:无文本
哪里
不空白(书籍t d)=t/=“”&&d/=“”
handleNewBook::Handler应用程序应用程序()
handleNewBook=cRender“newBook”
路由::[(ByteString,Handler应用程序())]
路由=[(“/login”,带有auth handleLoginSubmit)
,(“/logout”,带有auth handleLogout)
,(“/new_user”,带有auth handleNewUser)
,(“/newBook”,handleNewBook)
,(“”,serveDirectory“静态”)
]
应用程序::SnapletInit应用程序
app=makeSnaplet“app”“一个snaplet示例应用程序。”无需任何操作

你那里的东西对我来说很好。你有更具体的问题吗?谢谢你。我还没有找到任何与编译拼接一起使用的dig func表单的示例,只是想了解一些如何将它们结合使用并利用效率提高的指导。这是一个很好的示例。也许你可以改变你的问题,让它只是举个例子?然后用这里的代码自己回答,这样它就会显示为已回答的问题。
New Book Entry:
<br>

<bookForm action="/newBook">

<dfChildErrorList ref="" />

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