web-routes-regular (empty) → 0.18
raw patch · 3 files changed
+68/−0 lines, 3 filesdep +basedep +parsecdep +regularsetup-changed
Dependencies added: base, parsec, regular, web-routes
Files
- Setup.hs +2/−0
- Web/Routes/Regular.hs +47/−0
- web-routes-regular.cabal +19/−0
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Web/Routes/Regular.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE TypeOperators, ScopedTypeVariables #-}+module Web.Routes.Regular where++import Control.Applicative hiding ((<|>))+import Data.Char (toLower)+import Generics.Regular+import Text.ParserCombinators.Parsec.Prim+import Text.ParserCombinators.Parsec.Combinator+import Web.Routes.PathInfo (PathInfo(fromPathSegments, toPathSegments), URLParser, segment)++class GToURL f where+ gtoPathSegments :: f a -> [String]+ gfromPathSegments :: URLParser (f a)++instance PathInfo a => GToURL (K a) where + gtoPathSegments (K a) = toPathSegments a+ gfromPathSegments = K <$> fromPathSegments ++instance (GToURL f, GToURL g) => GToURL (f :+: g) where+ gtoPathSegments (L x) = gtoPathSegments x+ gtoPathSegments (R y) = gtoPathSegments y+ gfromPathSegments = try (L <$> gfromPathSegments) <|> (R <$> gfromPathSegments)+ +instance (GToURL f, GToURL g) => GToURL (f :*: g) where+ gtoPathSegments (x :*: y) = gtoPathSegments x ++ gtoPathSegments y+ gfromPathSegments =+ do x <- gfromPathSegments+ y <- gfromPathSegments+ return (x :*: y)++instance GToURL U where+ gtoPathSegments U = []+ gfromPathSegments = eof >> return U++instance GToURL f => GToURL (S s f) where+ gtoPathSegments (S x) = gtoPathSegments x+ gfromPathSegments = S <$> gfromPathSegments++lower :: String -> String+lower = map toLower++instance forall c f. (Constructor c, GToURL f) => GToURL (C c f) where+ gtoPathSegments c@(C x) = (lower $ conName c) : gtoPathSegments x+ gfromPathSegments = + let constr = undefined :: C c f r+ in do segment (lower $ conName constr) <|> segment (conName constr)+ C <$> gfromPathSegments
+ web-routes-regular.cabal view
@@ -0,0 +1,19 @@+Name: web-routes-regular+Version: 0.18+License: BSD3+Author: jeremy@seereason.com+Maintainer: partners@seereason.com+Bug-Reports: http://bugzilla.seereason.com/+Category: Web, Language+Synopsis: Library for maintaining correctness of URLs within an application.+Description: A collection of types and functions that ensure that URLs generated by an application are valid. Need more properties here.+Cabal-Version: >= 1.6+Build-type: Simple++Library+ Build-Depends: base >= 4 && < 5, parsec >= 2 && <3, regular, web-routes >= 0.18+ Exposed-Modules: Web.Routes.Regular++source-repository head+ type: darcs+ location: http://src.seereason.com/web-routes/