r s i s t | User name String age Int Todo userId UserId task Text done Bool | ] Other syntax: sqltype, constraint, sql etc. Deriving json Reference: Persisent docs Sibi Prabakaran Web programming in Haskell using Yesod
34 marlowId <− insert $ " Marlow " 35 insert_ $ simonId "Buy dragon book " False simonTasks <− s e l e c t L i s t [ TodoUserId ==. simonId ] [ LimitTo 5] ( simon : : Maybe User ) <− get simonId delete marlowId deleteWhere [ TodoUserId ==. simonId ] Sibi Prabakaran Web programming in Haskell using Yesod
URLs Mapping between route to handler is done Two way parsing functions created Sync between parsing and handler functions ensured Sibi Prabakaran Web programming in Haskell using Yesod
/ hello HelloR / f i b /# Int FibR GET Canonical URLs (joinPath, cleanPath) Pieces: Static, Dynamic single, Dynamic multi Sibi Prabakaran Web programming in Haskell using Yesod
| HelloR | FibR Int renderMyAppRoute HomeR = [ ] renderMyAppRoute HelloR = [ " hello " ] renderMyAppRoute ( FibR i n t ) = [ " f i b " , toSinglePiece i n t ] parseMyAppRoute [ ] = Just HomeR parseMyAppRoute [ " hello " ] = Just HelloR parseMyAppRoute [ " f i b " , i n t ] = do f i b I n t <− fromSinglePiece i n t return $ FibR f i b I n t parseMyAppRoute _ = Nothing Sibi Prabakaran Web programming in Haskell using Yesod
t i t l e >#{ pageTitle } − My Site <link rel =stylesheet href=@{ StylesheetR }> <body> <h1 . page−t i t l e >#{ pageTitle } <p>Here i s a l i s t of your f r i e n d s : $ i f n u l l fri e nd s <p>Sorry , I l i e d <p>You don ’ t have any f r i e n d s . $else <ul> $ f o r a l l Friend name age <− f r i e nd s < l i >#{name} (#{ age } years old ) < footer >^{ copyright } Sibi Prabakaran Web programming in Haskell using Yesod
. blog { padding : 1em; border : 1px s o l i d #000; h1 { color : #{ headingColor } ; background−image : u r l (@{ MyBackgroundR } ) ; } } Cassius section . blog padding : 1em border : 1px s o l i d #000 h1 color : #{ headingColor } background−image : u r l (@{ MyBackgroundR } ) Sibi Prabakaran Web programming in Haskell using Yesod
) { $ ( " section . # { sectionClass } " ) . hide ( ) ; $ ( "#mybutton " ) . c l i c k ( function ( ) { document . l o c a t i o n = "@{SomeRouteR} " ; } ) ; ^{ addBling } } ) ; Sibi Prabakaran Web programming in Haskell using Yesod
name = " Sibi < s c r i p t > a l e r t ( ’ injected ’ ) < / s c r i p t >" main : : IO ( ) main = putStrLn $ renderHtml [ shamlet | # {name } | ] Output: Sibi & l t ; s c r i p t> ; a l e r t (' in je ct ed ')& l t ; / s c r i p t> ; Sibi Prabakaran Web programming in Haskell using Yesod
Textual values are always escaped (see ToMarkup instances) Html values aren’t escaped preEscapedToHtml Sibi Prabakaran Web programming in Haskell using Yesod
to re-use a single UI component Can perform IO operations (DB queries etc.) Controls the generation of end HTML (<body>,<head> tags) Sibi Prabakaran Web programming in Haskell using Yesod
do s e t T i t l e "My Page T i t l e " toWidget [ lu cius | h1 { color : green ; } | ] addScriptRemote " https : / / ajax . googleapis .com/ ajax / l i b s / jquery / 1 . 6 . 2 / jquery . min . j s " toWidget [ j u l i u s | $ ( function ( ) { $ ( " h1 " ) . c l i c k ( function ( ) { a l e r t ( "You clicked on the heading ! " ) ; } ) ; } ) ; | ] toWidgetHead [ hamlet | <meta name=keywords content="some sample keywords "> | ] toWidget [ hamlet | <h1>Here ’ s one way of including content | ] [ whamlet| <h2>Here ’ s another | ] toWidgetBody [ j u l i u s | a l e r t ( " This i s included in the body i t s e l f " ) ; | ] Sibi Prabakaran Web programming in Haskell using Yesod
compile on server Change config file for production (Personally used CPP) Files to deploy: executable, static folder Keter Hapistrano Sibi Prabakaran Web programming in Haskell using Yesod
yesod-auth yesod-fb yesod-sitemap websocket/eventsource support Lots of others in Hackage Real world experience Sibi Prabakaran Web programming in Haskell using Yesod