Start worknig on templates

This commit is contained in:
Niels G. W. Serup 2024-09-21 23:21:47 +02:00
parent d5b8e2006c
commit 47dd09f54c
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
4 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,6 @@
module FunctionImplementations.IO
( ListDirectory(..)
, ReadTemplate(..)
, ConvertImage(..)
, SaveFile(..)
, RunPandoc(..)
@ -12,6 +13,10 @@ data ListDirectory = ListDirectory deriving (Show)
instance IsFunctionIO ListDirectory FilePath [FilePath] where
runFIO ListDirectory _path = undefined
data ReadTemplate = ReadTemplate deriving (Show)
instance IsFunctionIO ReadTemplate FilePath Template where
runFIO ReadTemplate _path = undefined
data ConvertImage = ConvertImage deriving (Show)
instance IsFunctionIO ConvertImage ((FilePath, FilePath), ImageConversionSettings) () where
runFIO ConvertImage ((_, _), ResizeToWidth _) = undefined

View File

@ -3,6 +3,7 @@ module Functions
( isImageFilename
, convertedImageFilename
, listDirectory
, readTemplate
, convertImage
, saveFile
, runPandoc
@ -16,6 +17,7 @@ isImageFilename = runFunction IsImageFilename
convertedImageFilename = runFunction ConvertedImageFilename
listDirectory = runFunctionIO ListDirectory
readTemplate = runFunctionIO ReadTemplate
convertImage = runFunctionIO ConvertImage
saveFile = runFunctionIO SaveFile
runPandoc = runFunctionIO RunPandoc

View File

@ -4,8 +4,8 @@ import Types
import ComputationM
import Functions
handleRecipeDir :: Token FilePath -> ComputationM ()
handleRecipeDir dir = do
handleRecipeDir :: Token Template -> Token FilePath -> ComputationM ()
handleRecipeDir template dir = do
dirContents <- listDirectory dir
imageFilenames <- filterComputationM isImageFilename dirContents
convertedImageFilenames <- mapComputationM convertedImageFilename imageFilenames
@ -15,9 +15,11 @@ handleRecipeDir dir = do
test :: ComputationM ()
test = do
templateFilename <- inject "template.html"
template <- readTemplate templateFilename
dir <- inject "retter"
dirContents <- listDirectory dir
mapComputationM_ handleRecipeDir dirContents
mapComputationM_ (handleRecipeDir template) dirContents
main :: IO ()
main = mapM_ print $ evalComputationM test

View File

@ -6,6 +6,13 @@ import Data.ByteString (ByteString)
data ImageConversionSettings = ResizeToWidth Int
deriving (Show)
data TemplatePart = Literal String
| KeyValue String
deriving (Show)
data Template = Template [TemplatePart]
deriving (Show)
class (SourceState a, Show f) => IsFunction f a b | f -> a b where
runF :: f -> a -> b