From f2e65cfdeb838b9287b9e563a2b118c35133d39f Mon Sep 17 00:00:00 2001 From: Alex MacCaw Date: Wed, 9 Dec 2009 17:00:03 +0000 Subject: [PATCH] Major re-architecture to make Bowline compatible with bowline-desktop (http://github.com/maccman/bowline-desktop) --- TODO | 4 + assets/bowline.js | 132 +++++++ assets/jquery.bowline.js | 156 --------- assets/json2.js | 479 ++++++++++++++++++++++++++ lib/bowline.rb | 31 +- lib/bowline/async.rb | 29 -- lib/bowline/binders.rb | 248 +++++++------ lib/bowline/binders/collection.rb | 59 ---- lib/bowline/binders/singleton.rb | 31 -- lib/bowline/desktop.rb | 25 ++ lib/bowline/desktop/bridge.rb | 52 +++ lib/bowline/desktop/js.rb | 57 +++ lib/bowline/desktop/proxy.rb | 65 ++++ lib/bowline/generators/application.rb | 7 +- lib/bowline/generators/binder.rb | 9 +- lib/bowline/generators/model.rb | 9 + lib/bowline/initializer.rb | 14 +- lib/bowline/jquery.rb | 17 +- lib/bowline/local_model.rb | 92 +++++ lib/bowline/logging.rb | 54 +++ lib/bowline/observer.rb | 66 ---- lib/bowline/tasks/app.rake | 39 +-- lib/bowline/version.rb | 4 +- lib/bowline/watcher.rb | 101 ++++++ lib/bowline/window.rb | 19 - templates/binder.rb | 4 +- templates/model.rb | 2 +- templates/public/index.html | 3 +- 28 files changed, 1228 insertions(+), 580 deletions(-) create mode 100644 TODO create mode 100644 assets/bowline.js delete mode 100755 assets/jquery.bowline.js create mode 100644 assets/json2.js delete mode 100644 lib/bowline/async.rb delete mode 100644 lib/bowline/binders/collection.rb delete mode 100644 lib/bowline/binders/singleton.rb create mode 100644 lib/bowline/desktop.rb create mode 100644 lib/bowline/desktop/bridge.rb create mode 100644 lib/bowline/desktop/js.rb create mode 100644 lib/bowline/desktop/proxy.rb create mode 100644 lib/bowline/local_model.rb create mode 100644 lib/bowline/logging.rb delete mode 100644 lib/bowline/observer.rb create mode 100644 lib/bowline/watcher.rb delete mode 100644 lib/bowline/window.rb diff --git a/TODO b/TODO new file mode 100644 index 0000000..c438a11 --- /dev/null +++ b/TODO @@ -0,0 +1,4 @@ +Moving off Titanium: + app.rake + +Use new packaging system diff --git a/assets/bowline.js b/assets/bowline.js new file mode 100644 index 0000000..ccab235 --- /dev/null +++ b/assets/bowline.js @@ -0,0 +1,132 @@ +var Bowline = { + msgs: [], + callbacks: {}, + uuid: 0, + bound: {}, + + id: function(){ + return ++uuid; + } + + // Usage: invoke(klass, method, *args) + invoke: function(){ + var args = $.makeArray(arguments); + var klass = args.shift(); + var method = args.shift(); + var id = id(); + + var bopts = args.pop(); + if(typeof(bopts) == "object" && bopts.callback){ + callbacks[id] = bopts.callback; + } else { + args.push(bopts); + } + + msgs.push({ + klass:klass, + method:method, + args:args, + id:id + }); + }, + + // Usage: instanceInvoke(klass, id, method, *args) + instanceInvoke: function(){ + var args = $.makeArray(arguments); + args.splice(1, 0, "instance"); + invoke.apply(this, args); + }, + + helper: function(){ + // TODO + }, + + bind: function(el, klass, options){ + el = jQuery(el); + el.chain(options); + el.data('bowline', klass); + if(!bound[klass]) bound[klass] = []; + bound[klass].push(el); + }, + + // Bowline functions + + pollJS: function(){ + return JSON.stringify(msgs); + } + + invokeJS: function(str){ + log("Evaling: " + str); + return JSON.stringify(eval(str)); + }, + + invokeCallback: function(id, res){ + // TODO - delete callback after + callbacks[id](JSON.parse(res)); + }, + + created: function(klass, id, item){ + jQuery.each(callbacks[klass], function(){ + this.items('add', item); + }); + }, + + updated: function(klass, id, item){ + jQuery.each(callbacks[klass], function(){ + this.items('update', findItem(this, id)); + }); + }, + + removed: function(klass, id){ + jQuery.each(callbacks[klass], function(){ + this.items('remove', findItem(this, id)); + }); + }, + + trigger: function(klass, event, data){ + jQuery.each(callbacks[klass], function(){ + this.trigger(event, data); + }); + }, + + // System functions + + findItem: function(el, id){ + return jQuery.grep(el.items(true), function(n, i){ + return n.item().id == id; + })[0]; + }, + + log: function(msg){ + console.log(msg); + } +}; + +function($){ + $.fn.invoke = function(){ + if($(this).chain('active')){ + var args = $.makeArray(arguments); + if($(this).data('bowline')){ + // Class method + var klass = $(this).data('bowline'); + args.unshift(klass); + Bowline.invoke.apply(this, args); + } else { + // Instance method + var klass = $(this).item('root').data('bowline'); + var id = $(this).item().id; + args.unshift(id); + args.unshift(klass); + Bowline.instanceInvoke.apply(this, args); + } + } else { + throw 'Chain not active'; + } + }; + + $.fn.bind = function(){ + var args = $.makeArray(arguments); + args.unshift(this); + Bowline.bind.apply(this, args); + }; +}(jQuery); \ No newline at end of file diff --git a/assets/jquery.bowline.js b/assets/jquery.bowline.js deleted file mode 100755 index b53ea53..0000000 --- a/assets/jquery.bowline.js +++ /dev/null @@ -1,156 +0,0 @@ -(function($){ - var init = false; - var TI = Titanium; - var UI = TI.UI; - var mainWin = UI.mainWindow.window; - - $.bowline = { - setup: function(name, el){ - var rb = mainWin.eval("bowline_" + name + "_setup"); - if(!rb) throw 'Unknown class'; - rb(el); - }, - - klass: function(name){ - var rb = mainWin.eval("bowline_" + name); - if(!rb) throw 'Unknown class'; - return rb; - }, - - instance: function(name, el){ - var rb = mainWin.eval("bowline_" + name + "_instance"); - if(!rb) throw 'Unknown class'; - return rb(el); - }, - - helper: function(){ - return( - bowline_helper.apply( - bowline_helper, - arguments - ) - ); - }, - - load: function(){ - $(function(){ - setTimeout(function(){ - $(document.body).trigger('loading.bowline'); - var script = $(" - + +