mirror of
https://github.com/srid/rib.git
synced 2024-11-26 13:50:31 +03:00
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.
This commit is contained in:
parent
4f42517abb
commit
d92388a3e5
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user