eyeballs 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ Wed Nov 3
2
+ - - - - -
3
+ - Support passing in params via the routes
4
+
1
5
  Thu Oct 28
2
6
  - - - - - -
3
7
  - Much more robust support for o_O.params
data/README.md CHANGED
@@ -248,12 +248,20 @@ You can also set params in the URL, eg:
248
248
  })
249
249
 
250
250
  <a href="/posts/1">Click Me for Post 1!</a>
251
+
252
+ or in the route:
253
+
254
+ o_O.routes.draw(function(map){
255
+ map.match('/posts/:id/', {to: 'posts#show', 'custom':'posts'})
256
+ })
257
+
258
+ o_O.params('custom') #=> 'post'
251
259
 
252
260
  and your controller:
253
261
 
254
262
  o_O('PostsController', {
255
- show: function(params){
256
- alert(params('id')) #=> '1'
263
+ show: function(){
264
+ alert(o_O.params('id')) #=> '1'
257
265
  }
258
266
  })
259
267
 
@@ -309,11 +317,11 @@ Imagine a simple app for posting reviews. It will comprise a "Review" model, "Re
309
317
 
310
318
  This defines the Review model, allowing us to initialize and save Review objects, while ensuring `title` and `content` are included.
311
319
 
312
- The `create` action in `controllers/reviews_venue.js` looks like this (using jQuery):
320
+ The `create` action in `controllers/reviews_controller.js` looks like this (using jQuery):
313
321
 
314
322
  ...
315
323
  create: function(){
316
- var review = Review.initialize(o_O.params($(this)));
324
+ var review = Review.initialize(o_O.params('review'));
317
325
  var form = $(this);
318
326
  review.save({o
319
327
  invalid: function(review){
data/Rakefile CHANGED
@@ -27,7 +27,7 @@ begin
27
27
  require 'jeweler'
28
28
  Jeweler::Tasks.new do |s|
29
29
  s.name = "eyeballs"
30
- s.version = "0.5.11"
30
+ s.version = "0.5.12"
31
31
  s.author = "Paul Campbell"
32
32
  s.email = "paul@rslw.com"
33
33
  s.homepage = "http://www.github.com/paulca/eyeballs.js"
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.5.11"
8
+ s.version = "0.5.12"
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-10-28}
12
+ s.date = %q{2010-11-03}
13
13
  s.default_executable = %q{eyeballs}
14
14
  s.email = %q{paul@rslw.com}
15
15
  s.executables = ["eyeballs"]
@@ -28,19 +28,26 @@ o_O.routes = {
28
28
  this.match(name + '/:id', {to:name + '#show'});
29
29
  },
30
30
  match: function(route, options){
31
- var parsed_route = route.o_O_trim('/')
32
-
31
+ var parsed_route = route.o_O_trim('/');
32
+ var params = options;
33
+
34
+ for(var param in options)
35
+ {
36
+ if(param != 'to')
37
+ params[param] = options[param];
38
+ }
39
+
33
40
  if(typeof prefix != 'undefined')
34
41
  {
35
42
  parsed_route = prefix + '/' + parsed_route
36
43
  }
37
-
38
44
  if(parsed_route.indexOf(':') >= 0)
39
45
  {
40
46
  var regex_to_match = parsed_route.replace(/:[^\/]*/g, '([^\/]*)');
41
47
  o_O.routes.rules[parsed_route] = {
42
48
  action: o_O.routes.figure_action(options),
43
- matchers: parsed_route.match(/:[^\/]*/g)
49
+ matchers: parsed_route.match(/:[^\/]*/g),
50
+ params: params
44
51
  };
45
52
  o_O.routes.regex_urls.push({regex: regex_to_match, matcher:parsed_route});
46
53
  }
@@ -77,33 +84,33 @@ o_O.routes = {
77
84
  }
78
85
 
79
86
  var compute_params = function(rule){
80
- return function(attr){
81
- var params = {}
82
- if(rule)
87
+
88
+ if(rule)
89
+ {
90
+ for(j = 0; j < rule.matchers.length; j++)
83
91
  {
84
- for(j = 0; j < rule.matchers.length; j++)
85
- {
86
- params[rule.matchers[j].replace(/^:/, '')] = match[j+1];
87
- }
92
+ o_O.params.collection[rule.matchers[j].replace(/^:/, '')] = match[j+1];
88
93
  }
89
94
 
90
- if(query_string_parts.length > 0)
95
+ if(rule.params)
91
96
  {
92
- for(k = 0; k < query_string_parts.length; k++)
97
+ for(param in rule.params)
93
98
  {
94
- var param_parts = query_string_parts[k].split('=')
95
- params[param_parts[0]] = param_parts[1];
99
+ o_O.params.collection[param] = rule.params[param];
96
100
  }
97
101
  }
98
- if(attr)
99
- {
100
- return params[attr];
101
- }
102
- else
102
+ }
103
+
104
+ if(query_string_parts.length > 0)
105
+ {
106
+ for(k = 0; k < query_string_parts.length; k++)
103
107
  {
104
- return params;
108
+ var param_parts = query_string_parts[k].split('=')
109
+ o_O.params.collection[param_parts[0]] = param_parts[1];
105
110
  }
106
111
  }
112
+
113
+ return o_O.params
107
114
  }
108
115
 
109
116
  if(location.hash.o_O_trim() == '')
@@ -29,6 +29,9 @@
29
29
  this.methods.title_numbered = function(){
30
30
  return '1. ' + this.title;
31
31
  }
32
+ this.do_something = function(){
33
+ return 'did something'
34
+ }
32
35
  return this;
33
36
  });
34
37
 
@@ -48,6 +51,10 @@
48
51
  var test_model = o_O('Review').initialize({title: 'Delicious'})
49
52
  equals(test_model.title, 'Delicious', 'should just work as normal')
50
53
  })
54
+
55
+ test('class-ish method', function(){
56
+ equals(o_O('Review').do_something(), 'did something')
57
+ })
51
58
 
52
59
  test('serialization',1, function(){
53
60
  var myReview = Review.initialize({title: 'Groovy'})
@@ -52,6 +52,12 @@
52
52
  }
53
53
  })
54
54
 
55
+ o_O('GalleryController', {
56
+ gallery: function(){
57
+ $('div#gallery').html(o_O.params('thing'))
58
+ }
59
+ })
60
+
55
61
  o_O.routes.draw(function(map){
56
62
  map.root({to: "reviews#root"})
57
63
  map.match('/reviews/index/', {to: "reviews#index"});
@@ -60,6 +66,7 @@
60
66
  })
61
67
  map.match('/reviews/:test', {to: 'reviews#sending_params'})
62
68
  map.match('gobble', {to: 'reviews#sending_params_normal'})
69
+ map.match('/gallery/:image', {to: 'gallery#gallery', thing: 'gallery'})
63
70
 
64
71
  map.resources('songs')
65
72
  })
@@ -148,6 +155,14 @@
148
155
  }, 100)
149
156
  })
150
157
 
158
+ asyncTest('pass params via routes', function(){
159
+ $('a#gallery-link').click()
160
+ setTimeout(function(){
161
+ equals($('div#gallery').text(), 'gallery')
162
+ start();
163
+ }, 100)
164
+ })
165
+
151
166
 
152
167
  });
153
168
  </script>
@@ -186,5 +201,8 @@
186
201
  <a id="index-song" href="/songs/" data-ajax-history="true">Songs Index</a>
187
202
  <div id="songs-index"></div>
188
203
 
204
+ <a id="gallery-link" href="/gallery/stuff" data-ajax-history="true">Songs Index</a>
205
+ <div id="gallery"></div>
206
+
189
207
  </body>
190
208
  </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: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 11
10
- version: 0.5.11
9
+ - 12
10
+ version: 0.5.12
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-10-28 00:00:00 +01:00
18
+ date: 2010-11-03 00:00:00 +00:00
19
19
  default_executable: eyeballs
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency