yesod-slides



yesod-slides

0 0


yesod-slides

The slides for the presentation about developing web applications with Yesod in FMI.

On Github leohaskell / yesod-slides

Yesod

Haskell web framework

Created by 80910

Какво е Yesod?

"Yesod is a Haskell web framework for productive development of type-safe, RESTful, high performance web applications."

- Yesod Web Framework's team

Защо Yesod?

type-safety

висока производителност

по-малко boilerplate

използваме haskell

Stack

stack new my-project yesod-sqlite
cd my-project
stack setup
stack build
          

Компоненти

Routing

/               HomeR    GET
/login          LoginR   GET POST
/logout         LogoutR  GET
/songs/#UserId  SongsR   GET
/songinfo/#Int  SongR    GET
					

handler функции

/               HomeR    GET
/login          LoginR   GET POST
/logout         LogoutR  GET
/songs/#UserId  SongsR   GET
/songinfo/#Int  SongR    GET
          
getHomeR   :: Handler Html
getLoginR  :: Handler Html
postLoginR :: Handler Html
getLogoutR :: Handler Html
getSongsR  :: UserId -> Handler Html
getSongR   :: Int -> Handler Html
          

Например

getHomeR :: Handler Html
getHomeR = defaultLayout [whamlet|
  <p>Welcome to my page!
|]
          

Шекспирови шаблони

интерполация

if..elseif..else

forall

компилират се

нямаме счупени линкове

Хамлет (Hamlet)

$doctype
<html>
  <head>
    <title>Yesod FM
    <body>
      <header>
        <nav>
          <ul #menu>
            <li>
              <a href=@{HomeR}>homepage
            $if logged
              <li>
                <a href=@{LogoutR}>log out(#{uname})
      <div>^{content}
          

Касий (Cassius)

#london
  background-color: #{rainyBlue}
          
#wife
  right: 100%
  margin: 0
          

Юлий (Julius)

$(function() {
  $('#omni').on('click', function () {
    alert("42")
  })
})
          

Форми

data User = User
  { username :: Text
  , password :: Text
  , email    :: Maybe Text
  }
          
userForm = renderDivs $ User
  <$> areq textField     "username" Nothing
  <*> areq passwordField "password" Nothing
  <*> aopt emailField    "email"    Nothing
          

Бази данни

PostgreSQL

SQLite

MySQL

MongoDB

Redis

share [mkPersist sqlSettings, mkMigrate "migrateAll"]
  [persistLowerCase|
    User
      username Text
      password Text
      Username username
    Song
      album  Text
      author Text
      title  Text
      year   Int 
      userId UserId Maybe
      Name   author title
|]
          

Потребителски сесии

user <- lookupSession "user"
let (logged, uname) =
      case user of
        Just u  -> (True, u)
        Nothing -> (False, "")
          
getLogoutR = do
  deleteSession "user"
  defaultLayout [whamlet|
    <p>You have successfully logged out. We'll miss you!
  |]
          

Още

аутентикация

ауторизация