diff --git a/Application.hs b/Application.hs index 29231e6..f69e54a 100644 --- a/Application.hs +++ b/Application.hs @@ -57,6 +57,7 @@ import Handler.Haddock import Handler.Package import Handler.PackageList import Handler.CompressorStatus +import Handler.Tag -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the diff --git a/Handler/Tag.hs b/Handler/Tag.hs new file mode 100644 index 0000000..3718a44 --- /dev/null +++ b/Handler/Tag.hs @@ -0,0 +1,28 @@ +module Handler.Tag where + +import qualified Database.Esqueleto as E +import Data.Slug (Slug, unSlug) +import Import + + +getTagListR :: Handler Html +getTagListR = do + tags <- fmap (map (\(E.Value v) -> v)) $ runDB $ + E.selectDistinct $ E.from $ \tag -> do + E.orderBy [E.asc (tag E.^. TagTag)] + return (tag E.^. TagTag) + defaultLayout $ do + setTitle "Stackage tags" + $(widgetFile "tag-list") + +getTagR :: Slug -> Handler Html +getTagR tagSlug = do + packages <- fmap (map (\(E.Value v) -> v)) $ runDB $ + E.select $ E.from $ \tag -> do + E.where_ (tag E.^. TagTag E.==. E.val tagSlug) + E.orderBy [E.asc (tag E.^. TagPackage)] + return (tag E.^. TagPackage) + let tag = unSlug tagSlug + defaultLayout $ do + setTitle $ "Stackage tag" + $(widgetFile "tag") diff --git a/config/routes b/config/routes index e44a155..af86382 100644 --- a/config/routes +++ b/config/routes @@ -30,3 +30,5 @@ /package/#PackageName/like PackageLikeR POST /package/#PackageName/unlike PackageUnlikeR POST /package/#PackageName/tag PackageTagR POST +/tags TagListR GET +/tag/#Slug TagR GET \ No newline at end of file diff --git a/stackage-server.cabal b/stackage-server.cabal index 4ad4b54..de5fb4f 100644 --- a/stackage-server.cabal +++ b/stackage-server.cabal @@ -45,6 +45,7 @@ library Handler.Package Handler.PackageList Handler.CompressorStatus + Handler.Tag if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT diff --git a/templates/package.hamlet b/templates/package.hamlet index 63e1af9..41cde6b 100644 --- a/templates/package.hamlet +++ b/templates/package.hamlet @@ -23,7 +23,7 @@ $newline never No tags yet. # $forall tag <- tags - + #{tag} , # diff --git a/templates/tag-list.hamlet b/templates/tag-list.hamlet new file mode 100644 index 0000000..c98e4f1 --- /dev/null +++ b/templates/tag-list.hamlet @@ -0,0 +1,7 @@ +
+

Tags +