Require simpler IsImageExtension

This commit is contained in:
Niels G. W. Serup 2024-09-25 23:12:32 +02:00
parent 056c8d278b
commit c22fd7ddf0
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
4 changed files with 10 additions and 10 deletions

View File

@ -15,7 +15,7 @@ module DependencyGenerator
, joinPaths , joinPaths
, fileComponents , fileComponents
, isImageFilename , isImageExtension
, convertedImageFilename , convertedImageFilename
, applyTemplate , applyTemplate
, listDirectory , listDirectory
@ -97,10 +97,9 @@ mapDepGenM_ f input = do
_ <- mapDepGenM (\x -> f x >> pure NoToken) input _ <- mapDepGenM (\x -> f x >> pure NoToken) input
pure () pure ()
filterDepGenM :: (Token a -> DepGenM' Bool) -> Token [a] -> DepGenM' [a] filterDepGenM :: Token [Bool] -> Token [a] -> DepGenM' [a]
filterDepGenM f input = do filterDepGenM mask input = do
conds <- mapDepGenM f input genDependency (makeDependency (TupleToken (input, mask)) FilterComp)
genDependency (makeDependency (TupleToken (input, conds)) FilterComp)
unzipFstDepGenM :: TokenableTo [(a, b)] t => t -> DepGenM (Token [a]) unzipFstDepGenM :: TokenableTo [(a, b)] t => t -> DepGenM (Token [a])
unzipFstDepGenM t = do unzipFstDepGenM t = do
@ -141,8 +140,8 @@ joinPaths (a, b) = do
fileComponents :: TokenableTo FilePath a => a -> DepGenM' (String, String) fileComponents :: TokenableTo FilePath a => a -> DepGenM' (String, String)
fileComponents a = runFunction FileComponents =<< toToken a fileComponents a = runFunction FileComponents =<< toToken a
isImageFilename :: TokenableTo FilePath a => a -> DepGenM' Bool isImageExtension :: TokenableTo FilePath a => a -> DepGenM' Bool
isImageFilename a = runFunction IsImageFilename =<< toToken a isImageExtension a = runFunction IsImageExtension =<< toToken a
convertedImageFilename :: TokenableTo FilePath a => a -> DepGenM' FilePath convertedImageFilename :: TokenableTo FilePath a => a -> DepGenM' FilePath
convertedImageFilename a = runFunction ConvertedImageFilename =<< toToken a convertedImageFilename a = runFunction ConvertedImageFilename =<< toToken a

View File

@ -9,7 +9,7 @@ evalFunction f x = case (f, x) of
(JoinPaths, Tuple (String _, String _)) -> (JoinPaths, Tuple (String _, String _)) ->
String undefined String undefined
(IsImageFilename, String _) -> (IsImageExtension, String _) ->
Bool undefined Bool undefined
(ConvertedImageFilename, String _) -> (ConvertedImageFilename, String _) ->

View File

@ -7,7 +7,8 @@ handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> DepGenM
handleRecipeDir outputDir template dir = do handleRecipeDir outputDir template dir = do
dirContents <- listDirectory dir dirContents <- listDirectory dir
(bases, exts) <- unzipDepGenM (mapDepGenM fileComponents dirContents) (bases, exts) <- unzipDepGenM (mapDepGenM fileComponents dirContents)
imageFilenames <- filterDepGenM isImageFilename dirContents areImageFilenames <- mapDepGenM isImageExtension exts
imageFilenames <- filterDepGenM areImageFilenames dirContents
convertedImageFilenames <- mapDepGenM convertedImageFilename imageFilenames convertedImageFilenames <- mapDepGenM convertedImageFilename imageFilenames
mapDepGenM_ mapDepGenM_
(\files -> convertImage (files, inject $ ResizeToWidth 800)) (\files -> convertImage (files, inject $ ResizeToWidth 800))

View File

@ -6,7 +6,7 @@ import Language.Haskell.TH.Syntax (Lift)
data Function = JoinPaths data Function = JoinPaths
| FileComponents | FileComponents
| IsImageFilename | IsImageExtension
| ConvertedImageFilename | ConvertedImageFilename
| ApplyTemplate | ApplyTemplate
deriving (Show, Lift) deriving (Show, Lift)