96223e87 by Nicklas Ansman Giertz

Add a base for testing

This includes the following:
  * Add jasmine
  * Move the rivets build to the build folder
  * Add a guardfile that watches for source changes
  * Add a rakefile for building and minifying the source
  * Add a an example test case
  * Add vim swap files to the git ignore file
1 parent 93916c35
1 .DS_Store 1 .DS_Store
2 *.swp
......
1 source :rubygems
2
3 gem 'coffee-script'
4 gem 'closure-compiler'
5 gem 'guard'
6 gem 'guard-coffeescript'
1 GEM
2 remote: http://rubygems.org/
3 specs:
4 closure-compiler (1.1.6)
5 coffee-script (2.2.0)
6 coffee-script-source
7 execjs
8 coffee-script-source (1.3.3)
9 execjs (1.4.0)
10 multi_json (~> 1.0)
11 ffi (1.0.11)
12 guard (1.0.2)
13 ffi (>= 0.5.0)
14 thor (~> 0.14.6)
15 guard-coffeescript (0.6.0)
16 coffee-script (>= 2.2.0)
17 guard (>= 0.8.3)
18 multi_json (1.3.6)
19 thor (0.14.6)
20
21 PLATFORMS
22 ruby
23
24 DEPENDENCIES
25 closure-compiler
26 coffee-script
27 guard
28 guard-coffeescript
1 # A sample Guardfile
2 # More info at https://github.com/guard/guard#readme
3
4 guard 'coffeescript', :input => 'src', :output => 'build'
1 require 'rubygems'
2
3 BUILD_DIRECTORY = 'build'
4 SRC_DIRECTORY = 'src'
5
6 desc "build the toast-min.js files for distribution"
7 task :default => :clean do
8 FileUtils.mkdir_p(BUILD_DIRECTORY)
9 compile_js
10 end
11
12 task :build => :default
13
14 desc "removes the build directory"
15 task :clean do
16 print_action('Removing existing build directory') do
17 FileUtils.rm_rf('build')
18 end
19 end
20
21 def compile_js()
22 require 'coffee-script'
23 require 'closure-compiler'
24
25 source = File.read(File.join(SRC_DIRECTORY, 'rivets.coffee'))
26 FileUtils.mkdir_p(BUILD_DIRECTORY)
27 output = File.join(BUILD_DIRECTORY, 'rivets.js')
28 minified_output = File.join(BUILD_DIRECTORY, 'rivets-min.js')
29
30 compiled = ''
31 print_action("Compiling CoffeeScript to '#{output}'") do
32 File.open(output, 'w+') do |file|
33 compiled = CoffeeScript.compile(source)
34 file.write(compiled)
35 end
36 end
37
38 print_action("Minifying Javascript to '#{minified_output}'") do
39 File.open(minified_output, 'w+') do |file|
40 file.write(Closure::Compiler.new.compress(compiled))
41 end
42 end
43 end
44
45 def print_action(action, &block)
46 print "#{action}... "
47 STDOUT.flush
48
49 if block.call()
50 puts 'done'
51 else
52 puts 'failed'
53 end
54 end
1 (function(){var m,c,d,g,i,h,n,f,j=function(b,a){return function(){return b.apply(a,arguments)}},o=[].indexOf||function(b){for(var a=0,p=this.length;a<p;a++)if(a in this&&this[a]===b)return a;return-1};g=d=c=m=void 0;m=function(){function b(a,b,e,l,k){this.el=a;this.type=b;this.model=e;this.keypath=l;this.formatters=null!=k?k:[];this.unbind=j(this.unbind,this);this.publish=j(this.publish,this);this.bind=j(this.bind,this);this.set=j(this.set,this);this.routine=c[this.type]||i(this.type)}b.prototype.set=
2 function(a){var b,e,l,k;k=this.formatters;e=0;for(l=k.length;e<l;e++)b=k[e],a=d.formatters[b](a);return this.routine(this.el,a)};b.prototype.bind=function(){var a;d.adapter.subscribe(this.model,this.keypath,this.set);d.preloadData&&this.set(d.adapter.read(this.model,this.keypath));if(a=this.type,0<=o.call(h,a))return this.el.addEventListener("change",this.publish)};b.prototype.publish=function(a){return d.adapter.publish(this.model,this.keypath,n(a.target||a.srcElement))};b.prototype.unbind=function(){var a;
3 d.adapter.unsubscribe(this.model,this.keypath,this.set);if(a=this.type,0<=o.call(h,a))return this.el.removeEventListener("change",this.publish)};return b}();g=function(){function b(a,b){this.el=a;this.models=b;this.bind=j(this.bind,this);this.build=j(this.build,this);this.bindingRegExp=j(this.bindingRegExp,this);this.build()}b.prototype.bindingRegExp=function(){var a;return(a=d.prefix)?RegExp("^data-"+a+"-"):/^data-/};b.prototype.build=function(){var a,b,e,l,k,d,f,j,c,g,i,h;this.bindings=[];b=this.bindingRegExp();
4 i=this.el.getElementsByTagName("*");h=[];c=0;for(g=i.length;c<g;c++)k=i[c],h.push(function(){var c,i,h,g;h=k.attributes;g=[];c=0;for(i=h.length;c<i;c++)a=h[c],b.test(a.name)?(j=a.name.replace(b,""),f=a.value.split("|").map(function(a){return a.trim()}),d=f.shift().split("."),l=this.models[d.shift()],e=d.join("."),g.push(this.bindings.push(new m(k,j,l,e,f)))):g.push(void 0);return g}.call(this));return h};b.prototype.bind=function(){var a,b,e,c,d;c=this.bindings;d=[];b=0;for(e=c.length;b<e;b++)a=c[b],
5 d.push(a.bind());return d};return b}();n=function(b){switch(b.type){case "text":case "textarea":case "password":case "select-one":return b.value;case "checkbox":case "radio":return b.checked}};i=function(b){return function(a,c){return c?a.setAttribute(b,c):a.removeAttribute(b)}};f=function(b,a){null==a&&(a=!1);return function(c,d){return i(b)(c,a===!d?b:!1)}};h=["value","checked","unchecked","selected","unselected"];c={checked:f("checked"),selected:f("selected"),disabled:f("disabled"),unchecked:f("checked",
6 !0),unselected:f("selected",!0),enabled:f("disabled",!0),text:function(b,a){return null!=b.innerText?b.innerText=a||"":b.textContent=a||""},html:function(b,a){return b.innerHTML=a||""},value:function(b,a){return b.value=a},show:function(b,a){return b.style.display=a?"":"none"},hide:function(b,a){return b.style.display=a?"none":""}};d={preloadData:!0};f={configure:function(b){var a,c,e;null==b&&(b={});e=[];for(a in b)c=b[a],e.push(d[a]=c);return e},register:function(b,a){return c[b]=a},bind:function(b,
7 a){var c;null==a&&(a={});c=new g(b,a);c.bind();return c}};"undefined"!==typeof module&&null!==module?module.exports=f:this.rivets=f}).call(this);
1 // Generated by CoffeeScript 1.3.3
2 (function() { 1 (function() {
3 var Rivets, attributeBinding, bidirectionals, getInputValue, rivets, stateBinding, 2 var Rivets, attributeBinding, bidirectionals, getInputValue, rivets, stateBinding,
4 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 3 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
......
1 Copyright (c) 2008-2011 Pivotal Labs
2
3 Permission is hereby granted, free of charge, to any person obtaining
4 a copy of this software and associated documentation files (the
5 "Software"), to deal in the Software without restriction, including
6 without limitation the rights to use, copy, modify, merge, publish,
7 distribute, sublicense, and/or sell copies of the Software, and to
8 permit persons to whom the Software is furnished to do so, subject to
9 the following conditions:
10
11 The above copyright notice and this permission notice shall be
12 included in all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
2
3 #HTMLReporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; }
4 #HTMLReporter a { text-decoration: none; }
5 #HTMLReporter a:hover { text-decoration: underline; }
6 #HTMLReporter p, #HTMLReporter h1, #HTMLReporter h2, #HTMLReporter h3, #HTMLReporter h4, #HTMLReporter h5, #HTMLReporter h6 { margin: 0; line-height: 14px; }
7 #HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; }
8 #HTMLReporter #jasmine_content { position: fixed; right: 100%; }
9 #HTMLReporter .version { color: #aaaaaa; }
10 #HTMLReporter .banner { margin-top: 14px; }
11 #HTMLReporter .duration { color: #aaaaaa; float: right; }
12 #HTMLReporter .symbolSummary { overflow: hidden; *zoom: 1; margin: 14px 0; }
13 #HTMLReporter .symbolSummary li { display: block; float: left; height: 7px; width: 14px; margin-bottom: 7px; font-size: 16px; }
14 #HTMLReporter .symbolSummary li.passed { font-size: 14px; }
15 #HTMLReporter .symbolSummary li.passed:before { color: #5e7d00; content: "\02022"; }
16 #HTMLReporter .symbolSummary li.failed { line-height: 9px; }
17 #HTMLReporter .symbolSummary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
18 #HTMLReporter .symbolSummary li.skipped { font-size: 14px; }
19 #HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; }
20 #HTMLReporter .symbolSummary li.pending { line-height: 11px; }
21 #HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; }
22 #HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
23 #HTMLReporter .runningAlert { background-color: #666666; }
24 #HTMLReporter .skippedAlert { background-color: #aaaaaa; }
25 #HTMLReporter .skippedAlert:first-child { background-color: #333333; }
26 #HTMLReporter .skippedAlert:hover { text-decoration: none; color: white; text-decoration: underline; }
27 #HTMLReporter .passingAlert { background-color: #a6b779; }
28 #HTMLReporter .passingAlert:first-child { background-color: #5e7d00; }
29 #HTMLReporter .failingAlert { background-color: #cf867e; }
30 #HTMLReporter .failingAlert:first-child { background-color: #b03911; }
31 #HTMLReporter .results { margin-top: 14px; }
32 #HTMLReporter #details { display: none; }
33 #HTMLReporter .resultsMenu, #HTMLReporter .resultsMenu a { background-color: #fff; color: #333333; }
34 #HTMLReporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; }
35 #HTMLReporter.showDetails .summaryMenuItem:hover { text-decoration: underline; }
36 #HTMLReporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; }
37 #HTMLReporter.showDetails .summary { display: none; }
38 #HTMLReporter.showDetails #details { display: block; }
39 #HTMLReporter .summaryMenuItem { font-weight: bold; text-decoration: underline; }
40 #HTMLReporter .summary { margin-top: 14px; }
41 #HTMLReporter .summary .suite .suite, #HTMLReporter .summary .specSummary { margin-left: 14px; }
42 #HTMLReporter .summary .specSummary.passed a { color: #5e7d00; }
43 #HTMLReporter .summary .specSummary.failed a { color: #b03911; }
44 #HTMLReporter .description + .suite { margin-top: 0; }
45 #HTMLReporter .suite { margin-top: 14px; }
46 #HTMLReporter .suite a { color: #333333; }
47 #HTMLReporter #details .specDetail { margin-bottom: 28px; }
48 #HTMLReporter #details .specDetail .description { display: block; color: white; background-color: #b03911; }
49 #HTMLReporter .resultMessage { padding-top: 14px; color: #333333; }
50 #HTMLReporter .resultMessage span.result { display: block; }
51 #HTMLReporter .stackTrace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; }
52
53 #TrivialReporter { padding: 8px 13px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow-y: scroll; background-color: white; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; /*.resultMessage {*/ /*white-space: pre;*/ /*}*/ }
54 #TrivialReporter a:visited, #TrivialReporter a { color: #303; }
55 #TrivialReporter a:hover, #TrivialReporter a:active { color: blue; }
56 #TrivialReporter .run_spec { float: right; padding-right: 5px; font-size: .8em; text-decoration: none; }
57 #TrivialReporter .banner { color: #303; background-color: #fef; padding: 5px; }
58 #TrivialReporter .logo { float: left; font-size: 1.1em; padding-left: 5px; }
59 #TrivialReporter .logo .version { font-size: .6em; padding-left: 1em; }
60 #TrivialReporter .runner.running { background-color: yellow; }
61 #TrivialReporter .options { text-align: right; font-size: .8em; }
62 #TrivialReporter .suite { border: 1px outset gray; margin: 5px 0; padding-left: 1em; }
63 #TrivialReporter .suite .suite { margin: 5px; }
64 #TrivialReporter .suite.passed { background-color: #dfd; }
65 #TrivialReporter .suite.failed { background-color: #fdd; }
66 #TrivialReporter .spec { margin: 5px; padding-left: 1em; clear: both; }
67 #TrivialReporter .spec.failed, #TrivialReporter .spec.passed, #TrivialReporter .spec.skipped { padding-bottom: 5px; border: 1px solid gray; }
68 #TrivialReporter .spec.failed { background-color: #fbb; border-color: red; }
69 #TrivialReporter .spec.passed { background-color: #bfb; border-color: green; }
70 #TrivialReporter .spec.skipped { background-color: #bbb; }
71 #TrivialReporter .messages { border-left: 1px dashed gray; padding-left: 1em; padding-right: 1em; }
72 #TrivialReporter .passed { background-color: #cfc; display: none; }
73 #TrivialReporter .failed { background-color: #fbb; }
74 #TrivialReporter .skipped { color: #777; background-color: #eee; display: none; }
75 #TrivialReporter .resultMessage span.result { display: block; line-height: 2em; color: black; }
76 #TrivialReporter .resultMessage .mismatch { color: black; }
77 #TrivialReporter .stackTrace { white-space: pre; font-size: .8em; margin-left: 10px; max-height: 5em; overflow: auto; border: 1px inset red; padding: 1em; background: #eef; }
78 #TrivialReporter .finished-at { padding-left: 1em; font-size: .6em; }
79 #TrivialReporter.show-passed .passed, #TrivialReporter.show-skipped .skipped { display: block; }
80 #TrivialReporter #jasmine_content { position: fixed; right: 100%; }
81 #TrivialReporter .runner { border: 1px solid gray; display: block; margin: 5px 0; padding: 2px 0 2px 10px; }
1 function Data(attributes) {
2 this.attributes = attributes || {};
3 this.change = {}
4 }
5
6 Data.prototype.on = function(key, callback) {
7 this.change[key][callback] = true;
8 }
9
10 Data.prototype.off = function(key, callback) {
11 delete this.change[key][callback];
12 }
13
14 Data.prototype.set = function(attributes) {
15 var old, key;
16
17 for(key in attributes) {
18 old = this.attributes[key];
19 this.attributes[key] = attributes[key];
20 if(this.get(key) !== old)
21 this.alertCallbacks(key);
22 }
23 }
24
25 Data.prototype.get = function(key) {
26 this.attributes[key];
27 }
28
29 Data.prototype.alertCallbacks = function(key) {
30 if(!this.change[key])
31 return;
32
33 for(callback in this.change[key])
34 callback(this.get(key));
35 }
36
37 window.Data = Data;
1 rivets.configure({
2 adapter: {
3 subscribe: function(obj, keypath, callback) {
4 obj.on(keypath, callback);
5 },
6 read: function(obj, keypath) {
7 obj.get(keypath);
8 },
9 publish: function(obj, keypath, value) {
10 attributes = {};
11 attributes[keypath] = value;
12 obj.set(attributes);
13 }
14 }
15 });
16
17
18 describe('Rivets: ', function() {
19 var data;
20
21 beforeEach(function() {
22 data = new Data();
23 });
24
25 describe('Stuff', function() {
26 it('should work', function() {
27 expect(data.get('foo')).toBe(undefined);
28 expect(data.get('bar')).toBe('not undefined');
29 });
30 });
31 });
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <title>Rivets test suite</title>
6
7 <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.2.0/jasmine_favicon.png">
8 <link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0/jasmine.css">
9 <script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
10 <script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>
11
12 <script type="text/javascript" src="build/rivets.js"></script>
13
14 <script type="text/javascript" src="spec/mock.data.js"></script>
15 <script type="text/javascript" src="spec/rivets.js"></script>
16
17 <script type="text/javascript">
18 (function() {
19 var jasmineEnv = jasmine.getEnv();
20 jasmineEnv.updateInterval = 250;
21
22 var htmlReporter = new jasmine.HtmlReporter();
23
24 jasmineEnv.addReporter(htmlReporter);
25
26 jasmineEnv.specFilter = function(spec) {
27 return htmlReporter.specFilter(spec);
28 };
29
30 var currentWindowOnload = window.onload;
31
32 window.onload = function() {
33 if (currentWindowOnload) {
34 currentWindowOnload();
35 }
36 execJasmine();
37 };
38
39 function execJasmine() {
40 jasmineEnv.execute();
41 }
42
43 })();
44 </script>
45
46 </head>
47
48 <body>
49 </body>
50 </html>