From 8aaa0569781bf6fcb2189aa4566035fcfb5a850d Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Mon, 30 Sep 2024 23:30:43 +0200 Subject: [PATCH] Add IsDirectory --- byg/src/DependencyGenerator.hs | 4 ++++ byg/src/Evaluation/FunctionIO.hs | 5 ++++- byg/src/Types/FunctionIO.hs | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/byg/src/DependencyGenerator.hs b/byg/src/DependencyGenerator.hs index 15cbb1f..92129a9 100644 --- a/byg/src/DependencyGenerator.hs +++ b/byg/src/DependencyGenerator.hs @@ -28,6 +28,7 @@ module DependencyGenerator , applyTemplate , toText , listDirectory + , isDirectory , readTemplate , convertImage , saveFile @@ -214,6 +215,9 @@ toText a = runFunction ToText =<< toToken a listDirectory :: TokenableTo FilePath a => a -> DepGenM' [FilePath] listDirectory a = runFunctionIO ListDirectory =<< toToken a +isDirectory :: TokenableTo FilePath a => a -> DepGenM' Bool +isDirectory a = runFunctionIO IsDirectory =<< toToken a + readTemplate :: TokenableTo FilePath a => a -> DepGenM' Template readTemplate a = runFunctionIO ReadTemplate =<< toToken a diff --git a/byg/src/Evaluation/FunctionIO.hs b/byg/src/Evaluation/FunctionIO.hs index 1f863e5..877c666 100644 --- a/byg/src/Evaluation/FunctionIO.hs +++ b/byg/src/Evaluation/FunctionIO.hs @@ -12,13 +12,16 @@ import qualified Text.Pandoc as P import qualified Text.Blaze.Html.Renderer.Text as B import qualified Codec.Picture as CP import qualified Codec.Picture.STBIR as CPS -import System.Directory (listDirectory, createDirectory, copyFile) +import System.Directory (listDirectory, doesDirectoryExist, createDirectory, copyFile) evalFunctionIO :: FunctionIO -> Value -> IO Value evalFunctionIO f x = case (f, x) of (ListDirectory, String s) -> (List . map toValue) <$> listDirectory s + (IsDirectory, String s) -> + Bool <$> doesDirectoryExist s + (ReadTemplate, String s) -> do t <- T.readFile s let c = "CONTENT" diff --git a/byg/src/Types/FunctionIO.hs b/byg/src/Types/FunctionIO.hs index 24276f9..87e6dbb 100644 --- a/byg/src/Types/FunctionIO.hs +++ b/byg/src/Types/FunctionIO.hs @@ -5,6 +5,7 @@ module Types.FunctionIO import Language.Haskell.TH.Syntax (Lift) data FunctionIO = ListDirectory + | IsDirectory | ReadTemplate | ConvertImage | SaveFile