Permalink
Browse files

Merge branch 'master' of github.com:jldailey/BlingJS

  • Loading branch information...
2 parents 5779902 + 227691b commit f7a7e04ea8b20bc28dc3fa73b072252372718295 @jldailey committed May 24, 2012
Showing with 58 additions and 44 deletions.
  1. +40 −0 README.md
  2. +0 −35 README.txt
  3. +6 −5 bling.coffee
  4. +11 −3 tests/bling.coffee
  5. +1 −1 tests/domjs
View
@@ -0,0 +1,40 @@
+BlingJS is meant to be as useful as jQuery, but more consistent. In particular, it is more consistent about doing set-based operations.
+
+* All operations return sets wherever possible.
+* As much as possible is a plugin, even core operations.
+
+So, while it supports all the same basic operations as jQuery, they behave
+slightly different.
+
+For instance, the `.html()` operation.
+* in jQuery, returns the innerHTML of the _first_ DOM node in the input
+* here, you get a set of html strings, one from _each_ node.
+
+This **set philosophy** means that set operations are useful:
+* `.intersect()`
+* `.union()`
+
+These kinds of set operations are part of the "core" plugin, and there also some
+new things, like the `.select()` and `.zap()` operations.
+
+The `.select()` operation will collect a single property from every item in
+a set.
+> `.html()` is a shortcut for `.select('innerHTML')`.
+
+* You can extract nested values, e.g. `.select('style.color')`.
+* Arbitrary nesting depth, and arrays, e.g. `.select('foo.bar.0.baz')`.
+
+The `.zap()` operation is a way to do assignment and stay in a loosely
+functional context.
+> `.html("new html")` is a shortcut for `.zap('innerHTML', "new html")`.
+
+More than just simple assignment, it can also 'stripe' values across a set;
+a common thing to want to accomplish across list items.
+> `$("li").zap('className', ["odd", "even"])`.
+
+It can map a function across nested properties of your set items:
+> `$("li").zap('style.top', -> $.px @+10 )`
+This example moves every list-item up 10 pixels, and allows you to continue chaining
+on the list-items.
+
+http://blingjs.com
View
@@ -1,35 +0,0 @@
-BlingJS is meant to be as useful as jQuery, but more consistent.
-
-In particular, it is more consistent about doing set-based operations:
-All operations return sets wherever possible.
-
-So, while it supports all the same basic operations as jQuery,
-these operations behave slightly differently.
-
-For instance, the .html() operation in jQuery just returns the
-innerHTML of the first item in the set, in Bling, you get a set of
-html, one for each DOM node in the input set.
-
-This means that basic set primitives like .intersect() and .union()
-become more powerful. For instance, .parents() returns the chain of all
-parents up to the document node; intersecting this with some other set of nodes
-(say, a set of <li> elements, will find the exact list-item(s) you are within)
-
-There are also a couple things that are wholly new, and awesome. Like,
-the .zip() and .zap() operations.
-
-The .zip() operation will grab a single property from every item in
-a set. So, html() is defined as zip('innerHTML'). You can also extract
-nested values easily, as in zip('style.color'), arbitrary nesting depth
-is supported [e.g. zip('foo.bar.baz.bok')].
-
-The .zap() operation is a way to do assignment and stay in a loosely
-functional context. So, html("new html") is defined as
-zap('innerHTML', "new html"). But more than just simple assignment,
-it can also 'stripe' values across a set; a common thing to want to
-accomplish across list items: $("li").zap('className', ["odd", "even"]).
-
-For a more complete listing of what's great about it [like synth()],
-please visit the website:
-
-http://blingjs.com
View
@@ -1120,10 +1120,11 @@ Bling.prototype = []
x = toNode(x) # parse, cast, do whatever it takes to get a Node or Fragment
@each -> @appendChild x.cloneNode true
- appendTo: (x) -> # .appendTo(/n/) - each node [or a fragment] will become the last child of n
- $(x).append(@)
- try console.log "@.parentNode in appendTo:", @[0].parentNode, "should not be null"
- @
+ appendTo: (x) -> # .appendTo(/n/) - each node [or fragment] will become the last child of x
+ clones = @map( -> @cloneNode true)
+ i = 0
+ $(x).each -> @appendChild clones[i++]
+ clones
prepend: (x) -> # .prepend(/n/) - insert n [or a clone] as the first child of each node
if x?
@@ -1134,7 +1135,7 @@ Bling.prototype = []
before @childNodes[0], x.cloneNode(true)
@
- prependTo: (x) -> # .prependTo(/n/) - each node [or a fragment] will become the first child of n
+ prependTo: (x) -> # .prependTo(/n/) - each node [or a fragment] will become the first child of x
if x?
$(x).prepend(@)
@
View
@@ -217,11 +217,19 @@ testGroup("HTML",
assertEqual($("tr td.d").append("<span>Hi</span>").html().first(), "3,2<span>Hi</span>")
finally
$("tr td.d span").remove()
- appendTo:->
+ appendTo1:-> assertEqual($("<span>Hi</span>").toString(), "$([<span>Hi</span>])")
+ appendTo2:->
try
- assertEqual($("<span>Hi</span>").toString(), "$([<span>Hi</span>])")
assertEqual($("<span>Hi</span>").appendTo("tr td.d").toString(), "$([<span>Hi</span>])")
- assertEqual($("<span>Hi</span>").appendTo("tr td.d").select('parentNode').toString(), "$([<td class='d'><span>Hi</span></td>])")
+ finally
+ $("tr td.d span").remove()
+ appendTo3:->
+ try
+ assertEqual($("<span>Hi</span>").appendTo("tr td.d").select('parentNode').toString(), '$([<td class="d">3,2<span>Hi</span></td>])')
+ finally
+ $("tr td.d span").remove()
+ appendTo4:->
+ try
assertEqual($("<span>Hi</span>").appendTo("tr td.d").select('parentNode').html().first(), "3,2<span>Hi</span>")
finally
$("tr td.d span").remove()
Submodule domjs updated from aaf901 to 6c1329

0 comments on commit f7a7e04

Please sign in to comment.