diff --git a/byg/src/FunctionImplementations/IO.hs b/byg/src/FunctionImplementations/IO.hs index 20413fa..1824a98 100644 --- a/byg/src/FunctionImplementations/IO.hs +++ b/byg/src/FunctionImplementations/IO.hs @@ -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 diff --git a/byg/src/Functions.hs b/byg/src/Functions.hs index 1cf19e2..8fb6d41 100644 --- a/byg/src/Functions.hs +++ b/byg/src/Functions.hs @@ -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 diff --git a/byg/src/Main.hs b/byg/src/Main.hs index c0cdf1e..8614077 100644 --- a/byg/src/Main.hs +++ b/byg/src/Main.hs @@ -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 diff --git a/byg/src/Types.hs b/byg/src/Types.hs index 6c4602a..cdd791b 100644 --- a/byg/src/Types.hs +++ b/byg/src/Types.hs @@ -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