daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE TypeFamilies, QuasiQuotes, MultiParamTypeClasses,
  2.   TemplateHaskell, OverloadedStrings #-}
  3.  
  4. import Yesod
  5.  
  6. -- The app is parameterised on a custom datatype; this can also
  7. -- contain other info of course:
  8. data Links = Links
  9.  
  10. -- Routes, using template-haskell.  (I find "Links" as a string to be
  11. -- a bit icky, but otherwise it works quite nicely). 'R' as a suffix
  12. -- is just a convention, but means "Resource".  Note that HomeR, etc
  13. -- become members of another data type created automatically.
  14. mkYesod "Links" [parseRoutes|
  15. / HomeR GET
  16. /page1 Page1R GET
  17. /page2 Page2R GET
  18. |]
  19.  
  20. -- Instantiate the Yesod interface for the app data type: the defaults
  21. -- are fine here, but there's heaps of methods you can override to
  22. -- specify things like the URL root, customise the default layout,
  23. -- etc.
  24. instance Yesod Links
  25.  
  26. -- Route handling.  The mian thing here -- the main thing in yesod,
  27. -- really -- is that because it's (template-)haskell again these are
  28. -- checked at compile-time, so they're type-safe.  Also, get*R is
  29. -- generated by mkYesod above.
  30. getHomeR, getPage1R, getPage2R :: Handler RepHtml
  31. getHomeR = defaultLayout [whamlet|<a href=@{Page1R}>Go to page 1!|]
  32. getPage1R = defaultLayout [whamlet|<a href=@{Page2R}>Go to page 2!|]
  33. getPage2R = defaultLayout [whamlet|<a href=@{HomeR}>Go home!|]
  34.  
  35. main :: IO ()
  36. main = warpDebug 3000 Links
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top