mirror of
https://github.com/aelve/guide.git
synced 2024-11-24 05:45:11 +03:00
Extract routes- / url-helper into *.Common.*
This commit is contained in:
parent
2968979823
commit
3c8f552597
@ -4,11 +4,13 @@ import Prelude
|
||||
|
||||
import Data.Generic (class Generic, gEq, gShow)
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Pux.Router (end, lit, router, str)
|
||||
import Guide.Api.Types (CUid(..))
|
||||
import Guide.Common.Routes (categoryLit, categoryDetailUrl)
|
||||
import Guide.Common.Types (CategoryName(..))
|
||||
import Pux.Router (end, lit, router, str)
|
||||
|
||||
data Route
|
||||
= CategoryDetail CategoryName String
|
||||
= CategoryDetail CategoryName (CUid String)
|
||||
| NotFound String
|
||||
|
||||
derive instance genericRoute :: Generic Route
|
||||
@ -21,20 +23,8 @@ instance eqRoute :: Eq Route where
|
||||
match :: String -> Route
|
||||
match url = fromMaybe (NotFound url) $ router url $
|
||||
CategoryDetail <<< CategoryName <$> (lit categoryLit *> str)
|
||||
<*> str <* end
|
||||
<*> (CUid <$> str) <* end
|
||||
|
||||
toURL :: Route -> String
|
||||
toURL (NotFound url) = url
|
||||
toURL (CategoryDetail catName catId) = categoryDetailUrl catName catId
|
||||
|
||||
litUrl :: String -> String
|
||||
litUrl lit = "/" <> lit
|
||||
|
||||
categoryLit :: String
|
||||
categoryLit = "category"
|
||||
|
||||
categoryUrl :: CategoryName -> String
|
||||
categoryUrl (CategoryName name) = (litUrl categoryLit) <> (litUrl name)
|
||||
|
||||
categoryDetailUrl :: CategoryName -> String -> String
|
||||
categoryDetailUrl catName catId = (categoryUrl catName) <> (litUrl catId)
|
||||
|
@ -5,6 +5,7 @@ import Prelude
|
||||
import Data.Generic (class Generic, gEq, gShow)
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Pux.Router (end, lit, router, str)
|
||||
import Guide.Common.Routes (categoryLit, categoryUrl)
|
||||
import Guide.Common.Types (CategoryName(..))
|
||||
|
||||
data Route
|
||||
@ -24,12 +25,3 @@ match url = fromMaybe (NotFound url) $ router url $
|
||||
toURL :: Route -> String
|
||||
toURL (NotFound url) = url
|
||||
toURL (CategoryOverview catName) = categoryUrl catName
|
||||
|
||||
litUrl :: String -> String
|
||||
litUrl lit = "/" <> lit
|
||||
|
||||
categoryLit :: String
|
||||
categoryLit = "category"
|
||||
|
||||
categoryUrl :: CategoryName -> String
|
||||
categoryUrl (CategoryName name) = (litUrl categoryLit) <> (litUrl name)
|
||||
|
18
front-ps/common/Guide/Common/Routes.purs
Normal file
18
front-ps/common/Guide/Common/Routes.purs
Normal file
@ -0,0 +1,18 @@
|
||||
module Guide.Common.Routes where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Guide.Api.Types (CUid(..))
|
||||
import Guide.Common.Types (CategoryName(..))
|
||||
|
||||
litUrl :: String -> String
|
||||
litUrl lit = "/" <> lit
|
||||
|
||||
categoryLit :: String
|
||||
categoryLit = "category"
|
||||
|
||||
categoryUrl :: CategoryName -> String
|
||||
categoryUrl (CategoryName name) = (litUrl categoryLit) <> (litUrl name)
|
||||
|
||||
categoryDetailUrl :: forall a. CategoryName -> CUid a -> String
|
||||
categoryDetailUrl catName (CUid catId) = (categoryUrl catName) <> (litUrl catId)
|
Loading…
Reference in New Issue
Block a user