Add IsDirectory

This commit is contained in:
Niels G. W. Serup 2024-09-30 23:30:43 +02:00
parent da7ea65cf5
commit 8aaa056978
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
3 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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"

View File

@ -5,6 +5,7 @@ module Types.FunctionIO
import Language.Haskell.TH.Syntax (Lift)
data FunctionIO = ListDirectory
| IsDirectory
| ReadTemplate
| ConvertImage
| SaveFile