bowline 0.5.8 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/README.txt +2 -2
  2. data/Rakefile +3 -2
  3. data/TODO +2 -0
  4. data/VERSION +1 -1
  5. data/assets/bowline.js +131 -68
  6. data/assets/bowline.test.js +86 -0
  7. data/bowline.gemspec +15 -17
  8. data/examples/tweet.rb +3 -1
  9. data/lib/bowline.rb +9 -5
  10. data/lib/bowline/app_config.rb +41 -0
  11. data/lib/bowline/binders.rb +70 -101
  12. data/lib/bowline/binders/collection.rb +37 -0
  13. data/lib/bowline/binders/observer.rb +30 -0
  14. data/lib/bowline/binders/singleton.rb +43 -0
  15. data/lib/bowline/commands/run.rb +1 -0
  16. data/lib/bowline/desktop/bridge.rb +4 -4
  17. data/lib/bowline/desktop/js.rb +7 -3
  18. data/lib/bowline/desktop/runtime.rb +29 -0
  19. data/lib/bowline/desktop/window.rb +9 -1
  20. data/lib/bowline/desktop/window_methods.rb +1 -1
  21. data/lib/bowline/generators/application.rb +1 -0
  22. data/lib/bowline/generators/binder.rb +7 -2
  23. data/lib/bowline/generators/model.rb +1 -1
  24. data/lib/bowline/helpers.rb +2 -0
  25. data/lib/bowline/initializer.rb +39 -87
  26. data/lib/bowline/library.rb +1 -7
  27. data/lib/bowline/tasks/app.rake +1 -53
  28. data/lib/bowline/tasks/libs.rake +4 -17
  29. data/lib/bowline/version.rb +2 -2
  30. data/lib/bowline/watcher.rb +50 -23
  31. data/templates/Gemfile +10 -0
  32. data/templates/config/boot.rb +11 -8
  33. data/templates/main_window.rb +1 -0
  34. metadata +20 -15
  35. data/lib/bowline/dependencies/FAQ.markdown +0 -6
  36. data/lib/bowline/dependencies/MIT-LICENSE +0 -20
  37. data/lib/bowline/dependencies/README.markdown +0 -51
  38. data/lib/bowline/dependencies/TODO.markdown +0 -4
  39. data/lib/bowline/dependencies/lib/dependencies.rb +0 -6
  40. data/lib/bowline/dependencies/lib/dependencies/dependency.rb +0 -12
  41. data/lib/bowline/dependencies/lib/dependencies/repository.rb +0 -64
  42. data/lib/bowline/dependencies/lib/ext/rubygems.rb +0 -116
  43. data/lib/bowline/ext/class.rb +0 -51
  44. data/lib/bowline/ext/string.rb +0 -9
  45. data/lib/bowline/local_model.rb +0 -142
  46. data/lib/bowline/tasks/gems.rake +0 -36
data/README.txt CHANGED
@@ -142,7 +142,7 @@ $.bowline.helper('name', 'arg1', ['arg2'])
142
142
 
143
143
  Bowline supports ActiveRecord and the Sqlite3 database.
144
144
  The packaging for distributing databases is still in development though.
145
- Bowline also has a LocalModel class for models held in memory.
145
+ You can use the SuperModel gem (http://github.com/maccman/supermodel) for models held in memory.
146
146
 
147
147
  = WINDOWS
148
148
 
@@ -160,7 +160,7 @@ http://github.com/maccman/bowline-desktop
160
160
  = DISTRIBUTING
161
161
 
162
162
  Once your app is ready for a release, you should run the following command to make sure all the gems required have been vendorised:
163
- rake gems:sync
163
+ gem bundle
164
164
 
165
165
  Then, run:
166
166
  ./script/build
data/Rakefile CHANGED
@@ -8,8 +8,9 @@ begin
8
8
  gemspec.description = "Ruby/JS GUI framework"
9
9
  gemspec.authors = ["Alex MacCaw"]
10
10
  gemspec.add_dependency('templater', '>= 0.3.2')
11
- gemspec.add_dependency('activesupport', '>= 2.3.2')
11
+ gemspec.add_dependency('activesupport', '>= 3.0.0.beta')
12
12
  gemspec.add_dependency('rubyzip2', '>= 2.0.1')
13
+ gemspec.add_dependency('supermodel')
13
14
  end
14
15
  rescue LoadError
15
16
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
@@ -28,4 +29,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
28
29
  rdoc.options << "--line-numbers" << "--inline-source"
29
30
  rdoc.rdoc_files.include("README.txt")
30
31
  rdoc.rdoc_files.include("lib/**/*.rb")
31
- end
32
+ end
data/TODO CHANGED
@@ -25,6 +25,8 @@ Tutorials:
25
25
  - Add first-run initializers
26
26
  - Add reload keyboard shortcut
27
27
  - Add some sort of production mode
28
+ - Generate correct shebang on script files
29
+ - Use App.root rather than APP_ROOT
28
30
 
29
31
  - strip exe (to make smaller)
30
32
  - remove framework headers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.8
1
+ 0.6.0
@@ -118,6 +118,83 @@
118
118
 
119
119
  */
120
120
 
121
+ var BowlineBound = function(klass){
122
+ this.klass = klass;
123
+ this.options = {};
124
+ this.elements = jQuery();
125
+ };
126
+
127
+ BowlineBound.fn = BowlineBound.prototype;
128
+
129
+ BowlineBound.fn.updateOptions = function(opts){
130
+ this.options = jQuery.extend({}, this.options, opts);
131
+ this.singleton = this.options.singleton;
132
+ }
133
+
134
+ BowlineBound.fn.push = function(element){
135
+ this.elements = this.elements.add(element);
136
+ this.setup();
137
+ }
138
+
139
+ BowlineBound.fn.replace = function(items){
140
+ if(this.singleton) {
141
+ this.elements.item("replace", items);
142
+ } else {
143
+ this.elements.items("replace", items);
144
+ }
145
+ }
146
+
147
+ BowlineBound.fn.create = function(id, item){
148
+ if(this.singleton) {
149
+ this.elements.item(item);
150
+ } else {
151
+ this.elements.items("add", item);
152
+ }
153
+ }
154
+
155
+ BowlineBound.fn.update = function(id, item){
156
+ if(this.singleton){
157
+ this.elements.item(item);
158
+ } else {
159
+ this.findElement(id).item(item);
160
+ }
161
+ }
162
+
163
+ BowlineBound.fn.remove = function(id){
164
+ if(this.singleton) {
165
+ this.elements.item("replace", {});
166
+ } else {
167
+ this.findElement(id).item("remove");
168
+ }
169
+ }
170
+
171
+ BowlineBound.fn.invoke = function(){
172
+ var args = $.makeArray(arguments);
173
+ args.unshift(this.klass);
174
+ Bowline.invoke.apply(Bowline, args);
175
+ }
176
+
177
+ BowlineBound.fn.findElement = function(id){
178
+ // TODO - increase efficiency
179
+ var element = jQuery();
180
+ jQuery.each(this.elements.items(true), function(){
181
+ var sameItem = $(this).item().id == id;
182
+ if(sameItem) element = element.add(this);
183
+ });
184
+ return element;
185
+ }
186
+
187
+ BowlineBound.fn.setup = function(){
188
+ if (this.hasSetup) return;
189
+ this.hasSetup = true;
190
+ var self = this;
191
+ jQuery(function(){
192
+ Bowline.invoke(self.klass, "setup", function(opts){
193
+ self.updateOptions(opts);
194
+ });
195
+ });
196
+ }
197
+
121
198
  var Bowline = {
122
199
  callbacks: {},
123
200
  uuid: 0,
@@ -154,6 +231,8 @@ var Bowline = {
154
231
 
155
232
  Bowline.log("New message:", msg);
156
233
 
234
+ Bowline.log(JSON.stringify(msg))
235
+
157
236
  if(Bowline.enabled)
158
237
  _app.call(JSON.stringify(msg));
159
238
  },
@@ -174,100 +253,91 @@ var Bowline = {
174
253
 
175
254
  helper: function(){
176
255
  var args = jQuery.makeArray(arguments);
177
- args.unshift("Helper");
256
+ args.unshift("Bowline::Helpers");
178
257
  Bowline.invoke.apply(this, args);
179
258
  },
180
259
 
181
260
  bind: function(el, klass, options){
182
261
  el = jQuery(el);
262
+
263
+ el.data("bowline", klass);
183
264
  el.chain(options);
184
- el.data('bowline', klass);
265
+
185
266
  if(!Bowline.bounds[klass])
186
- Bowline.bounds[klass] = [];
267
+ Bowline.bounds[klass] = new BowlineBound(klass);
268
+
187
269
  Bowline.bounds[klass].push(el);
188
- jQuery(function(){
189
- Bowline.invoke(klass, "setup", function(res){
190
- Bowline.populate(klass, res);
191
- });
192
- });
270
+
271
+ // Shortcut
272
+ Bowline[klass] = Bowline.bounds[klass];
193
273
  },
194
274
 
195
275
  unbind: function(el, klass){
196
- var array = Bowline.bounds[klass]
197
- if(!array) return;
198
- array = jQuery.grep(array,
199
- function(n){ return n != el }
200
- );
201
- Bowline.bounds[klass] = array;
276
+ // TODO
277
+ // var array = Bowline.bounds[klass];
278
+ // if(!array) return;
279
+ // array = jQuery.grep(array,
280
+ // function(n){ return n.el != el }
281
+ // );
282
+ // Bowline.bounds[klass] = array;
283
+ },
284
+
285
+ openInspector: function(){
286
+ if(Bowline.enabled)
287
+ _app.openInspector();
202
288
  },
203
289
 
204
290
  // Bowline functions
205
291
 
206
292
  invokeJS: function(str){
207
293
  Bowline.log("Invoking:", str);
208
- return JSON.stringify(eval(str));
294
+ try {
295
+ return JSON.stringify(eval(str));
296
+ } catch(e) {
297
+ Bowline.warn(e);
298
+ }
209
299
  },
210
300
 
211
301
  invokeCallback: function(id, res){
212
302
  Bowline.log("Callback:", id, res);
213
- if(!Bowline.callbacks[id]) return true;
303
+ if(!Bowline.callbacks[id]) return;
214
304
  try {
215
305
  Bowline.callbacks[id](JSON.parse(res));
216
306
  delete Bowline.callbacks[id];
217
307
  } catch(e) {
218
- Bowline.log(e)
308
+ Bowline.warn(e)
219
309
  }
220
- return true;
221
310
  },
222
311
 
223
- populate: function(klass, items){
224
- if(!Bowline.bounds[klass]) return true;
225
- jQuery.each(Bowline.bounds[klass], function(){
226
- this.items('replace', items);
227
- });
228
- return true;
312
+ replace: function(klass, items){
313
+ if(!Bowline.bounds[klass]) return;
314
+ Bowline.bounds[klass].replace(items);
229
315
  },
230
316
 
231
317
  created: function(klass, id, item){
232
- if(!Bowline.bounds[klass]) return true;
233
- if(!item.id) item.id = id;
234
- jQuery.each(Bowline.bounds[klass], function(){
235
- this.items('add', item);
236
- });
237
- return true;
318
+ if(!Bowline.bounds[klass]) return;
319
+ Bowline.bounds[klass].create(id, item);
238
320
  },
239
321
 
240
322
  updated: function(klass, id, item){
241
- if(!Bowline.bounds[klass]) return true;
323
+ if(!Bowline.bounds[klass]) return;
242
324
  if(!item.id) item.id = id;
243
- jQuery.each(Bowline.bounds[klass], function(){
244
- Bowline.findItem(this, id).item('replace', item);
245
- });
246
- return true;
325
+ Bowline.bounds[klass].update(id, item);
247
326
  },
248
327
 
249
328
  removed: function(klass, id){
250
- if(!Bowline.bounds[klass]) return true;
251
- jQuery.each(Bowline.bounds[klass], function(){
252
- Bowline.findItem(this, id).item('remove');
253
- });
254
- return true;
329
+ if(!Bowline.bounds[klass]) return;
330
+ Bowline.bounds[klass].remove(id);
255
331
  },
256
332
 
257
333
  trigger: function(klass, event, data){
258
- if(!Bowline.bounds[klass]) return true;
259
- jQuery.each(Bowline.bounds[klass], function(){
260
- this.trigger(event, data);
261
- });
262
- return true;
334
+ if(!Bowline.bounds[klass]) return;
335
+ Bowline.bounds[klass].elements.trigger(event, data);
263
336
  },
264
337
 
265
338
  element: function(klass, id){
266
- var el = jQuery();
267
- jQuery.each(Bowline.bounds[klass], function(){
268
- el = el.add(findItem(this, id));
269
- });
270
- return el;
339
+ if(!Bowline.bounds[klass]) return;
340
+ return Bowline.bounds[klass].findElement(id);
271
341
  },
272
342
 
273
343
  // System functions
@@ -276,13 +346,6 @@ var Bowline = {
276
346
  Bowline.windowInvoke("loaded!");
277
347
  },
278
348
 
279
- findItem: function(el, id){
280
- var items = jQuery.grep(el.items(true), function(n, i){
281
- return jQuery(n).item().id == id;
282
- });
283
- return(jQuery(items[0]));
284
- },
285
-
286
349
  log: function(){
287
350
  if( !Bowline.trace ) return;
288
351
  var args = jQuery.makeArray(arguments);
@@ -299,20 +362,20 @@ var Bowline = {
299
362
 
300
363
  (function($){
301
364
  $.fn.invoke = function(){
302
- if($(this).chain('active')){
303
- var args = $.makeArray(arguments);
304
- if($(this).data('bowline')){
305
- // Class method
306
- var klass = $(this).data('bowline');
307
- args.unshift(klass);
308
- Bowline.invoke.apply(Bowline, args);
309
- } else {
310
- // Instance method
311
- var klass = $(this).item('root').data('bowline');
312
- var id = $(this).item().id;
365
+ if($(this).chain("active")){
366
+ var args = $.makeArray(arguments);
367
+ var element = $(this).item("root");
368
+ var klass = element.data("bowline");
369
+ if(!klass) throw "Unknown class: " + klass;
370
+
371
+ if(Bowline[klass].singleton){
372
+ var id = element.item().id;
313
373
  args.unshift(id);
314
374
  args.unshift(klass);
315
375
  Bowline.instanceInvoke.apply(Bowline, args);
376
+ } else {
377
+ args.unshift(klass);
378
+ Bowline.invoke.apply(Bowline, args);
316
379
  }
317
380
  } else {
318
381
  throw 'Chain not active';
@@ -0,0 +1,86 @@
1
+ // Emulates a Bowline backend
2
+
3
+ BowlineTest = {};
4
+ BowlineTest.trace = true;
5
+ BowlineTest.setup = function(){
6
+ window._app = {}
7
+ window._app.call = function(json){
8
+ var msg = JSON.parse(json);
9
+
10
+ if(msg.klass == "_window") return;
11
+
12
+ var klass = BowlineTest.klasses[msg.klass];
13
+ if(klass)
14
+ var method = klass[msg.method];
15
+
16
+ if(!method && msg.method == "setup"){
17
+ return;
18
+ }
19
+
20
+ if(!klass || !method) {
21
+ BowlineTest.log("Missing method:", msg.klass + "#" + msg.method);
22
+ return;
23
+ }
24
+
25
+ BowlineTest.log("Handling method:", msg.klass + "#" + msg.method);
26
+
27
+ var replace = function(val){
28
+ Bowline.replace(msg.klass, val);
29
+ }
30
+
31
+ var created = function(id, val){
32
+ Bowline.created(msg.klass, id, val);
33
+ }
34
+
35
+ var updated = function(id, val){
36
+ Bowline.updated(msg.klass, id, val);
37
+ }
38
+
39
+ var removed = function(id){
40
+ Bowline.removed(msg.klass, id);
41
+ }
42
+
43
+ var context = {
44
+ replace: replace,
45
+ created: created,
46
+ updated: updated,
47
+ removed: removed
48
+ };
49
+
50
+ var result;
51
+ try {
52
+ result = method.apply(context, msg.args);
53
+ } catch(e) {
54
+ console.error("Error in method:", klass + "#" + method);
55
+ throw(e);
56
+ }
57
+
58
+ if(msg.id != -1) {
59
+ Bowline.invokeCallback(
60
+ msg.id, JSON.stringify(result)
61
+ )
62
+ }
63
+ }
64
+ Bowline.enabled = true;
65
+ };
66
+
67
+ BowlineTest.log = function(){
68
+ if( !BowlineTest.trace ) return;
69
+ var args = jQuery.makeArray(arguments);
70
+ args.unshift("(BowlineTest)");
71
+ console.log.apply(console, args);
72
+ };
73
+
74
+ BowlineTest.klasses = {};
75
+ BowlineTest.register = function(className, object) {
76
+ BowlineTest.klasses[className] = object;
77
+ var bound = Bowline.bounds[className];
78
+ if(bound) bound.singleton = object.singleton;
79
+ }
80
+
81
+ BowlineTest.enabled = !Bowline.enabled;
82
+
83
+ if(BowlineTest.enabled){
84
+ BowlineTest.log("Enabled");
85
+ BowlineTest.setup();
86
+ }
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bowline}
8
- s.version = "0.5.8"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex MacCaw"]
12
- s.date = %q{2010-01-19}
12
+ s.date = %q{2010-02-10}
13
13
  s.default_executable = %q{bowline-gen}
14
14
  s.description = %q{Ruby/JS GUI framework}
15
15
  s.email = %q{alex@leadthinking.com}
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "assets/bowline.js",
31
31
  "assets/bowline.menu.js",
32
32
  "assets/bowline.state.js",
33
+ "assets/bowline.test.js",
33
34
  "assets/bowline.view.js",
34
35
  "assets/jquery.chain.js",
35
36
  "assets/jquery.dataset.js",
@@ -46,19 +47,15 @@ Gem::Specification.new do |s|
46
47
  "examples/twitter.html",
47
48
  "examples/users.rb",
48
49
  "lib/bowline.rb",
50
+ "lib/bowline/app_config.rb",
49
51
  "lib/bowline/binders.rb",
52
+ "lib/bowline/binders/collection.rb",
53
+ "lib/bowline/binders/observer.rb",
54
+ "lib/bowline/binders/singleton.rb",
50
55
  "lib/bowline/commands/build.rb",
51
56
  "lib/bowline/commands/console.rb",
52
57
  "lib/bowline/commands/generate.rb",
53
58
  "lib/bowline/commands/run.rb",
54
- "lib/bowline/dependencies/FAQ.markdown",
55
- "lib/bowline/dependencies/MIT-LICENSE",
56
- "lib/bowline/dependencies/README.markdown",
57
- "lib/bowline/dependencies/TODO.markdown",
58
- "lib/bowline/dependencies/lib/dependencies.rb",
59
- "lib/bowline/dependencies/lib/dependencies/dependency.rb",
60
- "lib/bowline/dependencies/lib/dependencies/repository.rb",
61
- "lib/bowline/dependencies/lib/ext/rubygems.rb",
62
59
  "lib/bowline/desktop.rb",
63
60
  "lib/bowline/desktop/app.rb",
64
61
  "lib/bowline/desktop/bridge.rb",
@@ -70,14 +67,13 @@ Gem::Specification.new do |s|
70
67
  "lib/bowline/desktop/misc.rb",
71
68
  "lib/bowline/desktop/network.rb",
72
69
  "lib/bowline/desktop/proxy.rb",
70
+ "lib/bowline/desktop/runtime.rb",
73
71
  "lib/bowline/desktop/sound.rb",
74
72
  "lib/bowline/desktop/window.rb",
75
73
  "lib/bowline/desktop/window_manager.rb",
76
74
  "lib/bowline/desktop/window_methods.rb",
77
75
  "lib/bowline/ext/array.rb",
78
- "lib/bowline/ext/class.rb",
79
76
  "lib/bowline/ext/object.rb",
80
- "lib/bowline/ext/string.rb",
81
77
  "lib/bowline/generators.rb",
82
78
  "lib/bowline/generators/application.rb",
83
79
  "lib/bowline/generators/binder.rb",
@@ -88,18 +84,17 @@ Gem::Specification.new do |s|
88
84
  "lib/bowline/helpers.rb",
89
85
  "lib/bowline/initializer.rb",
90
86
  "lib/bowline/library.rb",
91
- "lib/bowline/local_model.rb",
92
87
  "lib/bowline/logging.rb",
93
88
  "lib/bowline/platform.rb",
94
89
  "lib/bowline/tasks/app.rake",
95
90
  "lib/bowline/tasks/bowline.rb",
96
91
  "lib/bowline/tasks/database.rake",
97
- "lib/bowline/tasks/gems.rake",
98
92
  "lib/bowline/tasks/libs.rake",
99
93
  "lib/bowline/tasks/log.rake",
100
94
  "lib/bowline/tasks/misc.rake",
101
95
  "lib/bowline/version.rb",
102
96
  "lib/bowline/watcher.rb",
97
+ "templates/Gemfile",
103
98
  "templates/Rakefile",
104
99
  "templates/binder.rb",
105
100
  "templates/config/application.yml",
@@ -140,17 +135,20 @@ Gem::Specification.new do |s|
140
135
 
141
136
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
142
137
  s.add_runtime_dependency(%q<templater>, [">= 0.3.2"])
143
- s.add_runtime_dependency(%q<activesupport>, [">= 2.3.2"])
138
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta"])
144
139
  s.add_runtime_dependency(%q<rubyzip2>, [">= 2.0.1"])
140
+ s.add_runtime_dependency(%q<supermodel>, [">= 0"])
145
141
  else
146
142
  s.add_dependency(%q<templater>, [">= 0.3.2"])
147
- s.add_dependency(%q<activesupport>, [">= 2.3.2"])
143
+ s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
148
144
  s.add_dependency(%q<rubyzip2>, [">= 2.0.1"])
145
+ s.add_dependency(%q<supermodel>, [">= 0"])
149
146
  end
150
147
  else
151
148
  s.add_dependency(%q<templater>, [">= 0.3.2"])
152
- s.add_dependency(%q<activesupport>, [">= 2.3.2"])
149
+ s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
153
150
  s.add_dependency(%q<rubyzip2>, [">= 2.0.1"])
151
+ s.add_dependency(%q<supermodel>, [">= 0"])
154
152
  end
155
153
  end
156
154