Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/node_modules/
/bower_components/
/tmp/
/dist/
/output/
/coverage/
public/*.js
.psci_modules
.psci
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: node_js
node_js:
- 0.10
env:
- TAG=v0.6.8
install:
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- sudo tar zxvf $HOME/purescript.tar.gz -C /usr/local/bin purescript/psc{,i,-docs,-make} --strip-components=1
- sudo chmod a+x /usr/local/bin/psc{,i,-docs,-make}
- npm install bower gulp -g
- npm install && bower install
script:
- gulp bundle-test
209 changes: 209 additions & 0 deletions MODULES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
# Module Documentation

## Module Routing

#### `hashChanged`

``` purescript
hashChanged :: forall e. (String -> String -> Eff e Unit) -> Eff e Unit
```


#### `hashes`

``` purescript
hashes :: forall e. (String -> String -> Eff e Unit) -> Eff e Unit
```


#### `matches`

``` purescript
matches :: forall e a. Match a -> (Maybe a -> a -> Eff e Unit) -> Eff e Unit
```


#### `matchHash`

``` purescript
matchHash :: forall a. Match a -> String -> Either String a
```



## Module Routing.Match

#### `Match`

``` purescript
newtype Match a
= Match (Route -> Either String (Tuple Route a))
```


#### `matchMatchClass`

``` purescript
instance matchMatchClass :: MatchClass Match
```


#### `matchFunctor`

``` purescript
instance matchFunctor :: Functor Match
```


#### `matchAlt`

``` purescript
instance matchAlt :: Alt Match
```


#### `matchPlus`

``` purescript
instance matchPlus :: Plus Match
```


#### `matchAlternative`

``` purescript
instance matchAlternative :: Alternative Match
```


#### `matchApply`

``` purescript
instance matchApply :: Apply Match
```


#### `matchApplicative`

``` purescript
instance matchApplicative :: Applicative Match
```


#### `matchBind`

``` purescript
instance matchBind :: Bind Match
```


#### `matchMonad`

``` purescript
instance matchMonad :: Monad Match
```


#### `matchMonadPlus`

``` purescript
instance matchMonadPlus :: MonadPlus Match
```


#### `runMatch`

``` purescript
runMatch :: forall a. Match a -> Route -> Either String a
```



## Module Routing.Parser

#### `parse`

``` purescript
parse :: String -> Route
```



## Module Routing.Setter

#### `setHash`

``` purescript
setHash :: forall e. String -> Eff e Unit
```


#### `RouteState`

``` purescript
class RouteState a where
toHash :: a -> String
```

Class of types that can be converted to hashes

#### `setRouteState`

``` purescript
setRouteState :: forall r e. (RouteState r) => r -> Eff e Unit
```

wrapper over `setHash` that uses `RouteState`


## Module Routing.Types

#### `RoutePart`

``` purescript
data RoutePart
= Path String
| Query (M.StrMap String)
```


#### `Route`

``` purescript
type Route = [RoutePart]
```



## Module Routing.Match.Class

#### `MatchClass`

``` purescript
class (MonadPlus f) <= MatchClass f where
lit :: String -> f Unit
var :: f String
param :: String -> f String
fail :: forall a. String -> f a
```



## Module Routing.Match.Combinators

#### `num`

``` purescript
num :: forall f. (MatchClass f) => String -> f Number
```


#### `bool`

``` purescript
bool :: forall f. (MatchClass f) => String -> f Boolean
```




4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# purescript-routing

[![Build Status](https://travis-ci.org/cryogenian/purescript-routing.svg?branch=master)](https://travis-ci.org/cryogenian/purescript-routing)

35 changes: 35 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "purescript-routing",
"homepage": "https://github.com/slamdata/purescript-routing",
"authors": [
"Maxim Zimaliev <zimaliev@yandex.ru>"
],
"description": "purescript library for routing",
"keywords": [
"purescript",
"routing"
],
"license": "Apache 2.0",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"purescript-strings": "~0.4.3",
"purescript-maps": "~0.3.2",
"purescript-control": "~0.2.2",
"purescript-transformers": "~0.5.1",
"purescript-arrays": "~0.3.3",
"purescript-monoid": "~0.2.0",
"purescript-validation": "~0.1.1",
"purescript-semirings": "~0.1.1"
},
"devDependencies": {
"purescript-timers": "~0.0.8",
"purescript-debug-foreign": "~0.0.4",
"purescript-globals": "~0.1.5"
}
}
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("mandragora-bucket").define();
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "purescript-routing",
"description": "Routing lib for purescript",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/slamdata/purescript-routing.git"
},
"keywords": [
"purescript",
"routing"
],
"author": "Maxim Zimaliev <zimaliev@gmail.com>",
"license": "Apache 2.0",
"bugs": {
"url": "https://github.com/slamdata/purescript-routing/issues"
},
"homepage": "https://github.com/slamdata/purescript-routing",
"dependencies": {
"gulp": "^3.8.11",
"mandragora-bucket": "^0.1.12"
}
}
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script src="./concated.js"></script>
39 changes: 39 additions & 0 deletions src/Routing.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Routing where

import Control.Monad.Eff
import Data.Maybe
import Data.Either
import qualified Data.String.Regex as R

import Routing.Parser
import Routing.Match

foreign import hashChanged """
function hashChanged(handler) {
return function() {
var currentHash = document.location.hash;
handler("")(currentHash)();
window.addEventListener("hashchange", function(ev) {
handler(ev.oldURL)(ev.newURL)();
});
};
}
""" :: forall e. (String -> String -> Eff e Unit) -> Eff e Unit


hashes :: forall e. (String -> String -> Eff e Unit) -> Eff e Unit
hashes cb =
hashChanged $ \old new -> do
cb (dropHash old) (dropHash new)
where dropHash h = R.replace (R.regex "^[^#]*#" R.noFlags) "" h


matches :: forall e a. Match a -> (Maybe a -> a -> Eff e Unit) -> Eff e Unit
matches routing cb = hashes $ \old new ->
let mr = matchHash routing
fst = either (const Nothing) Just $ mr old
in either (const $ pure unit) (cb fst) $ mr new


matchHash :: forall a. Match a -> String -> Either String a
matchHash matcher hash = runMatch matcher $ parse hash
Loading