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

View File

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

View File

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

View File

@ -6,6 +6,13 @@ import Data.ByteString (ByteString)
data ImageConversionSettings = ResizeToWidth Int data ImageConversionSettings = ResizeToWidth Int
deriving (Show) 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 class (SourceState a, Show f) => IsFunction f a b | f -> a b where
runF :: f -> a -> b runF :: f -> a -> b