mirror of
https://github.com/srid/rib.git
synced 2024-11-27 01:12:09 +03:00
Add src
type variable to Target type
And use it from Rib.Shake
This commit is contained in:
parent
4e524aaa12
commit
c43641eaac
@ -119,10 +119,10 @@ buildHtml ::
|
||||
-- | Path to the source file (relative to `ribInputDir`)
|
||||
Path Rel File ->
|
||||
-- | How to parse the source file
|
||||
SourceReader repr ->
|
||||
SourceReader a ->
|
||||
-- | How to render the given source to HTML
|
||||
(Source repr -> Html ()) ->
|
||||
Action (Source repr)
|
||||
(Target (Path Rel File) a -> Html ()) ->
|
||||
Action (Target (Path Rel File) a)
|
||||
buildHtml k parser r = buildHtml' k parser replaceExtHtml r
|
||||
where
|
||||
replaceExtHtml _ = liftIO $ replaceExtension ".html" k
|
||||
@ -132,21 +132,21 @@ buildHtml' ::
|
||||
-- | Path to the source file (relative to `ribInputDir`)
|
||||
Path Rel File ->
|
||||
-- | How to parse the source file
|
||||
SourceReader repr ->
|
||||
SourceReader a ->
|
||||
-- | Output file name to use (relative to `ribOutputDir`)
|
||||
(repr -> Action (Path Rel File)) ->
|
||||
(a -> Action (Path Rel File)) ->
|
||||
-- | How to render the given source to HTML
|
||||
(Source repr -> Html ()) ->
|
||||
Action (Source repr)
|
||||
(Target (Path Rel File) a -> Html ()) ->
|
||||
Action (Target (Path Rel File) a)
|
||||
buildHtml' k parser outfileFn r = do
|
||||
v <- readSource parser k
|
||||
outfile <- outfileFn v
|
||||
let src = Source k outfile v
|
||||
writeHtml outfile $ r src
|
||||
pure src
|
||||
let t = Target outfile k v
|
||||
writeTarget t r
|
||||
pure t
|
||||
|
||||
-- | Write the target file
|
||||
writeTarget :: Target a -> (Target a -> Html ()) -> Action ()
|
||||
writeTarget :: Target src a -> (Target src a -> Html ()) -> Action ()
|
||||
writeTarget t r = writeHtml (targetPath t) (r t)
|
||||
|
||||
-- | Write a single HTML file with the given HTML value
|
||||
|
@ -14,6 +14,7 @@ module Rib.Target
|
||||
targetPath,
|
||||
targetUrl,
|
||||
targetVal,
|
||||
targetSrc,
|
||||
)
|
||||
where
|
||||
|
||||
@ -22,24 +23,28 @@ import Path
|
||||
import Relude
|
||||
|
||||
-- | A generated file on disk
|
||||
data Target a
|
||||
data Target src a
|
||||
= Target
|
||||
{ _target_path :: Path Rel File,
|
||||
-- ^ Path to the generated HTML file (relative to `Rib.Shake.ribOutputDir`)
|
||||
_target_src :: src,
|
||||
_target_val :: a
|
||||
}
|
||||
deriving (Generic, Functor, Show)
|
||||
|
||||
-- | Path to the source file (relative to `Rib.Shake.ribInputDir`)
|
||||
targetPath :: Target repr -> Path Rel File
|
||||
targetPath :: Target src a -> Path Rel File
|
||||
targetPath = _target_path
|
||||
|
||||
targetSrc :: Target src a -> src
|
||||
targetSrc = _target_src
|
||||
|
||||
-- | Parsed representation of the source.
|
||||
targetVal :: Target repr -> repr
|
||||
targetVal :: Target src a -> a
|
||||
targetVal = _target_val
|
||||
|
||||
-- | Relative URL to the generated source HTML.
|
||||
targetUrl :: Target repr -> Text
|
||||
targetUrl :: Target src a -> Text
|
||||
targetUrl = urlForPath . _target_path
|
||||
|
||||
-- | Given a path to a HTML file, return its relative URL
|
||||
|
Loading…
Reference in New Issue
Block a user