eyeballs 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README.md +16 -0
- data/Rakefile +1 -1
- data/dist/jquery/jquery.ba-hashchange.js +1 -0
- data/eyeballs.gemspec +2 -2
- data/src/drivers/jquery/modules/o_O.routes.js +34 -15
- data/src/drivers/jquery/modules/o_O.support.js +4 -0
- data/test/unit/test_routing.html +45 -5
- metadata +4 -4
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -237,6 +237,22 @@ You can now bind this to particular links, by adding the `data-ajax-history` att
|
|
237
237
|
|
238
238
|
This link will now call `PostsController.new()` when it is clicked.
|
239
239
|
|
240
|
+
If you want a default action to fire, that is when the `document.hash` is empty, just hook up a `map.root`:
|
241
|
+
|
242
|
+
o_O.routes.draw(function(map){
|
243
|
+
map.root({to: 'posts#index'})
|
244
|
+
})
|
245
|
+
|
246
|
+
If you have several routes that share the same prefix, you can use a namespace:
|
247
|
+
|
248
|
+
o_O.routes.draw(function(map){
|
249
|
+
map.namespace('my', function(){
|
250
|
+
map.match('posts/new', {to: "myposts#new"}) # hooks up to MypostsController.new()
|
251
|
+
})
|
252
|
+
})
|
253
|
+
|
254
|
+
Tasty!
|
255
|
+
|
240
256
|
#### Binding actions to events ####
|
241
257
|
|
242
258
|
To bind events to these controller actions, use the data-controller and data-action attributes:
|
data/Rakefile
CHANGED
data/eyeballs.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{eyeballs}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Paul Campbell"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-07}
|
13
13
|
s.default_executable = %q{eyeballs}
|
14
14
|
s.email = %q{paul@rslw.com}
|
15
15
|
s.executables = ["eyeballs"]
|
@@ -3,30 +3,49 @@ o_O.routes = {
|
|
3
3
|
rules: {},
|
4
4
|
urls: [],
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
figure_action: function(options){
|
7
|
+
var parts = options.to.split('#');
|
8
|
+
var controller = parts[0];
|
9
|
+
var action = parts[1];
|
10
|
+
|
11
|
+
controller = controller.capitalize() + "Controller";
|
12
|
+
return window[controller][action];
|
13
|
+
},
|
14
|
+
|
15
|
+
router: function(prefix){
|
16
|
+
return {
|
17
|
+
root: function(options){
|
18
|
+
o_O.routes.rules['root'] = {"action": o_O.routes.figure_action(options)}
|
19
|
+
},
|
20
|
+
namespace: function(prefix, callback){
|
21
|
+
callback(o_O.routes.router(prefix));
|
22
|
+
},
|
23
|
+
match: function(route, options){
|
24
|
+
var parsed_route = route.o_O_trim('/')
|
25
|
+
if(typeof prefix != 'undefined')
|
26
|
+
{
|
27
|
+
parsed_route = prefix + '/' + parsed_route
|
28
|
+
}
|
29
|
+
o_O.routes.rules[parsed_route] = {"action": o_O.routes.figure_action(options), "with": options.with};
|
30
|
+
o_O.routes.urls.push(parsed_route);
|
16
31
|
}
|
17
|
-
|
18
|
-
o_O.routes.rules[route] = {"action": figure_action(options), "with": options.with};
|
19
|
-
o_O.routes.urls.push(route);
|
20
32
|
}
|
21
33
|
},
|
22
34
|
|
23
35
|
draw: function(callback){
|
24
36
|
$(function(){
|
25
37
|
|
26
|
-
callback(o_O.routes.router);
|
38
|
+
callback(o_O.routes.router());
|
39
|
+
if(location.hash.o_O_trim() == '')
|
40
|
+
{
|
41
|
+
if(typeof o_O.routes.rules['root'] === 'object')
|
42
|
+
{
|
43
|
+
o_O.routes.rules['root'].action();
|
44
|
+
}
|
45
|
+
}
|
27
46
|
|
28
47
|
$(window).bind( 'hashchange', function(){
|
29
|
-
var hash = location.hash.replace(/^(#)/, '');
|
48
|
+
var hash = location.hash.replace(/^(#)/, '').o_O_trim('/');
|
30
49
|
if(o_O.routes.urls.indexOf(hash) >= 0)
|
31
50
|
{
|
32
51
|
o_O.routes.rules[hash].action(o_O.routes.rules[hash].with);
|
@@ -66,4 +66,8 @@ if(typeof String.prototype.capitalize == 'undefined')
|
|
66
66
|
String.prototype.capitalize = function(){
|
67
67
|
return this.charAt(0).toUpperCase() + this.slice(1);
|
68
68
|
}
|
69
|
+
}
|
70
|
+
|
71
|
+
String.prototype.o_O_trim = function(chars) {
|
72
|
+
return this.replace(new RegExp("(^[" + chars + "]+|[" + chars + "]+$)", "g"), '')
|
69
73
|
}
|
data/test/unit/test_routing.html
CHANGED
@@ -19,6 +19,9 @@
|
|
19
19
|
|
20
20
|
<script>
|
21
21
|
o_O('ReviewsController', {
|
22
|
+
root: function(){
|
23
|
+
$('div#root').html('rooting for you')
|
24
|
+
},
|
22
25
|
index: function(bit){
|
23
26
|
var out;
|
24
27
|
if(bit == 'test')
|
@@ -31,23 +34,48 @@
|
|
31
34
|
}
|
32
35
|
$('div#index').html(out);
|
33
36
|
return 'whoop!'
|
37
|
+
},
|
38
|
+
namespaced_index: function(bit){
|
39
|
+
var out;
|
40
|
+
if(bit == 'test')
|
41
|
+
{
|
42
|
+
out = 'namespaced and clicked!'
|
43
|
+
}
|
44
|
+
else
|
45
|
+
{
|
46
|
+
out = 'namespaced and indexed!'
|
47
|
+
}
|
48
|
+
$('div#namespaced-index').html(out);
|
49
|
+
return 'awesome!'
|
34
50
|
}
|
35
51
|
});
|
36
52
|
|
37
53
|
o_O.routes.draw(function(map){
|
38
|
-
map.
|
54
|
+
map.root({to: "reviews#root"})
|
55
|
+
map.match('/reviews/index/', {to: "reviews#index", with: 'test'});
|
56
|
+
map.namespace('my', function(my){
|
57
|
+
my.match('action', {to: "reviews#namespaced_index", with: 'test'})
|
58
|
+
})
|
39
59
|
})
|
40
60
|
|
41
61
|
$(document).ready(function(){
|
42
62
|
|
43
|
-
module("
|
63
|
+
module("Routing", {teardown: function(){
|
64
|
+
document.location.hash = ''
|
65
|
+
}});
|
44
66
|
|
45
67
|
test('o_O.routes.urls', function(){
|
46
|
-
equals(o_O.routes.urls[0], '/', 'should store the necessary URLs')
|
68
|
+
equals(o_O.routes.urls[0], 'reviews/index', 'should store the necessary URLs')
|
69
|
+
equals(o_O.routes.urls[1], 'my/action', 'should store the necessary URLs')
|
47
70
|
})
|
48
71
|
|
49
72
|
test('o_O.routes.rules', function(){
|
50
|
-
equals(o_O.routes.rules['/'].action(), ReviewsController.index())
|
73
|
+
equals(o_O.routes.rules['reviews/index'].action(), ReviewsController.index())
|
74
|
+
equals(o_O.routes.rules['my/action'].action(), ReviewsController.namespaced_index())
|
75
|
+
})
|
76
|
+
|
77
|
+
test('o_O.routes.root', function(){
|
78
|
+
equals($('div#root').html(), 'rooting for you');
|
51
79
|
})
|
52
80
|
|
53
81
|
asyncTest('map.match',function(){
|
@@ -57,6 +85,14 @@
|
|
57
85
|
start();
|
58
86
|
},100)
|
59
87
|
})
|
88
|
+
|
89
|
+
asyncTest('map.namespace',function(){
|
90
|
+
$('a#namespaced-index-link').trigger('click');
|
91
|
+
setTimeout(function(){
|
92
|
+
equals($('div#namespaced-index').html(), 'namespaced and clicked!', "should call the action");
|
93
|
+
start();
|
94
|
+
},100)
|
95
|
+
})
|
60
96
|
|
61
97
|
});
|
62
98
|
</script>
|
@@ -68,9 +104,13 @@
|
|
68
104
|
<h2 id="qunit-userAgent"></h2>
|
69
105
|
<ol id="qunit-tests"></ol>
|
70
106
|
|
71
|
-
<a id="index-link" data-ajax-history="true" href="/">Hello!</a>
|
107
|
+
<a id="index-link" data-ajax-history="true" href="/reviews/index">Hello!</a>
|
108
|
+
<a id="namespaced-index-link" data-ajax-history="true" href="/my/action">Hello!</a>
|
72
109
|
|
73
110
|
<div id="index">
|
74
111
|
</div>
|
112
|
+
<div id="namespaced-index">
|
113
|
+
</div>
|
114
|
+
<div id="root"></div>
|
75
115
|
</body>
|
76
116
|
</html>
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eyeballs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 2
|
10
|
+
version: 0.4.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Campbell
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-07 00:00:00 +01:00
|
19
19
|
default_executable: eyeballs
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|