1
1
mirror of https://github.com/srid/rib.git synced 2024-11-29 19:09:55 +03:00

Make input/ output directories not polymorphic

Until this PR is merged: https://github.com/commercialhaskell/path/pull/140
This commit is contained in:
Sridhar Ratnakumar 2019-11-24 11:36:38 -05:00
parent 842ed096d3
commit 086217a93f
2 changed files with 11 additions and 13 deletions

View File

@ -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.

View File

@ -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 ()