我在Yesod项目的首页上找到了这段代码:
import Yesod
data HelloWorld = HelloWorld
mkYesod "HelloWorld" [$parseRoutes|/ Home GET|]
instance Yesod HelloWorld where approot _ = ""
getHome = applyLayout [$hamlet|%h1 Hello World|]
main = toWaiApp HelloWorld >>= basicHandler 3000
Run Code Online (Sandbox Code Playgroud)
使用哪些语言功能[$parseRoutes|/ Home GET|]以及[$hamlet|%h1 Hello World|]使$,|,/和%符号起作用,这些符号的作用是什么?
Haskell包依赖继续是一个问题,但我不知道如何解决这个问题.我的环境:
然后:
我得到了这个:
$ cabal install yesod
cabal: Error: some packages failed to install:
persistent-0.3.1.2 failed during the building phase. The exception was:
ExitFailure 1
yesod-0.6.6 depends on persistent-0.3.1.2 which failed to install.
$ cabal install persistent-0.3.1.2
Resolving dependencies...
cabal: cannot configure blaze-builder-0.2.0.2. It requires text ==0.10.*
For the dependency on text ==0.10.* there are these packages: text-0.10.0.0,
text-0.10.0.1 and text-0.10.0.2. However none of them are available.
text-0.10.0.0 was …Run Code Online (Sandbox Code Playgroud) 我正在使用yesod开发一个haskell web应用程序,我最终想要部署到EC2,有人可以推荐一个AMI,它有一个最近的haskell平台和一个可以从存储库安装的git客户端吗?
我想根据日志级别,主题等更改日志消息输出到终端的颜色.
我发现在Haskell中执行此操作的唯一记录器是xmonad-contrib包的一部分,但我不想依赖它,因为它相当大.
我知道Yesod会记录颜色,但对于我如何使其记录器在Yesod Web应用程序之外工作并不明显.
我查看了hslogger,它看起来与System.Log.Logger非常相似,但似乎都没有开箱即用的颜色支持.
hslogger可以通过自定义扩展LogHandlers,所以可能有人实现了一个有颜色支持?
到目前为止,Haskell的登录是否有其他选择?
编辑:
根据Don Stewart的建议,我实现了一个与hslogger和ansi-c一起使用的自定义日志处理程序,以便允许以颜色登录终端.
我写了一个CRUD应用程序来与JIRA接口.我最终升级了我的haskell环境,因为cabal-dev并没有解决所有问题.结果,我有一些破损,随着我尝试使用任何与JIRA接口的代码时出现此错误.
Spike: HandshakeFailed (Error_Misc "user error (unexpected type received. expecting
handshake and got: Alert [(AlertLevel_Warning,UnrecognizedName)])")
Run Code Online (Sandbox Code Playgroud)
经过一番谷歌搜索后,我认为这与使用tls的tls或http-conduit有关.
我目前正在使用tls-1.1.2,http-conduit-1.8.7.1
之前我正在使用
tls-0.9.11并且http-conduit >= 1.5 && < 1.7(不确定到底哪个旧安装已经消失了.
这是我相信休息时间正在发生的地方
manSettings :: ManagerSettings
manSettings = def { managerCheckCerts = \ _ _ _-> return CertificateUsageAccept }
Run Code Online (Sandbox Code Playgroud)
这就是它过去的样子
manSettings :: ManagerSettings
manSettings = def { managerCheckCerts = \ _ _ -> return CertificateUsageAccept }
Run Code Online (Sandbox Code Playgroud)
这是使用它的代码
initialRequest :: forall (m :: * -> *). URI -> IO (Request m,Manager)
initialRequest uri …Run Code Online (Sandbox Code Playgroud) 我刚刚开始在Haskell和Yesod.为了让我的脚湿透,我将把我在MVC中编写的一个小项目转换为Haskell.我的第一步是确定所有路线.
总而言之,我有8个处理程序来运行这个项目.我的路线文件如下所示:
/activity ActivityR GET
/activity/#String ActivityItemR POST DELETE
/dashboard/month MonthDashboardR GET
/dashboard/year YearDashboardR GET
/calendar CalendarR GET
/events/calendar CalendarEventsR GET
/events/report ReportEventsR GET
/report ReportR GET
Run Code Online (Sandbox Code Playgroud)
我在添加这些路线时所经历的流程如下:
是否有快捷方式或通配符这些处理程序,以便我可以做类似的事情 Import Handler.*
或者是处理多个不同路由的处理程序模块较少的首选方法?
我开始使用Yesod开发一个小项目,这是我第一次使用Haskell做一些真实的事情.这个处理注册表单的代码工作正常:
postRegisterR :: Handler ()
postRegisterR = do email <- runInputPost $ ireq textField "email"
user <- runInputPost $ ireq textField "user"
pwd <- runInputPost $ ireq textField "pwd"
cpwd <- runInputPost $ ireq textField "cpwd"
if pwd == cpwd && isValidEmail email
then do
tryInsert email user pwd
setSession "user" user
redirectUltDest SessionR
else do
redirect HomeR
tryInsert :: Text -> Text -> Text -> Handler ()
tryInsert email user pwd = do pwdbs <- liftIO $ hashedPwd pwd …Run Code Online (Sandbox Code Playgroud) 我目前正在Yesod网络平台上使用Haskell进行开发,我需要在我的一个网页中创建一个表单.此表单必须包含多个复选框,但需要将它们分组到类别中.例如,用户需要在10个复选框,5个项目的列表中选择3个学科,其中最多2个可以是武器.
我在Yesod网站上阅读了本书的部分内容,根据我的理解,我需要创建一个自定义字段来创建分组复选框.不幸的是,我对Haskell并不是很好(刚刚开始使用它1-2周前)而且我很难理解如何实现这一目标.作为参考,这是我在Yesod网站上读到的关于自定义字段的书的页面:http://www.yesodweb.com/book/forms
知道了,我的问题是:如何在Haskell/Yesod中创建分组复选框?
编辑:在我提供的链接中,我理解了Field(fieldView和fieldEnctype)的构造函数的最后两个值,它是第一个(fieldParse),我不知道如何为我的目的进行修改.以下是我引用的链接中的示例:
passwordConfirmField :: Field Handler Text
passwordConfirmField = Field
{ fieldParse = \rawVals _fileVals ->
case rawVals of
[a, b]
| a == b -> return $ Right $ Just a
| otherwise -> return $ Left "Passwords don't match"
[] -> return $ Right Nothing
_ -> return $ Left "You must enter two values"
, fieldView = \idAttr nameAttr otherAttrs eResult isReq ->
[whamlet|
<input id=#{idAttr} name=#{nameAttr} *{otherAttrs} type=password>
<div>Confirm:
<input id=#{idAttr}-confirm …Run Code Online (Sandbox Code Playgroud) 例如,如何使用Yesod应用程序的模型将新用户插入数据库?或者,还有更好的方法?
我正在处理脚手架应用程序.现在我创建了App实例,并且不知道如何使用它来执行请求.
:i Extra
data Extra
= Extra {extraCopyright :: Data.Text.Internal.Text,
extraAnalytics :: Maybe Data.Text.Internal.Text}
-- Defined in `Settings
let e = Extra "asdf" Nothing
let c = AppConfig {appEnv = Development, appPort = 3000, appRoot = "/", appHost = "localhost", appExtra = e}
f <- makeFoundation c
:t f
f :: App
:i App
data App
= App {settings :: AppConfig DefaultEnv Extra,
getStatic :: Yesod.Static.Static,
connPool :: persistent-1.2.3.0:Database.Persist.Class.PersistConfig.PersistConfigPool
PersistConf,
httpManager :: http-client-0.2.0.1:Network.HTTP.Client.Types.Manager,
persistConfig :: PersistConf,
appLogger …Run Code Online (Sandbox Code Playgroud) 我想禁用无头API端点的会话,但我必须保持它们打开,因为此服务还处理用户登录.
但是makeSessionBackend,无法访问Handler东西甚至是当前的URI isAuthorizedSource.
在我看来,我应该提升客户端会话后端代码并将其与包装器一起使用,直到我能从该WAI获得至少文本路径Request.
是不是有更好的方法告诉任何bakend忽略一些路线,如StaticR?