public
Description: A jQuery plugin for Morphic programming
Clone URL: git://github.com/nkallen/effen.git
polish
Nick Kallen (author)
Sat Feb 23 13:36:24 -0800 2008
commit  2dc062288b68203704e15310d07390025ef476b8
tree    2ed24c35b50c55a044dad0999eed86bd14daa4c5
parent  2d7adb437fc8393c19480fe4097c369467419f4b
...
9
10
11
12
 
13
14
 
15
16
17
 
18
19
20
 
 
21
22
 
23
24
25
26
 
 
27
28
29
 
 
30
31
32
...
9
10
11
 
12
13
 
14
15
16
 
17
18
 
 
19
20
21
 
22
23
24
 
 
25
26
27
 
 
28
29
30
31
32
0
@@ -9,24 +9,24 @@
0
     <script>
0
       $(document).ready(function() {
0
         jspec.describe("fn", function() {
0
- it("registers a function with a name on the object which can be invoked", function() {
0
+ it("registers and applies a function bound to a name", function() {
0
             var element = $("<div></div>");
0
- element.fn('name', function() { return "function invoked" });
0
+ element.fn({ name: function() { return "function invoked" } });
0
             element.fn('name').should("==", "function invoked");
0
           });
0
- it("invokes functions of any arity", function() {
0
+ it("registers and applies a function of any arity", function() {
0
             var element = $("<div></div>");
0
- element.fn('name', function(a, b, c) { return [a, b, c] });
0
- element.fn('name', 1, 2, 3).should("==", [1, 2, 3]);
0
+ element.fn({ name: function(a, b, c) { return [a, b, c] } });
0
+ element.fn('name', 1, 2, 3).should("eq", [1, 2, 3]);
0
           });
0
- it("registers many functions when provided a hash", function() {
0
+ it("registers many functions", function() {
0
             var element = $("<div></div>");
0
             element.fn({
0
- name1: function() { return 'name1' },
0
- name2: function() { return 'name2' }
0
+ name1: function() { return 1 },
0
+ name2: function() { return 2 }
0
             });
0
- element.fn('name1').should("==", 'name1');
0
- element.fn('name2').should("==", 'name2');
0
+ element.fn('name1').should("==", 1);
0
+ element.fn('name2').should("==", 2);
0
           });
0
         });
0
       });
...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
 
18
19
20
 
21
 
22
23
 
 
 
 
 
 
 
 
 
 
 
 
 
24
25
...
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
8
 
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
0
@@ -2,23 +2,26 @@
0
   $.fn.fn = function() {
0
    var self = this;
0
    var extension = name = arguments[0];
0
- if ( typeof name == "string") {
0
- if ($.isFunction(arguments[1])) {
0
- var procedure = arguments[1];
0
- self.data('fn.' + name, procedure);
0
- return self;
0
- } else {
0
- var fn = self.data('fn.' + name);
0
- if (fn) {
0
- var args = Array.prototype.slice.call(arguments, 1, arguments.length);
0
- return fn.apply(self, args);
0
- } else
0
- throw(name + " is not defined");
0
- }
0
+ if (typeof name == "string") {
0
+ return apply(self, name, $.makeArray(arguments).slice(1, arguments.length));
0
     } else {
0
       $.each(extension, function(key, value) {
0
- self.fn(key, value);
0
+ define(self, key, value);
0
       });
0
+ return self;
0
     }
0
   }
0
+ function define(self, name, fn) {
0
+ self.data(namespacedName(name), fn);
0
+ };
0
+ function apply(self, name, arguments) {
0
+ var fn = self.data(namespacedName(name));
0
+ if (fn)
0
+ return fn.apply(self, arguments);
0
+ else
0
+ throw(name + " is not defined");
0
+ };
0
+ function namespacedName(name) {
0
+ return 'fn.' + name;
0
+ }
0
 })(jQuery);
0
\ No newline at end of file
...
108
109
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
0
@@ -108,3 +108,26 @@ jspec.compress_lines = function(obj) {
0
       return "Expected " + (not ? "not " : "") + "to exist, but was " + jspec.compress_lines(this);
0
     }
0
   }
0
+
0
+ jspec.matchers["eq"] = {
0
+ describe: function(target, not) {
0
+ return jspec.compress_lines(this) + " should " + (not ? "not " : "") + "equal " + jspec.compress_lines(target)
0
+ },
0
+ matches: function(target) {
0
+ if (this instanceof Array) {
0
+ if (this.length != target.length)
0
+ return false;
0
+ for (i=0; i<this.length; i++) {
0
+ if (this[i] != target[i])
0
+ return false;
0
+ }
0
+ return true;
0
+ }
0
+ },
0
+ failure_message: function(target, not) {
0
+ if (not)
0
+ return "Expected " + jspec.compress_lines(this) + " not to equal " + jspec.compress_lines(target);
0
+ else
0
+ return "Expected " + jspec.compress_lines(this) + ". Got " + jspec.compress_lines(target);
0
+ }
0
+ }
0
\ No newline at end of file

Comments

    No one has commented yet.