Skip to content

Commit e888836

Browse files
committed
Merge pull request #3 from cryogenian/other
Other
2 parents 7ca8e3c + 99d05ae commit e888836

File tree

16 files changed

+576
-0
lines changed

16 files changed

+576
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/node_modules/
2+
/bower_components/
3+
/tmp/
4+
/dist/
5+
/output/
6+
/coverage/
7+
public/*.js
8+
.psci_modules
9+
.psci

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: node_js
2+
node_js:
3+
- 0.10
4+
env:
5+
- TAG=v0.6.8
6+
install:
7+
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
8+
- sudo tar zxvf $HOME/purescript.tar.gz -C /usr/local/bin purescript/psc{,i,-docs,-make} --strip-components=1
9+
- sudo chmod a+x /usr/local/bin/psc{,i,-docs,-make}
10+
- npm install bower gulp -g
11+
- npm install && bower install
12+
script:
13+
- gulp bundle-test

MODULES.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Module Documentation
2+
3+
## Module Routing
4+
5+
#### `hashChanged`
6+
7+
``` purescript
8+
hashChanged :: forall e. (String -> String -> Eff e Unit) -> Eff e Unit
9+
```
10+
11+
12+
#### `hashes`
13+
14+
``` purescript
15+
hashes :: forall e. (String -> String -> Eff e Unit) -> Eff e Unit
16+
```
17+
18+
19+
#### `matches`
20+
21+
``` purescript
22+
matches :: forall e a. Match a -> (Maybe a -> a -> Eff e Unit) -> Eff e Unit
23+
```
24+
25+
26+
#### `matchHash`
27+
28+
``` purescript
29+
matchHash :: forall a. Match a -> String -> Either String a
30+
```
31+
32+
33+
34+
## Module Routing.Match
35+
36+
#### `Match`
37+
38+
``` purescript
39+
newtype Match a
40+
= Match (Route -> Either String (Tuple Route a))
41+
```
42+
43+
44+
#### `matchMatchClass`
45+
46+
``` purescript
47+
instance matchMatchClass :: MatchClass Match
48+
```
49+
50+
51+
#### `matchFunctor`
52+
53+
``` purescript
54+
instance matchFunctor :: Functor Match
55+
```
56+
57+
58+
#### `matchAlt`
59+
60+
``` purescript
61+
instance matchAlt :: Alt Match
62+
```
63+
64+
65+
#### `matchPlus`
66+
67+
``` purescript
68+
instance matchPlus :: Plus Match
69+
```
70+
71+
72+
#### `matchAlternative`
73+
74+
``` purescript
75+
instance matchAlternative :: Alternative Match
76+
```
77+
78+
79+
#### `matchApply`
80+
81+
``` purescript
82+
instance matchApply :: Apply Match
83+
```
84+
85+
86+
#### `matchApplicative`
87+
88+
``` purescript
89+
instance matchApplicative :: Applicative Match
90+
```
91+
92+
93+
#### `matchBind`
94+
95+
``` purescript
96+
instance matchBind :: Bind Match
97+
```
98+
99+
100+
#### `matchMonad`
101+
102+
``` purescript
103+
instance matchMonad :: Monad Match
104+
```
105+
106+
107+
#### `matchMonadPlus`
108+
109+
``` purescript
110+
instance matchMonadPlus :: MonadPlus Match
111+
```
112+
113+
114+
#### `runMatch`
115+
116+
``` purescript
117+
runMatch :: forall a. Match a -> Route -> Either String a
118+
```
119+
120+
121+
122+
## Module Routing.Parser
123+
124+
#### `parse`
125+
126+
``` purescript
127+
parse :: String -> Route
128+
```
129+
130+
131+
132+
## Module Routing.Setter
133+
134+
#### `setHash`
135+
136+
``` purescript
137+
setHash :: forall e. String -> Eff e Unit
138+
```
139+
140+
141+
#### `RouteState`
142+
143+
``` purescript
144+
class RouteState a where
145+
toHash :: a -> String
146+
```
147+
148+
Class of types that can be converted to hashes
149+
150+
#### `setRouteState`
151+
152+
``` purescript
153+
setRouteState :: forall r e. (RouteState r) => r -> Eff e Unit
154+
```
155+
156+
wrapper over `setHash` that uses `RouteState`
157+
158+
159+
## Module Routing.Types
160+
161+
#### `RoutePart`
162+
163+
``` purescript
164+
data RoutePart
165+
= Path String
166+
| Query (M.StrMap String)
167+
```
168+
169+
170+
#### `Route`
171+
172+
``` purescript
173+
type Route = [RoutePart]
174+
```
175+
176+
177+
178+
## Module Routing.Match.Class
179+
180+
#### `MatchClass`
181+
182+
``` purescript
183+
class (MonadPlus f) <= MatchClass f where
184+
lit :: String -> f Unit
185+
var :: f String
186+
param :: String -> f String
187+
fail :: forall a. String -> f a
188+
```
189+
190+
191+
192+
## Module Routing.Match.Combinators
193+
194+
#### `num`
195+
196+
``` purescript
197+
num :: forall f. (MatchClass f) => String -> f Number
198+
```
199+
200+
201+
#### `bool`
202+
203+
``` purescript
204+
bool :: forall f. (MatchClass f) => String -> f Boolean
205+
```
206+
207+
208+
209+

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# purescript-routing
2+
3+
[![Build Status](https://travis-ci.org/cryogenian/purescript-routing.svg?branch=master)](https://travis-ci.org/cryogenian/purescript-routing)
4+

bower.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "purescript-routing",
3+
"homepage": "https://github.com/slamdata/purescript-routing",
4+
"authors": [
5+
"Maxim Zimaliev <zimaliev@yandex.ru>"
6+
],
7+
"description": "purescript library for routing",
8+
"keywords": [
9+
"purescript",
10+
"routing"
11+
],
12+
"license": "Apache 2.0",
13+
"ignore": [
14+
"**/.*",
15+
"node_modules",
16+
"bower_components",
17+
"test",
18+
"tests"
19+
],
20+
"dependencies": {
21+
"purescript-strings": "~0.4.3",
22+
"purescript-maps": "~0.3.2",
23+
"purescript-control": "~0.2.2",
24+
"purescript-transformers": "~0.5.1",
25+
"purescript-arrays": "~0.3.3",
26+
"purescript-monoid": "~0.2.0",
27+
"purescript-validation": "~0.1.1",
28+
"purescript-semirings": "~0.1.1"
29+
},
30+
"devDependencies": {
31+
"purescript-timers": "~0.0.8",
32+
"purescript-debug-foreign": "~0.0.4",
33+
"purescript-globals": "~0.1.5"
34+
}
35+
}

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("mandragora-bucket").define();

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "purescript-routing",
3+
"description": "Routing lib for purescript",
4+
"private": true,
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/slamdata/purescript-routing.git"
8+
},
9+
"keywords": [
10+
"purescript",
11+
"routing"
12+
],
13+
"author": "Maxim Zimaliev <zimaliev@gmail.com>",
14+
"license": "Apache 2.0",
15+
"bugs": {
16+
"url": "https://github.com/slamdata/purescript-routing/issues"
17+
},
18+
"homepage": "https://github.com/slamdata/purescript-routing",
19+
"dependencies": {
20+
"gulp": "^3.8.11",
21+
"mandragora-bucket": "^0.1.12"
22+
}
23+
}

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="./concated.js"></script>

src/Routing.purs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module Routing where
2+
3+
import Control.Monad.Eff
4+
import Data.Maybe
5+
import Data.Either
6+
import qualified Data.String.Regex as R
7+
8+
import Routing.Parser
9+
import Routing.Match
10+
11+
foreign import hashChanged """
12+
function hashChanged(handler) {
13+
return function() {
14+
var currentHash = document.location.hash;
15+
handler("")(currentHash)();
16+
window.addEventListener("hashchange", function(ev) {
17+
handler(ev.oldURL)(ev.newURL)();
18+
});
19+
};
20+
}
21+
""" :: forall e. (String -> String -> Eff e Unit) -> Eff e Unit
22+
23+
24+
hashes :: forall e. (String -> String -> Eff e Unit) -> Eff e Unit
25+
hashes cb =
26+
hashChanged $ \old new -> do
27+
cb (dropHash old) (dropHash new)
28+
where dropHash h = R.replace (R.regex "^[^#]*#" R.noFlags) "" h
29+
30+
31+
matches :: forall e a. Match a -> (Maybe a -> a -> Eff e Unit) -> Eff e Unit
32+
matches routing cb = hashes $ \old new ->
33+
let mr = matchHash routing
34+
fst = either (const Nothing) Just $ mr old
35+
in either (const $ pure unit) (cb fst) $ mr new
36+
37+
38+
matchHash :: forall a. Match a -> String -> Either String a
39+
matchHash matcher hash = runMatch matcher $ parse hash

0 commit comments

Comments
 (0)