Split template loading into multiple steps

This commit is contained in:
2024-10-05 18:07:26 +02:00
parent 1988beb49a
commit 47420cbe41
6 changed files with 20 additions and 14 deletions

View File

@@ -52,6 +52,11 @@ evalFunction f x = case (f, x) of
(ElemOf, Tuple (y, List ys)) ->
Bool (y `elem` ys)
(MakeTemplate, Tuple (Text t, Text c)) ->
let (beforeContent, after) = T.breakOn c t
afterContent = T.drop (T.length c) after
in Template $ TemplateParts beforeContent afterContent
(ApplyTemplate, Tuple (Template (TemplateParts beforeContent afterContent), Text t)) ->
Text $ T.concat [beforeContent, t, afterContent]

View File

@@ -7,7 +7,6 @@ import Prelude hiding (String, FilePath)
import Types.Values
import Types (FunctionIO(..), Value(..), toValue)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.IO as T
import qualified Text.Pandoc as P
@@ -24,11 +23,8 @@ evalFunctionIO f x = case (f, x) of
(IsDirectory, String (StringWrapper s)) ->
Bool <$> doesDirectoryExist s
(ReadTemplate, Tuple (String (StringWrapper s), Text c)) -> do
t <- T.readFile s
let (beforeContent, after) = T.breakOn c t
afterContent = T.drop (T.length c) after
pure $ Template $ TemplateParts beforeContent afterContent
(ReadTextFile, String (StringWrapper s)) ->
Text <$> T.readFile s
(ConvertImage, Tuple (Tuple (String (StringWrapper source), String (StringWrapper target)),
ImageConversionSettings (ResizeToWidth widthResized))) -> do