Start worknig on templates
This commit is contained in:
parent
d5b8e2006c
commit
47dd09f54c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue