Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed collections - :)

  • Loading branch information...
commit 6ca99c49131bcd25fec4d2ed4873754617021f41 1 parent 406ed92
Alex MacCaw authored
44 assets/jquery.bowline.js
View
@@ -26,8 +26,34 @@
// rb.send(src[1]);
// return false;
// });
- }
- }
+ },
+
+ // A lot of JS libs require hashes
+ // without any functions in them
+ rubyHash: function( hsh ) {
+ res = {};
+ $.each(hsh, function(key, value){
+ if(typeof(value) != 'function'){
+ res[key] = value;
+ }
+ });
+ return res;
+ },
+
+ // Length on a Ruby array is a function
+ rubyMap: function( elems, callback ) {
+ var ret = [];
+
+ for ( var i = 0, length = elems.length(); i < length; i++ ) {
+ var value = callback( elems[ i ], i );
+
+ if ( value != null )
+ ret[ ret.length ] = value;
+ }
+
+ return ret.concat.apply( [], ret );
+ }
+ },
$.fn.bowline = function(name, options){
$(this).chain(options);
@@ -53,7 +79,15 @@
}
};
- $.fn.bowlineUpdate = function(items){
- console.log(items);
- }
+ $.fn.updateCollection = function( items ){
+ items = $.bowline.rubyMap(items, function(n){
+ return $.bowline.rubyHash(n);
+ });
+ $(this).items(items);
+ };
+
+ $.fn.updateSingleton = function( item ){
+ item = $.bowline.rubyHash(item);
+ $(this).item(item);
+ };
})(jQuery)
13 lib/bowline/collection.rb
View
@@ -10,16 +10,9 @@ def items=(args)
def item_sync!
return unless @@items && @@elements
- # todo
- puts "Calling item_sync"
- p @@items.to_js
- p @@elements
- puts "logging..."
- js.console.log([{"one" => "two"}])
- # js.console.log(@@items)
- # Call the chain.js function 'items' on elements
- puts "Setting"
- @@elements.each {|i| i.bowlineUpate([{"name" => "two", "three" => "four"}]) }
+ @@elements.each {|i|
+ i.updateCollection(@@items.to_js)
+ }
end
def find(id)
4 lib/bowline/singleton.rb
View
@@ -10,7 +10,9 @@ def item=(arg)
def item_sync!
return unless @@item && @@elements
# Call the chain.js function 'item' on elements
- @@elements.each {|i| i.item(@@item.to_js) }
+ @@elements.each {|i|
+ i.updateSingleton(@@item.to_js)
+ }
end
def find(*a)
Please sign in to comment.
Something went wrong with that request. Please try again.