Swap DepGenM and DepGenM'
This commit is contained in:
parent
f4ff6d6d98
commit
daacf2e6fa
|
@ -31,21 +31,21 @@ import Types.Dependency (Action(..), Dependency, makeDependency)
|
|||
import Control.Monad.State (MonadState, State, runState, put, get)
|
||||
import Control.Monad.Writer (MonadWriter, WriterT, execWriterT, tell)
|
||||
|
||||
newtype DepGenM' a = DepGenM { unDepGenM :: WriterT [Dependency] (State Int) a }
|
||||
newtype DepGenM a = DepGenM { unDepGenM :: WriterT [Dependency] (State Int) a }
|
||||
deriving (Functor, Applicative, Monad, MonadState Int, MonadWriter [Dependency])
|
||||
|
||||
type DepGenM a = DepGenM' (Token a)
|
||||
type DepGenM' a = DepGenM (Token a)
|
||||
|
||||
evalDepGenM' :: Int -> DepGenM' () -> ([Dependency], Int)
|
||||
evalDepGenM' :: Int -> DepGenM () -> ([Dependency], Int)
|
||||
evalDepGenM' top m = runState (execWriterT (unDepGenM m)) top
|
||||
|
||||
evalDepGenM :: DepGenM' () -> [Dependency]
|
||||
evalDepGenM :: DepGenM () -> [Dependency]
|
||||
evalDepGenM m = fst (evalDepGenM' 0 m)
|
||||
|
||||
tellDep :: Dependency -> DepGenM' ()
|
||||
tellDep :: Dependency -> DepGenM ()
|
||||
tellDep dep = tell [dep]
|
||||
|
||||
genDependencyM :: (Token a -> DepGenM' Dependency) -> DepGenM a
|
||||
genDependencyM :: (Token a -> DepGenM Dependency) -> DepGenM' a
|
||||
genDependencyM f = do
|
||||
top <- get
|
||||
let top' = top + 1
|
||||
|
@ -55,26 +55,26 @@ genDependencyM f = do
|
|||
tellDep result
|
||||
pure target
|
||||
|
||||
genDependency :: (Token a -> Dependency) -> DepGenM a
|
||||
genDependency :: (Token a -> Dependency) -> DepGenM' a
|
||||
genDependency f = genDependencyM (pure . f)
|
||||
|
||||
inject :: Valuable a => a -> DepGenM a
|
||||
inject :: Valuable a => a -> DepGenM' a
|
||||
inject x = genDependency (makeDependency NoToken (Inject (toValue x)))
|
||||
|
||||
getListElem :: Token [a] -> DepGenM a
|
||||
getListElem :: Token [a] -> DepGenM' a
|
||||
getListElem outer = genDependency (makeDependency outer GetListElem)
|
||||
|
||||
setListElem :: Token a -> Token [a] -> DepGenM' ()
|
||||
setListElem :: Token a -> Token [a] -> DepGenM ()
|
||||
setListElem a outer = do
|
||||
tellDep (makeDependency a SetListElem outer)
|
||||
|
||||
runFunction :: Function -> Token a -> DepGenM b
|
||||
runFunction :: Function -> Token a -> DepGenM' b
|
||||
runFunction f input = genDependency (makeDependency input (Function f))
|
||||
|
||||
runFunctionIO :: FunctionIO -> Token a -> DepGenM b
|
||||
runFunctionIO :: FunctionIO -> Token a -> DepGenM' b
|
||||
runFunctionIO f input = genDependency (makeDependency input (FunctionIO f))
|
||||
|
||||
mapDepGenM :: (Token a -> DepGenM b) -> Token [a] -> DepGenM [b]
|
||||
mapDepGenM :: (Token a -> DepGenM' b) -> Token [a] -> DepGenM' [b]
|
||||
mapDepGenM f input = genDependencyM $ \target -> do
|
||||
top <- get
|
||||
let (res, top') = evalDepGenM' top $ do
|
||||
|
@ -84,49 +84,49 @@ mapDepGenM f input = genDependencyM $ \target -> do
|
|||
put top'
|
||||
pure (makeDependency input (MapComp res) target)
|
||||
|
||||
mapDepGenM_ :: (Token a -> DepGenM' ()) -> Token [a] -> DepGenM' ()
|
||||
mapDepGenM_ :: (Token a -> DepGenM ()) -> Token [a] -> DepGenM ()
|
||||
mapDepGenM_ f input = do
|
||||
_ <- mapDepGenM (\x -> f x >> pure NoToken) input
|
||||
pure ()
|
||||
|
||||
filterDepGenM :: (Token a -> DepGenM Bool) -> Token [a] -> DepGenM [a]
|
||||
filterDepGenM :: (Token a -> DepGenM' Bool) -> Token [a] -> DepGenM' [a]
|
||||
filterDepGenM f input = do
|
||||
conds <- mapDepGenM f input
|
||||
genDependency (makeDependency (TupleToken input conds) FilterComp)
|
||||
|
||||
|
||||
joinPaths :: Token (FilePath, FilePath) -> DepGenM FilePath
|
||||
joinPaths :: Token (FilePath, FilePath) -> DepGenM' FilePath
|
||||
joinPaths = runFunction JoinPaths
|
||||
|
||||
isImageFilename :: Token FilePath -> DepGenM Bool
|
||||
isImageFilename :: Token FilePath -> DepGenM' Bool
|
||||
isImageFilename = runFunction IsImageFilename
|
||||
|
||||
convertedImageFilename :: Token FilePath -> DepGenM FilePath
|
||||
convertedImageFilename :: Token FilePath -> DepGenM' FilePath
|
||||
convertedImageFilename = runFunction ConvertedImageFilename
|
||||
|
||||
applyTemplate :: Token (Template, String) -> DepGenM String
|
||||
applyTemplate :: Token (Template, String) -> DepGenM' String
|
||||
applyTemplate = runFunction ApplyTemplate
|
||||
|
||||
listDirectory :: Token FilePath -> DepGenM [FilePath]
|
||||
listDirectory :: Token FilePath -> DepGenM' [FilePath]
|
||||
listDirectory = runFunctionIO ListDirectory
|
||||
|
||||
readTemplate :: Token FilePath -> DepGenM Template
|
||||
readTemplate :: Token FilePath -> DepGenM' Template
|
||||
readTemplate = runFunctionIO ReadTemplate
|
||||
|
||||
convertImage :: Token ((FilePath, FilePath), ImageConversionSettings) -> DepGenM' ()
|
||||
convertImage :: Token ((FilePath, FilePath), ImageConversionSettings) -> DepGenM ()
|
||||
convertImage input = do
|
||||
_ <- runFunctionIO ConvertImage input
|
||||
pure ()
|
||||
|
||||
saveFile :: Token (String, FilePath) -> DepGenM' ()
|
||||
saveFile :: Token (String, FilePath) -> DepGenM ()
|
||||
saveFile input = do
|
||||
_ <- runFunctionIO SaveFile input
|
||||
pure ()
|
||||
|
||||
makeDir :: Token FilePath -> DepGenM' ()
|
||||
makeDir :: Token FilePath -> DepGenM ()
|
||||
makeDir input = do
|
||||
_ <- runFunctionIO MakeDir input
|
||||
pure ()
|
||||
|
||||
runPandoc :: Token FilePath -> DepGenM String
|
||||
runPandoc :: Token FilePath -> DepGenM' String
|
||||
runPandoc = runFunctionIO RunPandoc
|
||||
|
|
|
@ -3,7 +3,7 @@ module SiteGenerator (generateSite) where
|
|||
import Types
|
||||
import DependencyGenerator
|
||||
|
||||
handleRecipeDir :: Token Template -> Token FilePath -> DepGenM' ()
|
||||
handleRecipeDir :: Token Template -> Token FilePath -> DepGenM ()
|
||||
handleRecipeDir _template dir = do
|
||||
dirContents <- listDirectory dir
|
||||
imageFilenames <- filterDepGenM isImageFilename dirContents
|
||||
|
@ -12,7 +12,7 @@ handleRecipeDir _template dir = do
|
|||
settings <- inject $ ResizeToWidth 800
|
||||
convertImage $ TupleToken files settings
|
||||
|
||||
generateSite :: DepGenM' ()
|
||||
generateSite :: DepGenM ()
|
||||
generateSite = do
|
||||
outputDir <- inject "site"
|
||||
makeDir outputDir
|
||||
|
|
Loading…
Reference in New Issue