Generalize ReadTemplate
This commit is contained in:
parent
7801371534
commit
1988beb49a
|
@ -228,8 +228,11 @@ listDirectory a = runFunctionIO ListDirectory =<< toToken a
|
|||
isDirectory :: TokenableTo FilePath a => a -> DepGenM' Bool
|
||||
isDirectory a = runFunctionIO IsDirectory =<< toToken a
|
||||
|
||||
readTemplate :: TokenableTo FilePath a => a -> DepGenM' Template
|
||||
readTemplate a = runFunctionIO ReadTemplate =<< toToken a
|
||||
readTemplate :: (TokenableTo FilePath a, TokenableTo Text b) => a -> b -> DepGenM' Template
|
||||
readTemplate a b = do
|
||||
a' <- toToken a
|
||||
b' <- toToken b
|
||||
runFunctionIO ReadTemplate $ TupleToken (a', b')
|
||||
|
||||
convertImage :: (TokenableTo (FilePath, FilePath) a, TokenableTo ImageConversionSettings b) => a -> b -> DepGenM ()
|
||||
convertImage a b = do
|
||||
|
|
|
@ -24,10 +24,9 @@ evalFunctionIO f x = case (f, x) of
|
|||
(IsDirectory, String (StringWrapper s)) ->
|
||||
Bool <$> doesDirectoryExist s
|
||||
|
||||
(ReadTemplate, String (StringWrapper s)) -> do
|
||||
(ReadTemplate, Tuple (String (StringWrapper s), Text c)) -> do
|
||||
t <- T.readFile s
|
||||
let c = "CONTENT"
|
||||
(beforeContent, after) = T.breakOn c t
|
||||
let (beforeContent, after) = T.breakOn c t
|
||||
afterContent = T.drop (T.length c) after
|
||||
pure $ Template $ TemplateParts beforeContent afterContent
|
||||
|
||||
|
@ -62,4 +61,4 @@ evalFunctionIO f x = case (f, x) of
|
|||
pure $ Text $ TL.toStrict $ B.renderHtml html
|
||||
|
||||
_ ->
|
||||
error "unexpected combination of function and argument type"
|
||||
error ("unexpected combination of function and argument type; got function " ++ show f ++ " with argument " ++ show x)
|
||||
|
|
|
@ -62,7 +62,7 @@ generateSite = do
|
|||
recipesDir <- inject "retter"
|
||||
outputRecipesDir <- joinPaths outputDir recipesDir
|
||||
makeDir outputRecipesDir
|
||||
template <- readTemplate $ inject "template.html"
|
||||
template <- readTemplate (inject "template.html") (inject "CONTENT")
|
||||
indexName <- inject "index.html"
|
||||
dirNames <- listDirectory recipesDir
|
||||
dirPaths <- mapDepGenM (joinPaths recipesDir) dirNames
|
||||
|
|
Loading…
Reference in New Issue