1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE OverloadedStrings #-}
4 {-# LANGUAGE UndecidableInstances #-}
5 {-# LANGUAGE NoMonomorphismRestriction #-}
6 {-# OPTIONS_GHC -Wno-missing-signatures #-}
8 module Examples.Ex02 where
10 import Data.Either (Either (..))
12 import Data.Function (($), (.))
13 import Data.Maybe (Maybe (..))
15 import Data.Set qualified as Set
16 import GHC.Generics (Generic)
17 import Network.URI.Slug qualified as URI
18 import Symantic.Classes (
27 import Symantic.Reader (Reader (..))
28 import Text.Show (Show)
36 -- SitePage [URI.Slug]
37 -- SiteSpecial [URI.Slug]
38 deriving (Eq, Show, Generic)
40 instance Renderable Site where
41 render Comp{..} = case compValue of
42 SiteFeeds -> Right ("feeds", "txt")
43 SiteFilter _fil -> Right ("filter", "txt")
44 SiteStatic -> Left $ pathOfSlugs compSlugs
47 gen0 = generate (unReader site model0)
51 encode (unReader site model0) $
54 { filterLang = Just LangFr
61 <+> literalSlug "feed"
62 <+> "filter" </> infer
65 -- ("page" </> many1 (captureSlug "page"))
67 -- ("special" </> many1 (captureSlug "page"))
71 { filterLang :: Maybe Lang
72 , filterTag :: Maybe Tag
74 deriving (Eq, Show, Generic)
87 infer = adt @Filter $ adt (literalSlug "all" <+> infer) <.> optional infer
90 data Lang = LangEn | LangFr deriving (Eq, Show, Generic)
91 instance (IsoFunctor repr, SumFunctor repr, Slugable repr) => Inferable Lang repr where
92 infer = adt @Lang $ literalSlug "fr" <+> literalSlug "en"
96 { modelTags :: Set URI.Slug
100 model0 = Model{modelTags = Set.fromList ["tag0", "tag1"]}
103 newtype Tag = Tag {unTag :: URI.Slug} deriving (Eq, Show)
105 instance (IsoFunctor repr, Slugable repr) => Inferable Tag (Reader Model repr) where
106 infer = Reader $ (Iso Tag unTag <%>) . chooseSlug . modelTags