generated from srid/ema-template
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from srid/ext-kind
Polymorphic file-ext in Route and Source
- Loading branch information
Showing
11 changed files
with
182 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,44 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
module Emanote.Class where | ||
|
||
import Control.Lens.Operators ((^.)) | ||
import qualified Data.IxSet.Typed as Ix | ||
import qualified Data.Set as Set | ||
import Ema (Ema (..)) | ||
import Emanote.Model (Model) | ||
import qualified Emanote.Model as M | ||
import Emanote.Route (MarkdownRoute) | ||
import qualified Emanote.Model.Note as N | ||
import Emanote.Route (Route) | ||
import qualified Emanote.Route as R | ||
import Emanote.Route.Ext (FileType (Html, LMLType, OtherExt)) | ||
|
||
-- | TODO: Use `OpenUnion` here? | ||
data EmanoteRoute | ||
= ERNoteHtml (Route 'Html) | ||
| EROtherFile (Route 'OtherExt) | ||
deriving (Eq, Show, Ord) | ||
|
||
instance Ema Model EmanoteRoute where | ||
encodeRoute = \case | ||
ERNoteHtml r -> | ||
R.encodeRoute r | ||
EROtherFile r -> | ||
R.encodeRoute r | ||
|
||
instance Ema Model (Either FilePath MarkdownRoute) where | ||
encodeRoute = | ||
either id R.encodeRoute | ||
decodeRoute model fp = | ||
fmap Left (M.modelLookupStaticFile fp model) | ||
<|> fmap Right (R.decodeRoute fp) | ||
allRoutes = M.allRoutes | ||
fmap EROtherFile (M.modelLookupStaticFile fp model) | ||
<|> fmap ERNoteHtml (R.decodeHtmlRoute fp) | ||
allRoutes model = | ||
let htmlRoutes = | ||
model ^. M.modelNotes | ||
& Ix.toList | ||
<&> htmlRouteForLmlRoute . (^. N.noteRoute) | ||
staticFiles = | ||
Set.toList $ model ^. M.modelStaticFiles | ||
in fmap ERNoteHtml htmlRoutes | ||
<> fmap EROtherFile staticFiles | ||
|
||
htmlRouteForLmlRoute :: Route ('LMLType x) -> Route 'Html | ||
htmlRouteForLmlRoute = coerce |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.