packages feed

path-extra (empty) → 0.0.0

raw patch · 3 files changed

+171/−0 lines, 3 filesdep +basedep +path

Dependencies added: base, path

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Athan Clark++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 Athan Clark 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.
+ path-extra.cabal view
@@ -0,0 +1,22 @@+Name:                   path-extra+Version:                0.0.0+Author:                 Athan Clark <athan.clark@gmail.com>+Maintainer:             Athan Clark <athan.clark@gmail.com>+License:                BSD3+License-File:           LICENSE+Synopsis:               Chris Done's path library, enriched with URL-related goodies.+-- Description:+Cabal-Version:          >= 1.10+Build-Type:             Simple++Library+  Default-Language:     Haskell2010+  HS-Source-Dirs:       src+  GHC-Options:          -Wall+  Exposed-Modules:      Path.Extended+  Build-Depends:        base >= 4.6 && < 5+                      , path++Source-Repository head+  Type:                 git+  Location:             https://github.com/athanclark/path-extra.git
+ src/Path/Extended.hs view
@@ -0,0 +1,119 @@+module Path.Extended+  ( -- * Types+    Location+  , QueryParam+    -- * Combinators+    -- ** Parent Accessors+  , addParent+  , delParent+    -- ** Path+  , fromPath+    -- ** File Extensions+  , setFileExt+  , addFileExt+  , delFileExt+  , getFileExt+    -- ** Query Parameters+  , setQuery+  , addQuery+  , addQueries+  , delQuery+  , getQuery+    -- ** Fragment+  , setFragment+  , addFragment+  , delFragment+  , module P+  ) where++import Path as P+import Data.List (intercalate)+++-- | A location for some base and type - internally uses @Path@.+data Location b t = Location+  { locParentJumps :: Int -- ^ only when b ~ Rel+  , locPath        :: Path b t+  , locFileExt     :: Maybe String -- ^ only when t ~ File+  , locQueryParams :: [QueryParam]+  , locFragment    :: Maybe String+  } deriving (Eq, Ord)++instance Show (Location b t) where+  show (Location js pa fe qp fr) =+    let loc = concat (replicate js "../")+           ++ toFilePath pa+           ++ maybe "" (\f -> "." ++ f) fe+        query = case qp of+                  [] -> ""+                  qs -> "?" ++ intercalate "&" (map go qs)+          where+            go (k,mv) = k ++ maybe "" (\v -> "=" ++ v) mv+    in loc ++ query ++ maybe "" (\f -> "#" ++ f) fr++type QueryParam = (String, Maybe String)++++-- | Prepend a parental accessor path - @../@+addParent :: Location Rel t -> Location Rel t+addParent (Location j pa fe qp fr) =+  Location (j+1) pa fe qp fr++delParent :: Location Rel t -> Location Rel t+delParent l@(Location j pa fe qp fr)+  | j <= 0    = l+  | otherwise = Location (j-1) pa fe qp fr+++-- | This should be your entry point for creating a @Location@.+fromPath :: Path b t -> Location b t+fromPath pa = Location 0 pa Nothing [] Nothing+++setFileExt :: Maybe String -> Location b File -> Location b File+setFileExt fe (Location js pa _ qp fr) =+  Location js pa fe qp fr++addFileExt :: String -> Location b File -> Location b File+addFileExt fe = setFileExt (Just fe)++delFileExt :: Location b File -> Location b File+delFileExt = setFileExt Nothing++getFileExt :: Location b File -> Maybe String+getFileExt (Location _ _ fe _ _) =+  fe+++setQuery :: [QueryParam] -> Location b t -> Location b t+setQuery qp (Location js pa fe _ fr) =+  Location js pa fe qp fr++-- | Appends a query parameter+addQuery :: QueryParam -> Location b t -> Location b t+addQuery q (Location js pa fe qp fr) =+  Location js pa fe (qp ++ [q]) fr++addQueries :: [QueryParam] -> Location b t -> Location b t+addQueries qs (Location js pa fe qs' fr) =+  Location js pa fe (qs' ++ qs) fr++delQuery :: Location b t -> Location b t+delQuery = setQuery []++getQuery :: Location b t -> [QueryParam]+getQuery (Location _ _ _ qp _) =+  qp+++setFragment :: Maybe String -> Location b t -> Location b t+setFragment fr (Location js pa fe qp _) =+  Location js pa fe qp fr++addFragment :: String -> Location b t -> Location b t+addFragment fr = setFragment (Just fr)++delFragment :: Location b t -> Location b t+delFragment = setFragment Nothing+