From 100d2948cb67f1892e3f06d2daef82056def3648 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Tue, 1 Mar 2016 22:43:31 +0000 Subject: [PATCH] Add Vervis.Path module with repo path utils --- src/Vervis/Path.hs | 61 ++++++++++++++++++++++++++++++++++++++++++++++ vervis.cabal | 1 + 2 files changed, 62 insertions(+) create mode 100644 src/Vervis/Path.hs diff --git a/src/Vervis/Path.hs b/src/Vervis/Path.hs new file mode 100644 index 0000000..7f84fe6 --- /dev/null +++ b/src/Vervis/Path.hs @@ -0,0 +1,61 @@ +{- This file is part of Vervis. + - + - Written in 2016 by fr33domlover . + - + - ♡ Copying is an act of love. Please copy, reuse and share. + - + - The author(s) have dedicated all copyright and related and neighboring + - rights to this software to the public domain worldwide. This software is + - distributed without any warranty. + - + - You should have received a copy of the CC0 Public Domain Dedication along + - with this software. If not, see + - . + -} + +module Vervis.Path + ( askRepoRootDir + , personDir + , askPersonDir + , projectDir + , askProjectDir + , repoDir + , askRepoDir + ) +where + +import Prelude + +import Data.Text (Text, unpack) +import System.FilePath (()) +import Yesod.Core.Handler (getYesod) + +import Vervis.Foundation +import Vervis.Settings + +askRepoRootDir :: Handler FilePath +askRepoRootDir = appRepoDir . appSettings <$> getYesod + +personDir :: FilePath -> Text -> FilePath +personDir root user = root unpack user + +askPersonDir :: Text -> Handler FilePath +askPersonDir user = do + root <- askRepoRootDir + return $ personDir root user + +projectDir :: FilePath -> Text -> Text -> FilePath +projectDir root user proj = root unpack user unpack proj + +askProjectDir :: Text -> Text -> Handler FilePath +askProjectDir user proj = do + root <- askRepoRootDir + return $ projectDir root user proj + +repoDir :: FilePath -> Text -> Text -> Text -> FilePath +repoDir root user proj repo = projectDir root user proj unpack repo + +askRepoDir :: Text -> Text -> Text -> Handler FilePath +askRepoDir user proj repo = do + root <- askRepoRootDir + return $ repoDir root user proj repo diff --git a/vervis.cabal b/vervis.cabal index f4a6c65..8edebe3 100644 --- a/vervis.cabal +++ b/vervis.cabal @@ -58,6 +58,7 @@ library Vervis.Handler.Project Vervis.Handler.Repo Vervis.Handler.Util + Vervis.Path Vervis.Style -- other-modules: default-extensions: TemplateHaskell