From ba544e3839032b96d3a2b865bd9aa3e5a2c38153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hamal=20Dvo=C5=99=C3=A1k?= <mordae@anilinux.org> Date: Mon, 27 Jan 2020 01:41:43 +0100 Subject: [PATCH] Add link feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Hamal Dvořák <mordae@anilinux.org> --- lib/Hikaru/Link.hs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Hikaru/Link.hs b/lib/Hikaru/Link.hs index d0ff46e..0286485 100644 --- a/lib/Hikaru/Link.hs +++ b/lib/Hikaru/Link.hs @@ -7,7 +7,8 @@ Maintainer : mordae@anilinux.org Stability : unstable Portability : non-portable (ghc) -This module provides various ways to build local links. +This module provides various ways to build local links and provide +feedback based on the request path. -} module Hikaru.Link @@ -18,6 +19,10 @@ module Hikaru.Link , lhref_ , phref_ , qhref_ + + -- ** Path Feedback + , isActivePath + , isActivePrefix ) where import BasePrelude @@ -96,4 +101,26 @@ where qhref_ qs = href_ (makeLink [] qs) + -- Path Feedback ----------------------------------------------------------- + + + -- | + -- Determine whether the supplied path is the one user has requested. + -- + isActivePath :: (MonadAction m) => [Text] -> m Bool + isActivePath link = do + path <- getPathInfo + return $ link == path + + + -- | + -- Determine whether the supplied path is a prefix of the one user has + -- requested. Empty path components in the supplied path are ignored. + -- + isActivePrefix :: (MonadAction m) => [Text] -> m Bool + isActivePrefix link = do + path <- getPathInfo + return $ isPrefixOf (filter (/= "") link) path + + -- vim:set ft=haskell sw=2 ts=2 et: -- GitLab