Skip to content

pbrisbin/yesod-links

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yesod links

import Yesod.Links

instance YesodLinked MySite where
    type Linked = MySite

Make concise link-widgets by defining how things should be represented as links.

--
-- * Make linking to any specific route simpler
--
instance IsLink MySiteRoute where
    toLink RootR  = Link (Internal RootR)  "go home"         "home"
    toLink AboutR = Link (Internal AboutR) "about this site" "about"

getRootR :: Handler RepHtml
getRootR = defaultLayout $ do
    [whamlet|

        be sure to visit our ^{link AboutR} page.

        |]

--
-- * Use it for more than just routes
--
data Post = Post
    { postSlug  :: Text
    , postTitle :: Text
    , postDescr :: Text
    }

instance IsLink Post where
    toLink (Post s t d) = Link (Internal $ PostR s) d t

getIndexR :: Handler RepHtml
getIndexR = defaultLayout do
    [whamlet|

        <ul>
            $forall post <- posts
                <li>^{link post}
        
        |]

--
-- * Bypass the IsLink instance and use the raw link' function for 
--   external links
--
getAboutR :: Handler RepHtml
getAboutR = defaultLayout $ do
    [whamlet|
        
        be sure to checkout my ^{link' github} profile.

        |]

    where
        github :: Link MySite
        github = Link (External "https://github.com/pbrisbin") "my github repos" "github"

About

Convenience functions for creating link widgets to types

Resources

License

Stars

Watchers

Forks

Packages

No packages published