From 086217a93f81e10fece7807e31c347873aa99581 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sun, 24 Nov 2019 11:36:38 -0500 Subject: [PATCH] Make input/ output directories not polymorphic Until this PR is merged: https://github.com/commercialhaskell/path/pull/140 --- src/Rib/App.hs | 8 +++----- src/Rib/Shake.hs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Rib/App.hs b/src/Rib/App.hs index eab5a1d..b28e6f8 100644 --- a/src/Rib/App.hs +++ b/src/Rib/App.hs @@ -45,16 +45,14 @@ data App -- | Run Rib using arguments passed in the command line. run :: - forall b. - Typeable b => -- | Directory from which source content will be read. -- -- NOTE: This should ideally *not* be `"."` as our use of watchTree (of -- `runWith`) can interfere with Shake's file scaning. - Path b Dir -> + Path Rel Dir -> -- | The path where static files will be generated. Rib's server uses this -- directory when serving files. - Path b Dir -> + Path Rel Dir -> -- | Shake build rules for building the static site Action () -> IO () @@ -77,7 +75,7 @@ run src dst buildAction = runWith src dst buildAction =<< cmdArgs ribCli ] -- | Like `run` but with an explicitly passed `App` mode -runWith :: forall b. Typeable b => Path b Dir -> Path b Dir -> Action () -> App -> IO () +runWith :: Path Rel Dir -> Path Rel Dir -> Action () -> App -> IO () runWith src dst buildAction = \case WatchAndGenerate -> withManager $ \mgr -> do -- Begin with a *full* generation as the HTML layout may have been changed. diff --git a/src/Rib/Shake.hs b/src/Rib/Shake.hs index 2d2d189..04d672a 100644 --- a/src/Rib/Shake.hs +++ b/src/Rib/Shake.hs @@ -31,18 +31,18 @@ import Path import Path.IO import Rib.Markup -data Dirs b = Dirs (Path b Dir, Path b Dir) +data Dirs = Dirs (Path Rel Dir, Path Rel Dir) deriving (Typeable) -getDirs :: Typeable b => Action (Path b Dir, Path b Dir) +getDirs :: Action (Path Rel Dir, Path Rel Dir) getDirs = getShakeExtra >>= \case Just (Dirs d) -> return d Nothing -> fail "Input output directories are not initialized" -ribInputDir :: Typeable b => Action (Path b Dir) +ribInputDir :: Action (Path Rel Dir) ribInputDir = fst <$> getDirs -ribOutputDir :: Typeable b => Action (Path b Dir) +ribOutputDir :: Action (Path Rel Dir) ribOutputDir = do output <- snd <$> getDirs liftIO $ createDirIfMissing True output @@ -51,8 +51,8 @@ ribOutputDir = do -- | Shake action to copy static files as is buildStaticFiles :: [Path Rel File] -> Action () buildStaticFiles staticFilePatterns = do - input <- ribInputDir @Rel - output <- ribOutputDir @Rel + input <- ribInputDir + output <- ribOutputDir files <- getDirectoryFiles' input staticFilePatterns void $ forP files $ \f -> copyFileChanged' (input f) (output f) @@ -85,7 +85,7 @@ readDocMulti :: Path Rel File -> Action [Document t] readDocMulti pat = do - input <- ribInputDir @Rel + input <- ribInputDir fs <- getDirectoryFiles' input [pat] forP fs $ \f -> do need $ toFilePath <$> [input f] @@ -99,7 +99,7 @@ readDocMulti pat = do -- | Build a single HTML file with the given value buildHtml :: Path Rel File -> Html () -> Action () buildHtml f html = do - output <- ribOutputDir @Rel + output <- ribOutputDir writeHtml (output f) html where writeHtml :: MonadIO m => Path b File -> Html () -> m ()