From d92388a3e5f88e5420be391eb35aaedcb4ec559e Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sun, 29 Dec 2019 12:16:51 -0500 Subject: [PATCH] Eliminate Some/Proxy, reverting to simplest API Some and Proxy can be something the user can use on their code to multiplex between documents using disparate markup types. --- src/Rib/Document.hs | 4 +--- src/Rib/Shake.hs | 20 ++++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Rib/Document.hs b/src/Rib/Document.hs index 72add9c..126ebd1 100644 --- a/src/Rib/Document.hs +++ b/src/Rib/Document.hs @@ -89,14 +89,12 @@ instance Show DocumentError where mkDocumentFrom :: forall m b meta repr. (MonadError DocumentError m, MonadIO m, FromJSON meta, IsMarkup repr) => - -- | Which Markup parser to use - Proxy repr -> -- | File path, used only to identify (not access) the document "relpath" :! Path Rel File -> -- | Actual file path, for access and reading "path" :! Path b File -> m (Document meta repr) -mkDocumentFrom Proxy k@(arg #relpath -> k') f = do +mkDocumentFrom k@(arg #relpath -> k') f = do v <- liftEither . first DocumentError_MarkupError =<< readDoc @repr k f diff --git a/src/Rib/Shake.hs b/src/Rib/Shake.hs index 6329bc0..f73f6e1 100644 --- a/src/Rib/Shake.hs +++ b/src/Rib/Shake.hs @@ -26,7 +26,6 @@ module Rib.Shake where import Data.Aeson -import Data.Some import Development.Shake import Lucid (Html) import qualified Lucid @@ -69,17 +68,16 @@ buildStaticFiles staticFilePatterns = do buildHtmlMulti :: forall meta repr. (FromJSON meta, IsMarkup repr) => - Proxy repr -> -- | Source file patterns [Path Rel File] -> -- | How to render the given document to HTML - (Some (Document meta) -> Html ()) -> + (Document meta repr -> Html ()) -> -- | List of relative path to generated HTML and the associated document - Action [Some (Document meta)] -buildHtmlMulti pxy pat r = do - xs <- readDocMulti pxy pat + Action [Document meta repr] +buildHtmlMulti pat r = do + xs <- readDocMulti pat void $ forP xs $ \x -> do - outfile <- liftIO $ replaceExtension ".html" $ withSome x documentPath + outfile <- liftIO $ replaceExtension ".html" $ documentPath x buildHtml outfile (r x) pure xs @@ -87,11 +85,10 @@ buildHtmlMulti pxy pat r = do readDocMulti :: forall meta repr. (FromJSON meta, IsMarkup repr) => - Proxy repr -> -- | Source file patterns [Path Rel File] -> - Action [Some (Document meta)] -readDocMulti Proxy pats = do + Action [Document meta repr] +readDocMulti pats = do input <- ribInputDir fmap concat $ forM pats $ \pat -> do fs <- getDirectoryFiles' input [pat] @@ -99,8 +96,7 @@ readDocMulti Proxy pats = do need $ toFilePath <$> [input f] result <- runExceptT $ - mkSome - <$> mkDocumentFrom (Proxy @repr) + mkDocumentFrom ! #relpath f ! #path (input f) case result of