方圆是什么意思| 手脚抽筋吃什么药最好| 什么是善| 八格牙路是什么意思| 蛇什么时候出来活动| 肝风内动是什么意思| 什么是日间手术| 75年属什么生肖| oa期刊是什么意思| 64年出生属什么| 深圳居住证有什么用| 一九六三年属什么生肖| 哭笑不得是什么意思| 地铁站务员是干什么的| 耳道炎用什么药最有效| 嗓子嘶哑吃什么药| 相貌是什么意思| 什么是假性抑郁症| 为什么身上会起小红点| 大便有凹槽是什么原因| 4月11号是什么星座| 弯弯的什么| 哺乳期可以吃什么水果| 地笼捕河虾用什么诱饵| ifu是什么意思| 万宝龙皮带算什么档次| 吃什么可以降低血糖| 高手过招下一句是什么| trust阴性tppa阳性说明什么| 球蛋白是什么意思| 什么水果低糖| 吃什么变白| 腊肉炖什么好吃| 甲申日是什么意思| 为什么会得多囊| 学富五车是什么意思| 吃蛋白粉有什么好处和坏处| 肾虚用什么补最好| 阿尔兹海默症挂什么科| ga是什么激素| 啤酒花是什么| 菠菜什么时候种最合适| 鳞状上皮细胞是什么意思| 吃什么补血小板快| 身心合一是什么意思| qn是什么医嘱| 沙发是什么发质| 怀孕第一个月最怕什么| 下午右眼跳是什么预兆| 吃什么食物下奶快而且奶多| 软科是什么意思| 谢字五行属什么| 粒细胞低是什么原因| 今期难过美人关是什么生肖| 多少年婚姻是什么婚| 中医把脉能看出什么| 肾虚去医院挂什么科| 爱情和面包是什么意思| 有什么好吃的菜| #NAME?| 铅超标有什么症状| 客观原因是什么意思| 青少年长白头发是什么原因| 孕早期吃什么好| 龙是什么意思| 风采是什么意思| 热锅上的蚂蚁是什么意思| 行长是什么级别| 偏财代表什么| 十点多是什么时辰| 腹部胀疼是什么原因| 生殖器疱疹是什么病| 梦见手链断了是什么意思| 宝贝什么意思| 盆底脱垂有什么症状| 小学生什么时候放暑假| 赵子龙属什么生肖| 尿糖弱阳性是什么意思| 瑞舒伐他汀钙片治什么病| 左卵巢囊性回声什么意思| 郎才女貌是什么意思| 眼角痒是什么原因| 多是什么结构的字| 菊花茶泡了为什么会变绿| 桑葚补什么| 成字五行属什么| 梦见动物是什么意思| 高锰酸钾是什么颜色| 白羊座男和什么星座最配| 身份证号后四位代表什么| 自作多情是什么意思| 胆固醇偏高是什么原因| 剂型是什么意思| 梦到甘蔗代表什么预兆| 甲胎蛋白增高说明什么| 马华念什么| 前庭功能障碍是什么病| 什么动物三只爪| 冷落是什么意思| 榛子是什么树的果实| 鱼油有什么功效和作用| 9月1号什么星座| 耳朵发热是什么预兆| 一凉就咳嗽是什么原因| 怀孕肚子疼是什么原因| 螃蟹为什么吐泡泡| 处女座属于什么星象| 鸡眼用什么药好| 碘伏是什么颜色| 呵是什么意思| 梦见自己鞋子破了是什么意思| 刘备的儿子叫什么| 白介素8升高说明什么| 孕妇吃什么长胎不长肉| 黑素瘤早期什么症状| 怀孕哭对宝宝有什么影响| 胃寒吃什么| 阁老相当于现在什么官| 献血有什么坏处| 出虚汗吃什么药| 申的五行属什么| 相濡以沫是什么意思| 海笋是什么东西| 男性乳头疼是什么原因| 洗衣粉和洗衣液有什么区别| 什么淀粉最好| 为什么叫五十肩| 什么时候看到的月亮最大| 金黄的什么| 下肢静脉血栓吃什么药| 鹞是什么意思| 植物神经紊乱挂什么科| daily是什么意思| 皮夹克是什么意思| 芭蕉花炖猪心治什么病| 10月20是什么星座| 什么t恤质量好| 什么炖鸡好吃| 脑梗吃什么药效果好| 肩膀痛应该挂什么科| 十万为什么| simon什么意思| 12月16是什么星座| 冬虫夏草是什么东西| 杞人忧天告诉我们什么道理| 左眼皮跳是什么意思| 脸为什么容易红| 清清什么| 西瓜禁忌和什么一起吃| 吃什么保肝护肝| 白介素高是什么原因| 歌姬是什么意思| hpv去医院挂什么科| 喝完酒头疼吃什么药| 才高八斗是什么生肖| 自然流产是什么症状| 婕字五行属什么| 便宜的反义词是什么| 牙龈肿了吃什么消炎药| 门庭冷落是什么意思| wonderland是什么意思| 磷高有什么症状和危害| 尿酸高是什么原因导致的| tga是什么意思| 伤官代表什么| 伤春悲秋什么意思| bf什么意思| 丘疹是什么原因引起的| 吃什么药能让月经马上来| 拜阿司匹林和阿司匹林有什么区别| 朝野是什么意思| hl代表什么| 如如不动是什么意思| 前列腺吃什么药好| 乳腺增生不能吃什么食物| 康什么大道| 流产了有什么症状| 连襟是什么意思| 土生金是什么意思| 什么是代谢| 痢疾吃什么药| 满满的回忆什么意思| 神经官能症挂什么科| 为什么不呢| pp和pc材质有什么区别| 什么叫邪淫| 丝瓜为什么会变黑| 胃不好吃什么水果好| 求欢是什么意思| 生理盐水敷脸有什么效果| 甲功是查什么的| 本色出演是什么意思| 敏感肌是什么意思| 痛风吃什么肉最好| 银耳长在什么地方| 望穿秋水是什么意思| 什么是喜欢| 狗改不了吃屎是什么意思| 乳酪是什么东西| sap是做什么的| 喝酒后头疼吃什么药| bc是什么意思| 乖乖是什么意思| 湿气重不能吃什么食物| 宫颈炎盆腔炎吃什么药效果最好| 一什么永什么成语| 肝病晚期什么症状| who是什么意思| 咳嗽吃什么食物好| 淋巴细胞百分比低说明什么问题| 脸无缘无故的肿是什么原因| 血管痉挛吃什么药| 吃中药能吃什么水果| 芥末配什么好吃| 好整以暇什么意思| 猫吐是什么原因| 死心眼什么意思| 冶阳萎什么药最有效| 鱼用什么游泳| 什么是有机食品和无机食品| 今晚开什么特马| 阿米巴是什么意思| 口腔疱疹吃什么药| 尿潜血挂什么科| 小腿疼痛挂什么科| 胃病四联疗法是什么药| 什么是埋线双眼皮| jm是什么| 幽门螺杆菌是什么病| 脚气是什么样的图片| 甲状腺功能挂什么科| 什么叫大男子主义| bag是什么意思| 上海副市长什么级别| 今天过生日是什么星座| 姑姑的孙子叫我什么| 甲功四项是什么检查项目| 痛风吃什么消炎药| 糖醋里脊是什么肉做的| 什么是阴阳人| 心跳加速心慌吃什么药| 宝宝经常发烧是什么原因引起的| 空明什么意思| 输卵管造影什么时候检查最好| 火车硬卧代硬座是什么意思| 空调睡眠模式是什么意思| 前列腺挂什么科| 肚子疼看什么科| 腱鞘炎看什么科| 肝ca是什么意思| 西瓜为什么是红色的| 活性酶是什么| 为什么会流产| 黄腔是什么意思| 茯苓长什么样子图片| 上海以前叫什么| 哈西奈德溶液治什么病| 皇帝的新装是什么意思| 鸡内金是什么| 到付是什么意思| 羽军念什么| 什么是腺样体肥大| 化胡为佛是什么意思| 90年是什么命| 百度Jump to content

今起乌鲁木齐地区油价上调 每升将上调0.17元至0.2元

From Wikipedia, the free encyclopedia
Yesod
Original author(s)Michael Snoyman
Developer(s)Michael Snoyman, et al.
Initial release2010; 15 years ago (2010)
Stable release
1.6.24.5[1] Edit this on Wikidata / 14 September 2023; 22 months ago (14 September 2023)
Repository
Written inHaskell
Operating systemCross-platform
Available inEnglish
TypeWeb framework
LicenseMIT
Websitewww.yesodweb.com Edit this at Wikidata
百度 进而对文化产业与中国制造业起到金融助力作用。

Yesod (Hebrew pronunciation: [je?sod]; Hebrew: ??????, "Foundation") is a web framework based on the programming language Haskell for productive development of type-safe, representational state transfer (REST) model based (where uniform resource locators (URLs) identify resources, and Hypertext Transfer Protocol (HTTP) methods identify transitions), high performance web applications, developed by Michael Snoyman, et al. It is free and open-source software released under an MIT License.

Yesod is based on templates, to generate instances for listed entities, and dynamic content process functions, through Template Haskell constructs to host domain-specific language (eDSL) content templates called QuasiQuotes, where the content is translated into code expressions by metaprogramming instructions.[2]

There are also web-like language snippet templates that admit code expression interpolations, making them fully type-checked at compile time.[3]

Yesod divides its functions in separate libraries (database, html rendering, forms, etc.) so functions may used as needed.

MVC architecture

[edit]

Yesod uses the model–view–controller (MVC) software design pattern for its user interfaces.

Controller

[edit]

Server interface

[edit]

Yesod uses a Web application interface (WAI),[4] a type of application programming interface (API), to isolate servlets, aka web apps., from servers, with handlers for the server protocols Common Gateway Interface (CGI),[5] FastCGI,[6] Simple Common Gateway Interface (SCGI),[7] Warp,[8] Launch (open as local URL to the default browser, closing the server when the window is closed),[9]

The foundation type

[edit]

See ref.[10] Yesod requires a data type that instantiates the model–view–controller classes. This is called the foundation type. In the example below, it is named "MyApp".

The REST model identifies a web resource with a web path. Here, REST resources are given names with an R suffix (like "HomeR") and are listed in a parseRoutes site map description template. From this list, route names and dispatch handler names are derived.

Yesod makes use of Template Haskell metaprogramming to generate code from templates at compile time, assuring that the names in the templates match and everything typechecks (e.g. web resource names and handler names).

By inserting a mkYesod call, this will call Template Haskell primitives to generate the code[11] corresponding to the route type members, and the instances of the dispatch controller classes as to dispatch GET calls to route HomeR to a routine named composing them both as "getHomeR", expecting an existing handler that matches the name.

Hello World

[edit]

"Hello, World!" program example based on a Common Gateway Interface (CGI) server interface (the handler types have changed, but the philosophy remains):

{- file wai-cgi-hello.hs -}
{-# LANGUAGE PackageImports, TypeFamilies, QuasiQuotes, MultiParamTypeClasses,
             TemplateHaskell, OverloadedStrings #-}
import "wai" Network.Wai
import "wai-extra" Network.Wai.Handler.CGI (run) -- interchangeable WAI handler

import "yesod" Yesod
import "yesod-core" Yesod.Handler (getRequest)
import "text" Data.Text (Text)
import "shakespeare" Text.Cassius (Color(..), colorBlack)

-- the Foundation type
data MyApp = MyApp

-- sitemap template, listing path, resource name and methods accepted
-- `mkYesod` takes the foundation type name as param. for name composition of dispatch functions
mkYesod "MyApp" [parseRoutes|
/ HomeR GET
|]

instance Yesod MyApp

-- indentation structured CSS template
myStyle :: [Text]  CssUrl url
myStyle paramStyle =
        [cassius|
.box
    border: 1px solid #{boxColor}
|]
        where
          boxColor = case paramStyle of
                        ["high-contrast"]  colorBlack
                        _  Color 0 0 255

-- indentation structured HTML template
myHtml :: [(Text, Text)]  HtmlUrl url
myHtml params = [hamlet|
<!-- indentation, or lack of it, under starting tags or commands ('$' prefix) 
     describe the content or sequence tree structure -->
<!-- '.' or '#' prefixes in tags introduce css styled "class" or "id" attribute values -->
<!-- interpolation of haskell expressions follow the "shakespeare templates" #{expr} syntax -->

<p>Hello World! There are <span .box>#{length params} parameters</span>:
$if null params
    <p>Nothing to list 
$else
    <ul>
         $forall param <- params
             <li>#{fst param}: #{snd param}
|]
getHomeR :: Handler RepHtml
getHomeR = do
        req <- getRequest
        let params = reqGetParams req
        paramStyle <- lookupGetParams "style"
        
        defaultLayout $ do
            -- adding widgets to the Widget monad (a ''Writer'' monad)
            setTitle "Yesod example"
            toWidgetHead $ myStyle paramStyle
            toWidgetBody $ myHtml params

-- there are ''run'' function variants for different WAI handlers

main = toWaiApp MyApp >>= run
# cgi test
export REMOTE_ADDR=127.0.0.1
export REQUEST_METHOD=GET
export PATH_INFO=/
export QUERY_STRING='p1=abc;p2=def;style=high-contrast'
./wai-cgi-hello

[10]

Resources, routes, HTTP method handlers

[edit]

See ref.[12][13] Yesod follows the representational state transfer model of access to web documents, identifying docs. and directories as resources with a Route constructor, named with an uppercase R suffix (for example, HomeR).

The routes table
The parseRoutes template should list the resources specifying route pieces, resource name and dispatch methods to be accepted.

URL segment capture as parameter is possible specifying a '#' prefix for single segment capture or '*' for multisegment capture, followed by the parameter type.

-- given a MyApp foundation type

mkYesod "MyApp" [parseRoutes|
/                     HomeR      -- no http methods stated: all methods accepted
/blog                 BlogR      GET POST

-- the '#' prefix specify the path segment as a route handler parameter
/article/#ArticleId   ArticleR   GET PUT

-- the '*' prefix specify the parameter as a sequence of path pieces
/branch/*Texts        BranchR    GET

-- to simplify the grammar, compound types must use an alias, eg. type Texts for ''[Text]''
|]
  • Applying the previous template generates the following route constructors:
data Route MyApp = 
    HomeR                    -- referenced in templates as: @{HomeR}
    | BlogR                  -- in templates: @{BlogR}
    | ArticleR ArticleId     -- in templates: @{ArticleR myArticleId}
    | BranchR Texts          -- in templates: @{BranchR myBranchSegments}
  • For every supported HTTP method a handler function must be created to match the dispatch names generated by mkYesod from the parseRoutes template, by prefixing the method name (or the prefix "handler" if no method stated) to the resource, as described (actual versions handler types have changed, but the philosophy remains):
-- for "/ HomeR"        -- no http methods stated ? only one handler with prefix ''handler''
handlerHomeR :: HasReps t ? Handler t

-- for "/blog BlogR GET POST"
getBlogR :: HasReps t ? Handler t
postBlogR :: HasReps t ? Handler t

-- for "/article/#ArticleId ArticleR GET PUT"
getArticleR :: HasReps t ? ArticleId  Handler t
putArticleR :: HasReps t ? ArticleId  Handler t

Request data, parameters, cookies, languages, other header info

[edit]

See ref.[12]

Authentication, authorization

[edit]

See ref.[14] Authentication plugins: OpenID, BrowserID, Email, GoogleEmail, HashDB, RpxNow.[15]

There is an important setting for automatic redirection after authentication.[16]

Sessions

[edit]

See ref.[17] Session back-ends: ClientSession[18] (it stores the session in a cookie), ServerSession[19][20] (it stores most of the session data at the server)

>> To avoid undue bandwidth overhead, production sites can serve their static content from a separate domain name to avoid the overhead of transmitting the session cookie for each request
Session messages
[edit]

A success, failure or indicative message can be stored (setMessage) in the Session and will be shown, if it exists, by the default_layout routine through the default_layout.hamlet template, being cleared on consultation.[21]

Subsites

[edit]

Common URL prefix subsites for workflows, file serving or site partitioning. See ref.[22][23]

Built-in subsites: Static,[24][25] Auth[26]

Form processing, layout generation

[edit]

See ref.[27]

The Form type here is an object that is used in the controller to parse and process the form fields user input and produce a (FormResult, Widget) pair were the widget holds the layout of the next rendering of the form with error messages and marks. It can also be used to generate a new form with blanks or default values.

The form type takes the shape of a function of an html snippet to be embedded in the view, that will hold security purpose hidden fields.

A form object is generated from an ApplicativeMonadic composition of fields for a combined, sequential parsing of field inputs.

There are three types of forms:

  • Applicative (with tabular layout),
  • Monadic (with free layout style), both in the Yesod.Form.Functions module,
  • Input (for parsing only, no view generated) in the Yesod.Form.Input module.

The field generators, whose names are composed by the form type initial (a|m|i) followed by (req|opt){- required or optional -}, have a fieldParse component and a fieldView one.[28]

  • the function runForm{Post|Get} runs the field parsers against the form field inputs and generates a (FormResult, Widget) pair from the views offering a new form widget with the received form field values as defaults. The function suffix is the http method used in the form submission.
  • while generateForm{Post|Get} ignores inputs from the client and generates a blank or defaults form widget.[29]

The actual function parameters and types have changed through Yesod versions. Check the Yesod book and libraries signatures.

The magic is in the FormResult data type Applicative instance, where (<*>) collects the error messages for the case of FormFailure [textErrMsg] result values[30]

Monadic forms permit free form layout and better treatment of hiddenField members.[27]

A sample of an Applicative[31] form:

-- a record for our form fields
data Person = Person {personName :: Text, personAge :: Int, personLikings :: Maybe Text}

-- the Form type has an extra parameter for an html snippet to be embedded, containing a CSRF token hidden field for security
type Form sub master x = Html  MForm sub master (FormResult x, Widget)

{-
-- for messages in validation functions:
  @param master: yesod instance to use in renderMessage (return from handler's getYesod)
  @param languages: page languages to use in renderMessage

-- optional defaults record:
  @param mbPersonDefaults: Just defaults_record, or Nothing for blank form
-}

personForm :: MyFoundationType  [Text]  Maybe Person  Form sub master Person
{- ''aopt'' (optional field AForm component) for "Maybe" fields,
   ''areq'' (required fld AForm comp.) will insert the "required" attribute
-}
personForm master languages mbPersonDefaults = renderTable $ 
  Person <$> areq textField            fldSettingsName    mbNameDefault 
         <*> areq customPersonAgeField fldSettingsAge     mbAgeDefault 
         <*> aopt textareaField        fldSettingsLikings mbLikingsDefault 
  where
    mbNameDefault    = fmap personName    mbPersonDefaults
    mbAgeDefault     = fmap personAge     mbPersonDefaults
    mbLikingsDefault = fmap personLikings mbPersonDefaults

    -- "fieldSettingsLabel" returns an initial fieldSettings record
    -- recently the "FieldSettings" record can be defined from a String label since it implements IsString
    fldSettingsName = (fieldSettingsLabel MsgName) {fsAttrs = [("maxlength","20")]}
    fldSettingsAge = fieldSettingsLabel MsgAge
    fldSettingsLikings = (fieldSettingsLabel MsgLikings) {fsAttrs = [("cols","40"),("rows","10")]}

    customPersonAgeField = check validateAge intField

    validateAge y
        | y < 18    = Left $ renderMessage master languages MsgUnderAge
        | otherwise = Right y

View

[edit]

The types shown correspond to an older version, but the philosophy remains.

The Handler monad returns content in one or more of several formats as components of types that implement the HasReps class[32] {RepHtml, RepJson, RepXml, RepPlain, the dual RepHtmlJson, a pair or list of pairs [(ContentType, Content)], ..}.[33][34] Json examples:[35][36][37]

The HasReps default implementation of chooseRep chooses the document representation to be returned according to the preferred content-type list of the client accept header.[32]

  • Widgets[38] are HTML DOM code snippets made by specific commands (e.g. setTitle) or from templates of structure (HTML) / behaviour (JavaScript) / style (CSS), whose types instantiate the classes ToWidget, ToWidgetHead or ToWidgetBody.

A Widget monad,[39] based on a Writer[40] one and argument to defaultLayout, facilitate to piece the widgets together.

Indentation based templates for tree structured markup

[edit]

'$' prefixes lines of logic statements.

Automatic closing tags are generated only for the tag at line start position.

  • the whamlet quasiquoter returns a Widget expression. (saves to Widget before [hamlet|..|]).
toWidget [hamlet|
$doctype 5
<html>
    <!-- only the tag at the beginning of the line will be automatically closed -->
    <!-- '.' or '#' prefixes in tags introduce class/id names, à la CSS -->
    <!-- ":boolVar:" prefix in attributes makes them conditionally generated -->
    <!-- interpolation of haskell expressions follow the "shakespearean templates"
         syntax introduced in the so named section -->

    <head>
        <title>#{pageTitle} - My Site
        <link rel=stylesheet href=@{Stylesheet_route}>
    <body>
        <header>
           ^{headerTemplate}
        <section #mySectionId>
          <p><span .titleClass>_{MsgArticleListTitle}</span>
          $if null articles
            <p :isRed:style="color:red">_{MsgSorryNoArticles}
          $else
            <ul>
                $forall art <- articles
                    <li>#{articleNumber art} .- #{articleTitle art}
        <footer>
          ^{footerTemplate}
|]
Template interpolation - Shakespearean templates
[edit]

See ref.[42] These are content view templates that follow a common substitution pattern of code expressions within curly brackets with different character prefix to refer to

template expressions with ^{...}
refers to other templates of the same type, with given parameters as ^{template params},
route expressions with @{...}
safe (typed) urls as @{HomeR},
message expressions with _{...}
i18n message rendering as _{MsgMessageLabel params}
other Haskell expressions with #{...}
haskell expression rendering as #{haskell_expression} which type must be convertible
    • in case of hamlet html templates, the expression type must be an instance of Text.Blaze.ToMarkup[44]
    • in case of CSS templates, the expression type must be an instance of Text.Cassius.ToCss[45]
    • in case of JavaScript templates, the expression type must be an instance of Text.Julius.ToJavascript [46]
    • in case of i18n message definitions (in "<isoLanguage>.msg" files) with parameter interpolations, the expression type must be an instance of Text.Shakespeare.I18N.ToMessage [47]
    • in case of text/plain templates (for use in emails), the expression type must be an instance of Text.Shakespeare.Text.ToText [48]

Using non-English text in expressions requires use of the Unicode-aware type Text, since the Glasgow Haskell Compiler's (GHC's) show for the type String renders non-ASCII characters as escaped numerical codes.

External file templates
  • at compile time: Template content can be loaded from external files using compile time splice calls as $(expr).[49]
  • at run time: There is a reload mode for reparsing external template files at every service call, except for HTML hamlet templates: See doc.[50]
Other templates
[edit]
for JavaScript, CoffeeScript, Roy
the julius quasiquoter: introduces a JavaScript template.[51] JavaScript variants CoffeeScript and Roy-language[52] have also specific quasiquoters.[2][51]
for CSS
  • the cassius quasiquoter: introduces a css template with indentation based structuring.[53]
  • the lucius quasiquoter: introduces a css template with standard syntax plus shakespeare-template style substitutions.[54]
TypeScript and JSX templates
the tsc and tscJSX quasiquoters. Only on UNIX derivatives (no Windows by now).[55]
text/plain templates
for e-mail or text/plain http content type.[56]
  1. templates: lt: lazy text, st: strict text
  2. templates for text with a left margin delimiter '|': lbt (lazy), sbt (strict)

Localizable messages

[edit]

See ref.[57]

Yesod app messages are localizable (i18n). They should be held within the messages folder, in files named based on ISO, as <iso-language>.msg

Message entries follow the EBNF pattern:

-- EBNF: identifier, {' ', parameter, '@', type}, ":", text with interpolations
ArticleUnexistent param@Int64 : unexistent article #{param}
  • message constructors are formed prepending "Msg" to the message label identifier.
  • the message datatype is formed appending "Message" to the foundation type name.
-- in code
myMsg :: MyAppMessage  -- datatype appending "Message" to the foundation type
myMsg = MsgArticleUnexistent myArticleId  -- constructor prepending "Msg" to the msg. label

-- in widget templates
  _{MsgArticleUnexistent myArticleId}

Actual i18n support is missing from the stack app template. The mkMessage "MyApp" messagesFolder isoLangDefault must be added to the "Foundation.hs" file to get the messages instantiated.[58]

[edit]
  • Navigation breadcrumbs.[59] A YesodBreadcrumbs instance must be provided for the site where the generator function breadcrumb should return for each route a title and parent one. Then, the query function breadcrumbs will return the present route title and the ancestors' (route, title) pairs.

Search engine XML Sitemap

[edit]
  • Search engines XML Sitemaps,[60] where sitemap returns an XML Sitemap as http response, with the routes we want the search engines to crawl, and attributes to instruct the crawler, from a provided list of SitemapUrl records.

Web feed views

[edit]
  • Web feed views (RDF Site Summary (RSS) – Atom).[61] Handlers return RepRss, RepAtom, or dual RepAtomRss content (to be selected on accept headers' preferred content-type list) from a given Feed structure.

Model

[edit]

Using in-memory mutable data (in the foundation datatype)

[edit]

E.g. a visitor count. See ref.[62]

The Database layer

[edit]
  • persistent is the name of the database access layer with templates for generating types for entities and keys as well as schema initialization.[63][64][65]

There is first class support for PostgreSQL, SQLite, MongoDB, CouchDB and MySQL, with experimental support for Redis.[63]

The Database layout is described in a template listing the entities, fields and constraints.[66]

  • For every entity listed, an integer key column "id" is generated with autoincrement and primary index attributes, with a type alias appending Id to the entity name
  • For every entity listed, a record type named as the entity is generated were record fields names are composed prefixing the entity name to the field name like "personName". An EntityField type "PersonName" is also generated for foreign key referencing from other entities.
  • There is an automatic database schema migration mechanism for DB schema updates, which, to succeed, requires, when adding columns to existent tables, to specify 'Default-column-value constraints with sql level notation.[67]
  • "At most one" cardinality has a special mechanism around the type Checkmark.[68]
  • Weak entities (childs in life constrained owner-child relationships) have no special support for cascade delete triggers, but there are functions to deleteCascade manually in the Database.Persist.Class module.[69]
automatic table creation, schema update and table migration
Modifications of the entities template produces an schema update with automatic table creation, and migration for the DBMS's that support "ALTER TABLE" SQL commands in a migrateAll procedure, generated from the template content. See "Migrations" in ref.[63] to look for migration aware DBMS.
share [mkPersist sqlSettings,
       mkMigrate "migrateAll"   -- generates the migration procedure with the specified name
       ] [persist|

User   -- table name and entity record type
    -- implicit autoincrement column "id" as primary key, typed UserId
    ident Text             -- refers to db. table column "ident"; 
                     -- generates a record field prefixing the table name as  "userIdent"
    password Text Maybe         -- Maybe indicates Nullable field
    UniqueUser ident            -- unique constraint with space sep. field sequence

Email  -- table name and entity record type
    -- implicit autoincrement column "id" as primary key, typed EmailId
    email Text
    user UserId                 -- foreign key by specifying other tables EntityField types
    verkey Text Maybe

    newlyAddedColumn Text "default='sometext'::character varying"  -- sql level Default constraint

    UniqueEmail email     -- unique constraint
|]
  • Esqueleto: is a haskell combinators layer to generate correct relational queries to persistent.[70]

Example for persistent rawSQL and Esqueleto queries.[71]

E-mail

[edit]

The following packages are part of the yesod-platform:[72]

  • email-validate: Validating an email address.[73]
  • mime-mail: Compose and send MIME email messages.[74]

Facebook

[edit]
  • Useful glue functions between the fb library and Yesod.[75]

Development cycle

[edit]

New Yesod apps are generated from the HaskellStack tool[76] templates, replacing previous command "yesod init"

Stack based app. template names are prefixed by yesod as "yesod-{minimal | postgres | sqlite | mysql | mongo | ...}"

  • Since HaskellStack uses the stackage repo by default, extra packages from the hackage repo should be referred in the "stack.yaml" extra-deps section.
  • Packages may be customized to a local subfolder. They must be referred in the "stack.yaml" packages section.

The "Yesod helper" tool

[edit]
  • The yesod helper tool [77]
    • yesod devel run from the project site, recompiles and restarts the project at every file tree modification.
    • yesod add-handler adds a new handler and module to the project, adding an import clause for the handler in the "Application" module.

Deploying with Keter: A web app server monitor and reverse proxy server

[edit]

See refs.[78][79] [80]

Keter is a process as a service that handles deployment and restart of Yesod web app servers, and, per web app, database creation for PostgreSQL.

The console command yesod keter packs the web app. as a keter bundle for uploading to a keter folder named "incoming".

Keter monitors the "incoming" folder and unpacks the app. to a temporary one, then assigns the web app a port to listen to, and starts it.

Initially it worked with Nginx as reverse proxy (keter version 0.1*), adding virtual server entries to its configuration and making Nginx reload it, but now Keter itself provides its own reverse proxy functionality, removing Nginx dependency and acting as the main web server.[81]

Old documentation (Nginx based).[82][83]

Integration with JavaScript generated from functional languages

[edit]

See ref.[84][85][86]

See also

[edit]

References

[edit]
  1. ^ "yesodweb/yesod".
  2. ^ a b c "HaskellWiki - QuasiQuotation". Haskell.org. 2025-08-07. Retrieved 2025-08-07.
  3. ^ "University of Kent - Comparing Dynamic and Static Language Approaches to Web Frameworks - Yesod vs Ruby on Rails" (PDF). Retrieved 2025-08-07.
  4. ^ "The wai package". Hackage.haskell.org. Retrieved 2025-08-07.
  5. ^ "The wai-extra package with CGI WAI handler". Hackage.haskell.org. Retrieved 2025-08-07.
  6. ^ "The wai-handler-fastcgi package". Hackage.haskell.org. Retrieved 2025-08-07.
  7. ^ "The wai-handler-scgi package". Hackage.haskell.org. Retrieved 2025-08-07.
  8. ^ "The warp package". Hackage.haskell.org. Retrieved 2025-08-07.
  9. ^ "The wai-handler-launch package". Hackage.haskell.org. Retrieved 2025-08-07.
  10. ^ a b "book - Basics". Yesodweb.com. Retrieved 2025-08-07.
  11. ^ The mkYesod code
  12. ^ a b "book - Routing and Handlers". Yesodweb.com. Retrieved 2025-08-07.
  13. ^ "Playing with Routes and Links". FPComplete.com. 2025-08-07. Retrieved 2025-08-07.
  14. ^ "book - Authentication and Authorization". Yesodweb.com. Retrieved 2025-08-07.
  15. ^ "The yesod-auth package". Hackage.haskell.org. Retrieved 2025-08-07.
  16. ^ "book - Sessions - See section "Ultimate Destination"". Yesodweb.com. Retrieved 2025-08-07.
  17. ^ "Sessions". Yesodweb.com. Retrieved 2025-08-07.
  18. ^ "Web.ClientSession". Hackage.haskell.org. Retrieved 2025-08-07.
  19. ^ "ServerSession: secure modular server-side sessions". Hackage.haskell.org. Retrieved 2025-08-07.
  20. ^ "Web.ServerSession.Frontend.Yesod". Hackage.haskell.org. Retrieved 2025-08-07.
  21. ^ "Session Messages". Yesodweb.com. Retrieved 2025-08-07.
  22. ^ "Creating a Subsite". Yesodweb.com. Retrieved 2025-08-07.
  23. ^ "Yesod and subsites: a no-brainer". Monoid.se. 2025-08-07. Retrieved 2025-08-07.[]
  24. ^ "The Magic of Yesod, part 2 - See section "Static Subsite"". Yesodweb.com. 2025-08-07. Retrieved 2025-08-07.
  25. ^ "The package yesod-static - Static Subsite". Hackage.haskell.org. Retrieved 2025-08-07.
  26. ^ "The package yesod-auth - Auth Subsite". Hackage.haskell.org. Retrieved 2025-08-07.
  27. ^ a b "book - Forms". Yesodweb.com. Retrieved 2025-08-07.
  28. ^ "Yesod.Form.Fields". Hackage.haskell.org. Retrieved 2025-08-07.
  29. ^ "Yesod.Form.Functions runFormPost". Hackage.haskell.org. Retrieved 2025-08-07.
  30. ^ "Yesod.Form.Types". Hackage.haskell.org. Retrieved 2025-08-07.
  31. ^ "HaskellWiki - Applicative functor". haskell.org. Retrieved 2025-08-07.
  32. ^ a b "The class HasReps". Hackage.haskell.org. Retrieved 2025-08-07.
  33. ^ "RESTful Content". Yesodweb.com. Retrieved 2025-08-07.
  34. ^ "The class ToContent". Hackage.haskell.org. Retrieved 2025-08-07.
  35. ^ "More Client Side Yesod: todo sample". Yesodweb.com. 2025-08-07. Retrieved 2025-08-07.
  36. ^ "JSON Web Service". Yesodweb.com. Retrieved 2025-08-07.
  37. ^ "The yesod-json package". Hackage.haskell.org. Retrieved 2025-08-07.
  38. ^ "book - Widgets". Yesodweb.com. Retrieved 2025-08-07.
  39. ^ "The widget monad". Hackage.haskell.org. Retrieved 2025-08-07.
  40. ^ "The Writer monad". Haskell.org. Retrieved 2025-08-07.
  41. ^ "Template Haskell Quasi-quotation". Haskell.org. Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  42. ^ a b "book - Shakesperean templates". Yesodweb.com. Retrieved 2025-08-07.
  43. ^ "The hamlet template module". Hackage.haskell.org. Retrieved 2025-08-07.
  44. ^ "Class Text.Blaze.ToMarkup". Hackage.haskell.org. Retrieved 2025-08-07.
  45. ^ "Class Text.Cassius.ToCss". Hackage.haskell.org. Retrieved 2025-08-07.
  46. ^ "Class Text.Julius.ToJavascript". Hackage.haskell.org. Retrieved 2025-08-07.
  47. ^ "Class Text.Shakespeare.I18N.ToMessage". Hackage.haskell.org. Retrieved 2025-08-07.
  48. ^ "Class Text.Shakespeare.Text.ToText". Hackage.haskell.org. Retrieved 2025-08-07.
  49. ^ "Template Haskell". haskell.org. Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  50. ^ "book - Shakesperean templates # Calling shakespeare". Yesodweb.com. Retrieved 2025-08-07.
  51. ^ a b "The Julius template module". Hackage.haskell.org. Retrieved 2025-08-07.
  52. ^ "Roy language". Roy.brianmckenna.org. Retrieved 2025-08-07.[permanent dead link]
  53. ^ "The Cassius template module". Hackage.haskell.org. Retrieved 2025-08-07.
  54. ^ "The Lucius template module". Hackage.haskell.org. Retrieved 2025-08-07.
  55. ^ "The Typescript template module". Hackage.haskell.org. Retrieved 2025-08-07.
  56. ^ "Shakespeare plain text templates module". Hackage.haskell.org. Retrieved 2025-08-07.
  57. ^ "book - Internationalization". Yesodweb.com. Retrieved 2025-08-07.
  58. ^ mkMessage
  59. ^ "The YesodBreadcrumbs class". Hackage.haskell.org. Retrieved 2025-08-07.
  60. ^ "The yesod-sitemap package". Hackage.haskell.org. Retrieved 2025-08-07.
  61. ^ "The yesod-newsfeed package for RSS / Atom views". Hackage.haskell.org. Retrieved 2025-08-07.
  62. ^ "Book - Initializing data in the foundation datatype". Yesodweb.com. Retrieved 2025-08-07.
  63. ^ a b c "book - Persistent". Yesodweb.com. Retrieved 2025-08-07.
  64. ^ "Yesod-persistent package". Hackage.haskell.org. Retrieved 2025-08-07.
  65. ^ "Yesod-persistent docs". github.com. Retrieved 2025-08-07.
  66. ^ "Yesod-persistent entity syntax". github.com. Retrieved 2025-08-07.
  67. ^ "Redundant migrations for fields' default values". GitHub.com. Retrieved 2025-08-07.
  68. ^ ""At most one" cardinality enforcement in persistent with type Checkmark". Hackage.haskell.org. Retrieved 2025-08-07.
  69. ^ "How can I create a foreign key constraint using Yesod/Persistent?". stackoverflow.com. Retrieved 2025-08-07.
  70. ^ "esqueleto package". Hackage.haskell.org. Retrieved 2025-08-07.
  71. ^ "Query example at". Stackoverflow.com. 2025-08-07. Retrieved 2025-08-07.
  72. ^ "The yesod package". Hackage.haskell.org. Retrieved 2025-08-07.
  73. ^ "The email-validate package". Hackage.haskell.org. Retrieved 2025-08-07.
  74. ^ "The mime-mail package". Hackage.haskell.org. Retrieved 2025-08-07.
  75. ^ "The yesod-fb package". Hackage.haskell.org. Retrieved 2025-08-07.
  76. ^ Haskell Stack - How to install
  77. ^ The yesod-bin pkg with the helper tool (with instructions for use with the stack tool)
  78. ^ "book - Deploying your Webapp". Yesodweb.com. Retrieved 2025-08-07.
  79. ^ Readme.Md. "Yesod keter readme". GitHub. Retrieved 2025-08-07.
  80. ^ "The keter package". Hackage.haskell.org. Retrieved 2025-08-07.
  81. ^ "Keter updates". Yesodweb.com. 2025-08-07. Retrieved 2025-08-07.
  82. ^ "Keter: Web App Deployment". Yesodweb.com. 2025-08-07. Retrieved 2025-08-07.
  83. ^ "Keter: It's Alive!". Yesodweb.com. 2025-08-07. Retrieved 2025-08-07.
  84. ^ "Javascript Options". github.com. Retrieved 2025-08-07.
  85. ^ "Yesod, AngularJS and Fay". yesodweb.com. 2025-08-07. Retrieved 2025-08-07.
  86. ^ "HaskellWiki - The JavaScript Problem". haskell.org. Retrieved 2025-08-07.
[edit]

Blog tutorials

[edit]

Comparisons

[edit]

Other languages

[edit]

At Linux distributions

[edit]
眼睛发涩是什么原因导致的 大便什么颜色是正常的 什么叫弱视 3个火读什么 胃立康片适合什么病
芯字五行属什么 肺癌不能吃什么水果 琋字五行属什么 农历10月22日是什么星座 老年人全身无力是什么原因
自渎什么意思 白介素8升高说明什么 为什么月经迟迟不来又没怀孕 增加性功能吃什么药 什么炖鸡好吃
手脚脱皮是什么原因导致的 琬字五行属什么 朝奉是什么意思 软卧代软座什么意思 男人蛋皮痒用什么药
梦见爸爸去世预兆什么cl108k.com 孕妇吃什么水果好对胎儿好hcv7jop9ns8r.cn 大便不成形吃什么食物好hcv7jop6ns8r.cn 睡觉为什么流口水hcv8jop0ns2r.cn 粉色裤子搭什么上衣hcv8jop9ns7r.cn
丁字五行属什么hcv8jop7ns3r.cn 什么原因导致尿酸高hcv8jop3ns7r.cn 摩羯座男生喜欢什么样的女生hcv9jop8ns2r.cn 胃酸是什么症状hcv9jop7ns5r.cn 男人前列腺炎有什么症状表现hcv7jop6ns6r.cn
黄茶适合什么人喝hcv9jop3ns0r.cn 莲子吃了有什么好处qingzhougame.com 流萤是什么意思hcv9jop1ns4r.cn 进德勤一般要什么学历cj623037.com 气场什么意思hcv9jop6ns5r.cn
沙土地适合种什么农作物hcv9jop0ns0r.cn 氯读什么拼音hcv9jop6ns0r.cn 鱼腥草有什么功效bfb118.com 回锅肉是什么肉cl108k.com 脚上长水泡是什么原因引起的hcv8jop6ns9r.cn
百度