packages feed

saferoute (empty) → 0.0.0.0

raw patch · 6 files changed

+135/−0 lines, 6 filesdep +basedep +blaze-htmldep +containerssetup-changed

Dependencies added: base, blaze-html, containers, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Peter Harpending++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Peter Harpending nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,3 @@+# saferoute++This is a really simple Haskell library for type-safe routing.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ saferoute.cabal view
@@ -0,0 +1,42 @@+-- Initial saferoute.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                saferoute+version:             0.0.0.0+synopsis:            A simple type-safe routing library.+description:         +  saferoute is a type-safe routing library for web applications.+license:             BSD3+license-file:        LICENSE+author:              Peter Harpending+maintainer:          Peter Harpending <pharpend2@gmail.com>+copyright:           2014, Peter Harpending+category:            Web+build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10++flag blaze+  description: Support for blaze-html attribute embedding.+  default:     True++library+  exposed-modules:     +      Web.Saferoute+  -- other-modules:       +  other-extensions:    +  build-depends:+      base       >=4.7 && <4.8+    , containers >=0.5 && <0.6+    , text       >=1.1 && <1.2+  hs-source-dirs:      src/+  default-language:    Haskell2010+  ghc-options:         -Wall++  if flag(blaze)+    exposed-modules: Web.Saferoute.Blaze+    build-depends:   blaze-html >=0.7 && <0.8++source-repository head+  type:     git+  location: https://github.com/pharpend/saferoute.git
+ src/Web/Saferoute.hs view
@@ -0,0 +1,41 @@+-- |+-- Module       : Web.Saferoute+-- Description  : Type-safe routing for web applications.+-- Copyright    : 2014, Peter Harpending.+-- License      : BSD3+-- Maintainer   : Peter Harpending <pharpend2@gmail.com>+-- Stability    : experimental+-- Portability  : archlinux+--++module Web.Saferoute where++import qualified Data.Map.Lazy  as M+import qualified Data.Text.Lazy as L++-- |The type for a route - just an alias for 'L.Text'+type Route = L.Text++-- |The type class for a resource.+class Eq r => Resource r where+  {-# MINIMAL getRoute, (resourceList | routeResourceMap) #-}++  -- Get the 'Route' for a 'Resource'. This is in place to avoid+  -- @fmap@ stuff. Giving a 'Resource' to this function will+  -- invariably return a 'Route', as opposed to 'Maybe Route', which+  -- would be the case if I used a 'M.Map' lookup.+  getRoute :: r -> Route++  -- |A list of all of the constructors for your resource type.+  resourceList :: [r]+  resourceList = M.elems routeResourceMap++  -- |A map from a route to it's resource.+  routeResourceMap :: M.Map Route r+  routeResourceMap = M.fromList [(route, resource) | resource <- resourceList,+                                                     let route = getRoute resource ]++  -- |Given a 'Route', find the 'Resource' behind it. If the route+  -- isn't associated with any 'Resource', this returns 'Nothing'.+  lookupRoute :: Route -> Maybe r+  lookupRoute route = M.lookup route routeResourceMap
+ src/Web/Saferoute/Blaze.hs view
@@ -0,0 +1,17 @@+-- |+-- Module       : Web.Saferoute.Blaze+-- Description  : Support for blaze-html+-- Copyright    : 2014, Peter Harpending.+-- License      : BSD3+-- Maintainer   : Peter Harpending <pharpend2@gmail.com>+-- Stability    : experimental+-- Portability  : archlinux+--++module Web.Saferoute.Blaze where++import qualified Text.Blaze.Html5 as H+import           Web.Saferoute++getUrl :: Resource r => r -> H.AttributeValue+getUrl = H.toValue . getRoute