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

View File

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

View File

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

View File

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