")
9 | var hoverenters = 0,
10 | hoverinits = 0,
11 | hoverleaves = 0,
12 | delay = 15;
13 | $("#hover").bind("hoverinit", function(ev, hover){
14 | hover.delay(delay);
15 | hoverinits++;
16 | })
17 | .bind('hoverenter', function(){
18 | hoverenters++;
19 | })
20 | .bind('hoverleave',function(){
21 | hoverleaves++;
22 | })
23 | var hover = $("#hover")
24 | var off = hover.offset();
25 |
26 | //add a mouseenter, and 2 mouse moves
27 | Syn("mouseover",{pageX: off.top, pageY: off.left}, hover[0])
28 | ok(hoverinits, 'hoverinit');
29 | ok(hoverenters === 0,"hoverinit hasn't been called");
30 | stop();
31 |
32 | setTimeout(function(){
33 | ok(hoverenters === 1,"hoverenter has been called");
34 |
35 | ok(hoverleaves === 0,"hoverleave hasn't been called");
36 | Syn("mouseout",{pageX: off.top, pageY: off.left},hover[0]);
37 |
38 | ok(hoverleaves === 1,"hoverleave has been called");
39 |
40 | delay = 30;
41 |
42 | Syn("mouseover",{pageX: off.top, pageY: off.left},hover[0]);
43 | ok(hoverinits === 2, 'hoverinit');
44 |
45 | setTimeout(function(){
46 |
47 | Syn("mouseout",{pageX: off.top, pageY: off.left},hover[0]);
48 |
49 |
50 | setTimeout(function(){
51 | ok(hoverenters === 1,"hoverenter was not called");
52 | ok(hoverleaves === 1,"hoverleave was not called");
53 | start();
54 | },30)
55 |
56 | },10)
57 |
58 | },30)
59 | });
60 |
61 | });
62 |
--------------------------------------------------------------------------------
/event/hover/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/event/key/key.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
jQuery Event Key
6 |
9 |
10 |
11 |
12 |
Type in input:
13 |
Keydown:
14 |
Keypress:
15 |
Keyup:
16 |
17 |
31 |
32 |
--------------------------------------------------------------------------------
/event/key/key_test.js:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit','funcunit/syn','jquery/event/key').then(function(){
2 |
3 | module('jquery/event/key');
4 |
5 | test("type some things", function(){
6 | $("#qunit-test-area").append("
")
7 | var keydown, keypress, keyup;
8 | $('#key').keydown(function(ev){
9 | keydown = ev.keyName();
10 | }).keypress(function(ev){
11 | keypress = ev.keyName();
12 | }).keyup(function(ev){
13 | keyup = ev.keyName();
14 | });
15 |
16 | stop();
17 |
18 | Syn.key("a","key", function(){
19 | equals(keydown, "a","keydown");
20 | equals(keypress,"a","keypress");
21 | equals(keyup, "a","keyup");
22 | start();
23 | });
24 | })
25 |
26 | })
27 |
--------------------------------------------------------------------------------
/event/key/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/event/pause/pause_test.js:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit','funcunit/syn','jquery/event/pause').then(function(){
2 |
3 | module("jquery/event/pause", {setup : function(){
4 | $("#qunit-test-area").html("")
5 | var div = $("
"+
6 | "Hello
"+
7 | ""+
8 | " ").appendTo($("#qunit-test-area"));
9 |
10 | }});
11 |
12 | test("basics",3, function(){
13 |
14 | var calls =0,
15 | lastTime,
16 | space = function(){
17 | if(lastTime){
18 |
19 | ok(new Date - lastTime > 35,"space between times "+(new Date - lastTime))
20 | }
21 | lastTime = new Date()
22 | };
23 |
24 | $('#ul').delegate("li", "show",function(ev){
25 | calls++;
26 | space();
27 |
28 | ev.pause();
29 |
30 | setTimeout(function(){
31 | ev.resume();
32 | },100)
33 |
34 | })
35 |
36 | $('#wrapper').bind('show', function(){
37 | space()
38 | equals(calls, 2, "both lis called");
39 | start()
40 | });
41 | stop();
42 | $('#foo').trigger("show")
43 | });
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | });
--------------------------------------------------------------------------------
/event/pause/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
swipe QUnit Test
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/event/resize/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
Resize QUnit Test
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/event/resize/resize.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
selection
6 |
15 |
16 |
17 |
Click an element to see who gets resized as a result. Elements with red borders are
18 | resizable.
19 |
20 | Hello World
21 | Hello World2
22 |
25 |
26 | JavaScriptMVC is just WAY smart
27 |
28 |
43 |
46 |
47 |
--------------------------------------------------------------------------------
/event/resize/resize_test.js:
--------------------------------------------------------------------------------
1 |
2 | steal('funcunit/qunit', 'jquery/event/resize').then(function() {
3 |
4 | module("jquery/event/resize")
5 |
6 |
7 | test("resize hits only children in order", function() {
8 | var ids = []
9 | record = function( ev ) {
10 | ids.push(this.id ? this.id : this)
11 | },
12 | divs = $("#qunit-test-area").html("
").find('div').bind('resize', record);
13 |
14 | $(document.body).bind('resize', record);
15 |
16 | $("#qunit-test-area").children().eq(0).trigger("resize");
17 |
18 | same(ids, ['1', '1.1', '1.2'])
19 |
20 | ids = [];
21 | $("#qunit-test-area").trigger("resize");
22 | same(ids, [document.body, '1', '1.1', '1.2', '2']);
23 |
24 | ids = [];
25 | $(window).trigger("resize");
26 | same(ids, [document.body, '1', '1.1', '1.2', '2']);
27 |
28 | $(document.body).unbind('resize', record);
29 | });
30 |
31 | test("resize stopping prop", function() {
32 | var ids = []
33 | record = function( ev ) {
34 |
35 | ids.push(this.id ? this.id : this)
36 | if ( this.id == '1' ) {
37 | ev.stopPropagation();
38 | }
39 | },
40 | divs = $("#qunit-test-area").html("
").find('div').bind('resize', record);
41 |
42 | $(document.body).bind('resize', record);
43 |
44 | $(window).trigger("resize");
45 | same(ids, [document.body, '1', '2']);
46 |
47 | $(document.body).unbind('resize', record);
48 | });
49 |
50 | test("resize event cascades from target", function() {
51 |
52 | var ids = [],
53 | record = function( ev ) {
54 | ids.push(this.id ? this.id : this);
55 | },
56 |
57 | divs = $("#qunit-test-area").html("
");
58 |
59 | divs.find("#1\\.1\\.1").bind("resize", record);
60 | divs.find("#1").bind("resize", record);
61 |
62 | $("#1\\.1").trigger("resize", [false]);
63 | same(ids, ['1.1.1']);
64 |
65 | $("#qunit-test-area").empty();
66 | });
67 |
68 |
69 | })
--------------------------------------------------------------------------------
/event/selection/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
selection QUnit Test
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/event/selection/selection_test.js:
--------------------------------------------------------------------------------
1 | steal("funcunit/qunit", "jquery/dom/selection").then(function(){
2 |
3 | module("jquery/dom/selection");
4 |
5 | test("getCharElement", function(){
6 | $("#qunit-test-area")
7 | .html("
"+
8 | "
"+
9 | "
0123456789
"+
10 | "
");
11 | stop();
12 | setTimeout(function(){
13 | var types = ['textarea','#inp','#1','#2'];
14 | for(var i =0; i< types.length; i++){
15 | console.log(types[i])
16 | $(types[i]).selection(1,5);
17 | }
18 | /*
19 | $('textarea').selection(1,5);
20 | $('input').selection(1,5);
21 | $('#1').selection(1,5);
22 | $('#2').selection(1,5);
23 | */
24 | var res = [];
25 | for(var i =0; i< types.length; i++){
26 | res.push( $(types[i]).selection() );
27 | }
28 |
29 |
30 |
31 | for(var i =0; i< res.length; i++){
32 | same(res[i],{start: 1, end: 5},types[i])
33 | }
34 |
35 | start();
36 | },1000)
37 | });
38 |
39 | });
--------------------------------------------------------------------------------
/event/swipe/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
swipe QUnit Test
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/event/swipe/swipe.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
swipe
6 |
21 |
22 |
23 |
Swipe Me
24 |
Swipes
25 |
26 | Swipe Me
27 | Swipe Me
28 | Swipe Me
29 | Swipe Me
30 |
31 |
32 |
49 |
50 |
--------------------------------------------------------------------------------
/event/swipe/swipe_test.js:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit','funcunit/syn','jquery/event/swipe').then(function(){
2 |
3 | module("jquery/swipe", {setup : function(){
4 | $("#qunit-test-area").html("")
5 | var div = $("
"+
6 | "
one
"+
7 | "
"+
8 | "
");
9 |
10 | div.appendTo($("#qunit-test-area"));
11 | var basicCss = {
12 | position: "absolute",
13 | border: "solid 1px black"
14 | }
15 | $("#outer").css(basicCss).css({top: "10px", left: "10px",
16 | zIndex: 1000, backgroundColor: "green", width: "200px", height: "200px"})
17 | }});
18 |
19 | test("swipe right event",2, function(){
20 |
21 | $("#outer").bind("swipe",function(){
22 | ok(true,"swipe called");
23 | }).bind("swipeleft", function(){
24 | ok(false, "swipe left")
25 | }).bind("swiperight", function(){
26 | ok(true, "swiperight")
27 | });
28 | stop();
29 | Syn.drag({
30 | from: "20x20",
31 | to: "50x20",
32 | duration: 100,
33 | },"outer", function(){
34 | start();
35 | })
36 |
37 | });
38 |
39 |
40 | test("swipe left event",2, function(){
41 |
42 | $("#outer").bind("swipe",function(){
43 | ok(true,"swipe called");
44 | }).bind("swipeleft", function(){
45 | ok(true, "swipe left")
46 | }).bind("swiperight", function(){
47 | ok(false, "swiperight")
48 | });
49 | stop();
50 | Syn.drag({
51 | from: "50x20",
52 | to: "20x20",
53 | duration: 100,
54 | },"outer", function(){
55 | start();
56 | })
57 |
58 | });
59 |
60 |
61 | test("swipe up event",2, function(){
62 |
63 | $("#outer").bind("swipe",function(){
64 | ok(true,"swipe called");
65 | }).bind("swipeup", function(){
66 | ok(true, "swipe left")
67 | }).bind("swiperight", function(){
68 | ok(false, "swiperight")
69 | }).bind("swipedown", function(){
70 | ok(false, "swipedown")
71 | });
72 | stop();
73 | Syn.drag({
74 | from: "20x50",
75 | to: "20x20",
76 | duration: 100,
77 | },"outer", function(){
78 | start();
79 | })
80 |
81 | });
82 |
83 | test("swipe down event",2, function(){
84 |
85 | $("#outer").bind("swipe",function(){
86 | ok(true,"swipe called");
87 | }).bind("swipeup", function(){
88 | ok(false, "swipe left")
89 | }).bind("swiperight", function(){
90 | ok(false, "swiperight")
91 | }).bind("swipedown", function(){
92 | ok(true, "swipedown")
93 | });
94 | stop();
95 | Syn.drag({
96 | from: "20x20",
97 | to: "20x50",
98 | duration: 100,
99 | },"outer", function(){
100 | start();
101 | })
102 |
103 | });
104 |
105 |
106 |
107 |
108 |
109 |
110 | })
--------------------------------------------------------------------------------
/event/tap/tap.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
select
6 |
21 |
22 |
23 |
I'd Tap That
24 |
27 |
32 |
33 |
--------------------------------------------------------------------------------
/event/tap/tap.js:
--------------------------------------------------------------------------------
1 | steal('jquery/event/livehack').then(function($){
2 | var supportTouch = "ontouchend" in document,
3 | scrollEvent = "touchmove scroll",
4 | touchStartEvent = supportTouch ? "touchstart" : "mousedown",
5 | touchStopEvent = supportTouch ? "touchend" : "mouseup",
6 | touchMoveEvent = supportTouch ? "touchmove" : "mousemove",
7 | data = function(event){
8 | var d = event.originalEvent.touches ?
9 | event.originalEvent.touches[ 0 ] || event.originalEvent.changedTouches[ 0 ] :
10 | event;
11 | return {
12 | time: (new Date).getTime(),
13 | coords: [ d.pageX, d.pageY ],
14 | origin: $( event.target )
15 | };
16 | };
17 |
18 | /**
19 | * @add jQuery.event.special
20 | */
21 | $.event.setupHelper( ["tap"], touchStartEvent, function(ev){
22 | //listen to mouseup
23 | var start = data(ev),
24 | stop,
25 | delegate = ev.delegateTarget || ev.currentTarget,
26 | selector = ev.handleObj.selector,
27 | entered = this,
28 | moved = false,
29 | touching = true,
30 | timer;
31 |
32 |
33 | function upHandler(event){
34 | stop = data(event);
35 | if ((Math.abs( start.coords[0] - stop.coords[0] ) < 10) &&
36 | ( Math.abs( start.coords[1] - stop.coords[1] ) < 10) ){
37 | $.each($.event.find(delegate, ["tap"], selector), function(){
38 | this.call(entered, ev, {start : start, end: stop})
39 | })
40 | }
41 | };
42 |
43 | timer = setTimeout(function() {
44 | $(delegate).unbind(touchStopEvent, upHandler);
45 | }, 500 );
46 |
47 | $(delegate).one(touchStopEvent, upHandler);
48 |
49 | });
50 |
51 | });
--------------------------------------------------------------------------------
/generate/app:
--------------------------------------------------------------------------------
1 | // _args = ['cookbook']; load('steal/generate/app')
2 |
3 | if (!_args[0]) {
4 | print("Usage: steal/js steal/generate/app path");
5 | quit();
6 | }
7 |
8 | load('steal/rhino/rhino.js');
9 |
10 | steal('steal/generate','steal/generate/system.js',function(steal){
11 | var classed = steal.generate.toClass(_args[0]),
12 | md = steal.generate.convert(classed),
13 | data = steal.extend({
14 | path: _args[0],
15 | application_name: md.underscore,
16 | current_path: steal.File.cwdURL(),
17 | path_to_steal : steal.File(_args[0]).pathToRoot()
18 | }, steal.system);
19 |
20 |
21 | steal.generate("jquery/generate/templates/app", _args[0], data);
22 | });
23 |
24 |
--------------------------------------------------------------------------------
/generate/coffee/controller:
--------------------------------------------------------------------------------
1 | if (_args.length < 1) {
2 | print("USAGE : steal/js steal/generate/coffee/controller Company.Widget")
3 | print("EX : steal/js steal/generate/coffee/controller Company.WidgetName");
4 | print(" > company/widget_name/widget_name.coffee")
5 | print();
6 | quit();
7 | }
8 |
9 | load('steal/rhino/rhino.js');
10 |
11 | steal( '//steal/generate/generate',
12 | '//steal/generate/system',
13 | function(steal){
14 | var upper = function(parts){
15 | for(var i =0; i < parts.length; i++){
16 | parts[i] = parts[i].charAt(0).toUpperCase()+parts[i].substr(1)
17 | }
18 | return parts
19 | }
20 |
21 | if(_args[0].charAt(0) !== _args[0].charAt(0).toUpperCase()){
22 | var caps = upper( _args[0].split(/_|-/) ).join(''),
23 | name = upper(caps.split("/")).join('.');
24 |
25 | print(" Creating "+name);
26 | _args[0] = name;
27 | }
28 |
29 | var md = steal.generate.convert(_args[0]),
30 | path = _args[0].toLowerCase().replace('.',"/");
31 | md.path_to_steal = new steal.File(path).pathToRoot()
32 | steal.generate("jquery/generate/coffee/templates/controller",md.path+"/"+md.underscore,md)
33 |
34 | });
35 |
36 |
--------------------------------------------------------------------------------
/generate/coffee/templates/controller/(underscore).coffee.ejs:
--------------------------------------------------------------------------------
1 | steal "jquery/controller",
2 | ($) ->
3 |
4 | $.Controller "<%= name %>",
5 | {
6 | defaults : {},
7 | },
8 | {
9 | init : ->
10 | @element.html "Hello World!"
11 | }
12 |
--------------------------------------------------------------------------------
/generate/coffee/templates/controller/(underscore).html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
<%= name %>
5 |
11 |
12 |
13 |
<%= name %> Demo
14 |
15 |
18 |
23 |
24 |
--------------------------------------------------------------------------------
/generate/coffee/templates/controller/(underscore)_test.coffee.ejs:
--------------------------------------------------------------------------------
1 | steal "funcunit",
2 | ->
3 | module "<%= fullName %>", setup: ->
4 | S.open "//<%= path %>/<%=underscore%>/<%=underscore%>.html"
5 |
6 | test "Text Test", ->
7 | equals S("h1").text(), "<%= fullName %> Demo", "demo text"
--------------------------------------------------------------------------------
/generate/coffee/templates/controller/funcunit.html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
<%= name %> FuncUnit Test
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/generate/controller:
--------------------------------------------------------------------------------
1 | if (_args.length < 1) {
2 | print("USAGE : steal/js steal/generate/controller Company.Widget")
3 | print("EX : steal/js steal/generate/controller Company.WidgetName");
4 | print(" > company/widget_name/widget_name.js")
5 | print();
6 | quit();
7 | }
8 |
9 | load('steal/rhino/rhino.js');
10 |
11 | steal( 'steal/generate',
12 | 'steal/generate/system.js',
13 | function(steal){
14 | var upper = function(parts){
15 | for(var i =0; i < parts.length; i++){
16 | parts[i] = parts[i].charAt(0).toUpperCase()+parts[i].substr(1)
17 | }
18 | return parts
19 | }
20 |
21 | if(_args[0].charAt(0) !== _args[0].charAt(0).toUpperCase()){
22 | var caps = upper( _args[0].split(/_|-/) ).join(''),
23 | name = upper(caps.split("/")).join('.');
24 |
25 | print(" Creating "+name);
26 | _args[0] = name;
27 | }
28 |
29 | var md = steal.generate.convert(_args[0]),
30 | path = _args[0].toLowerCase().replace(/\./g,"/");
31 |
32 | md.path_to_steal = new steal.File(path).pathToRoot()
33 | steal.generate("jquery/generate/templates/controller",md.path+"/"+md.underscore,md)
34 |
35 | });
36 |
37 |
--------------------------------------------------------------------------------
/generate/model:
--------------------------------------------------------------------------------
1 | if (_args.length < 1) {
2 | print("USAGE : js jquery/generate/model cookbook/models/recipe")
3 | print();
4 | quit();
5 | }
6 |
7 | load('steal/rhino/rhino.js');
8 |
9 | steal( 'steal/generate',
10 | 'steal/generate/system.js',
11 | 'steal/generate/inflector.js',
12 | function(steal){
13 |
14 | var upper = function(parts){
15 | for(var i =0; i < parts.length; i++){
16 | parts[i] = parts[i].charAt(0).toUpperCase()+parts[i].substr(1)
17 | }
18 | return parts
19 | }
20 |
21 | if(_args[0].charAt(0) !== _args[0].charAt(0).toUpperCase()){
22 | var caps = upper( _args[0].split(/_|-/) ).join(''),
23 | name = upper(caps.split("/")).join('.');
24 |
25 | print(" Creating "+name);
26 | _args[0] = name;
27 | }
28 |
29 | var md = steal.generate.convert(_args[0]),
30 | path = _args[0].toLowerCase().replace('.',"/");
31 |
32 | var folder = md.path.replace(/\/\w+$/, "")
33 | if(!folder){
34 | print("! Error: Models need to be part of an app");
35 | quit();
36 | }
37 | if(!steal.File(folder).exists()){
38 | print("! Error: folder "+folder+" does not exist!");
39 | quit();
40 | }
41 |
42 | md.path_to_steal = new steal.File(path).pathToRoot();
43 | md.appPath = md.path.replace(/\/models$/,"");
44 |
45 | //check pluralization of last part
46 | if(steal.Inflector.singularize(md.underscore) !== md.underscore){
47 | print("! Warning: Model names should be singular. I don't think "+md.underscore+" is singular!")
48 | }
49 |
50 |
51 | // generate the files
52 | steal.generate("jquery/generate/templates/model", md.appPath, md)
53 |
54 | try{
55 | // steal this model in models.js
56 | steal.generate.insertSteal(md.appPath+"/models/models.js", "./"+md.underscore+".js");
57 |
58 | // steal this model's unit test in qunit.js
59 | steal.generate.insertSteal(md.appPath+"/test/qunit/qunit.js", "./"+md.underscore+"_test.js");
60 | } catch (e) {
61 | if(e.type && e.type == "DUPLICATE"){
62 | print("! Error: This model was already created!")
63 | quit();
64 | }
65 | }
66 |
67 | // $.fixture.make for this model in fixtures.js
68 | var text = readFile("jquery/generate/templates/fixturemake.ejs");
69 | var fixturetext = new steal.EJS({
70 | text: text
71 | }).render(md);
72 | steal.generate.insertCode(md.appPath+"/fixtures/fixtures.js", fixturetext);
73 |
74 | });
--------------------------------------------------------------------------------
/generate/page:
--------------------------------------------------------------------------------
1 | if (_args.length < 2) {
2 | print("Creates an html page that loads one of your applications.\n")
3 | print("USAGE: js steal/generate/test app_name page_location\n")
4 | print();
5 | quit();
6 | }
7 |
8 | load('steal/rhino/rhino.js');
9 |
10 | steal('steal/generate','steal/generate/system.js',function(steal){
11 | var path = _args[0].toLowerCase().replace('.',"/")
12 | var data = steal.extend({
13 | path: path,
14 | application_name: path.match(/[^\/]*$/)[0],
15 | current_path: steal.File.cwdURL(),
16 | path_to_steal : new steal.File(path).pathToRoot()
17 | }, steal.system)
18 |
19 | var to = path+"/"+_args[1];
20 | steal.generate.render("jquery/generate/templates/page.ejs", to, data)
21 | });
--------------------------------------------------------------------------------
/generate/plugin:
--------------------------------------------------------------------------------
1 | // _args = ['thing']; load('steal/generate/app')
2 |
3 | if (!_args[0]) {
4 | print("Usage: steal/js steal/generate/plugin path");
5 | quit();
6 | }
7 | load('steal/rhino/rhino.js');
8 |
9 | steal('steal/generate',function(steal){
10 | var data = steal.extend({
11 | path: _args[0],
12 | application_name: _args[0].match(/[^\/]*$/)[0],
13 | current_path: steal.File.cwdURL(),
14 | path_to_steal : new steal.File(_args[0]).pathToRoot()
15 | }, steal.system)
16 |
17 | steal.generate("jquery/generate/templates/plugin",_args[0],data)
18 |
19 | })();
20 |
21 |
--------------------------------------------------------------------------------
/generate/scaffold:
--------------------------------------------------------------------------------
1 | if (_args.length < 1) {
2 | print("USAGE : steal/js steal/generate/scaffold FullName Type")
3 | print("TYPES : JsonRest\n")
4 | print("EX : js steal/generate/scaffold Cashnet.Models.Customer");
5 | print(" > cashnet/models/customer.js ....")
6 | print();
7 | quit();
8 | }
9 |
10 | load('steal/rhino/rhino.js');
11 |
12 | steal( 'steal/generate',
13 | 'steal/generate/system.js',
14 | 'jquery/generate/templates/model.js',
15 | function(steal){
16 | //check capitalization
17 |
18 | steal.generate.model(_args[0]);
19 |
20 | var parts = _args[0].split("."), part;
21 |
22 | for(var i=0; i< parts.length;i++){
23 | part = parts[i];
24 | if( part[0] !== part[0].toUpperCase() ){
25 | print("! Warning: "+part+" should probably be capitalized. JavaScriptMVC likes capital namespaces and class names.")
26 | }
27 | parts[i] = steal.generate.underscore(part);
28 | }
29 | // check folders
30 | var folder = parts.slice(0, parts.length-1).join("/");
31 | if(!folder){
32 | print("! Error: Scaffolding needs to be part of an app");
33 | quit();
34 | }
35 | if(!steal.File(folder).exists()){
36 | print("! Error: folder "+folder+" does not exist!");
37 | quit();
38 | }
39 | //check pluralization of last part
40 | if(steal.Inflector.singularize(part) !== part){
41 | print("! Warning: Model names should be singular. I don't think "+part+
42 | " is singular!")
43 | }
44 |
45 | var md = steal.generate.convert(_args[0]);
46 |
47 | md.type = _args[1]
48 |
49 | md.appPath = md.path.replace(/\/models$/,"");
50 | md.baseName = md.name.replace(/\.Models.*/, "."+md.className);
51 | steal.generate("jquery/generate/templates/scaffold",md.appPath+"/"+md.underscore,md);
52 |
53 | steal.generate.insertSteal(
54 | md.appPath+"/test/funcunit/funcunit.js",
55 | md.appPath+"/"+md.underscore+"/create/create_test.js");
56 |
57 | steal.generate.insertSteal(
58 | md.appPath+"/test/funcunit/funcunit.js",
59 | md.appPath+"/"+md.underscore+"/list/list_test.js")
60 |
61 | steal.generate.insertSteal(
62 | md.appPath+"/"+md.appPath+".js",
63 | md.appPath+"/"+md.underscore+"/create", true)
64 | steal.generate.insertSteal(
65 | md.appPath+"/"+md.appPath+".js",
66 | md.appPath+"/"+md.underscore+"/list", true)
67 |
68 |
69 | var text = readFile("jquery/generate/templates/scaffoldHookup.ejs");
70 | var hookup = new steal.EJS({
71 | text: text
72 | }).render(md);
73 | steal.generate.insertCode(md.appPath+"/"+md.appPath+".js", hookup );
74 | });
--------------------------------------------------------------------------------
/generate/templates/app/(application_name).css.ejs:
--------------------------------------------------------------------------------
1 | body {
2 | font-family:Lucida Sans,Lucida Grande,Arial,sans-serif;
3 | margin:0;
4 | line-height:22px;
5 | width:960px;
6 | margin:0 auto;
7 | }
8 | h1 {
9 | padding:30px 0 10px;
10 | margin-top:0;
11 | line-height:30px;
12 | }
13 |
14 | ul{
15 | padding:0 0 0 15px;
16 | list-style : none;
17 | }
18 |
19 | a {
20 | color:#ae3d26;
21 | text-decoration:none;
22 | }
23 |
24 | a:hover { text-decoration:underline; }
25 |
26 | hr {
27 | border:none;
28 | border-top:1px dotted #000;
29 | }
--------------------------------------------------------------------------------
/generate/templates/app/(application_name).html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
<%= application_name %>
5 |
6 |
7 |
Welcome to JavaScriptMVC 3.2!
8 |
9 | Steal plugins and files in <%= path %>/<%= application_name %>.js .
10 | Change to production mode by changing steal.js to steal.production.js in this file.
11 |
12 |
13 |
Here are some links to get you started:
14 |
20 |
21 |
Join the community:
22 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/generate/templates/app/(application_name).js.ejs:
--------------------------------------------------------------------------------
1 | steal(
2 | './<%= application_name %>.css', // application CSS file
3 | './models/models.js', // steals all your models
4 | './fixtures/fixtures.js', // sets up fixtures for your models
5 | function(){ // configure your application
6 |
7 | })
--------------------------------------------------------------------------------
/generate/templates/app/(application_name).md.ejs:
--------------------------------------------------------------------------------
1 | @page index <%= application_name %>
2 |
3 | This is a placeholder for the homepage of your documentation.
--------------------------------------------------------------------------------
/generate/templates/app/docs/.ignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jupiterjs/jquerymx/0f917a85327a6c0196c2cf28c1d90a9095e0eae1/generate/templates/app/docs/.ignore
--------------------------------------------------------------------------------
/generate/templates/app/fixtures/.ignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jupiterjs/jquerymx/0f917a85327a6c0196c2cf28c1d90a9095e0eae1/generate/templates/app/fixtures/.ignore
--------------------------------------------------------------------------------
/generate/templates/app/fixtures/fixtures.js.ejs:
--------------------------------------------------------------------------------
1 | // map fixtures for this application
2 |
3 | steal("jquery/dom/fixture", function(){
4 |
5 | })
--------------------------------------------------------------------------------
/generate/templates/app/funcunit.html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
<%= application_name%> FuncUnit Test
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/generate/templates/app/models/.ignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jupiterjs/jquerymx/0f917a85327a6c0196c2cf28c1d90a9095e0eae1/generate/templates/app/models/.ignore
--------------------------------------------------------------------------------
/generate/templates/app/models/models.js.ejs:
--------------------------------------------------------------------------------
1 | // steal model files
2 | steal("jquery/model")
--------------------------------------------------------------------------------
/generate/templates/app/qunit.html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
<%= application_name%> QUnit Test
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/generate/templates/app/scripts/build.html.ejs:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
<%= application_name %> Build Page
6 |
7 |
8 |
<%= application_name %> Build Page
9 |
This is a dummy page that loads your app so steal can
10 | get all the files.
11 |
12 |
If you built your app
13 | to depend on HTML in the page before DOMContent loaded or
14 | onload, you can add the HTML here, or you can change the
15 | build.js script to point to a better html file.
16 |
17 |
20 |
21 |
--------------------------------------------------------------------------------
/generate/templates/app/scripts/build.js.ejs:
--------------------------------------------------------------------------------
1 | //js <%= path %>/scripts/build.js
2 |
3 | load("steal/rhino/rhino.js");
4 | steal('steal/build').then('steal/build/scripts','steal/build/styles',function(){
5 | steal.build('<%= path %>/scripts/build.html',{to: '<%= path %>'});
6 | });
7 |
--------------------------------------------------------------------------------
/generate/templates/app/scripts/clean.js.ejs:
--------------------------------------------------------------------------------
1 | //steal/js <%= path %>/scripts/compress.js
2 |
3 | load("steal/rhino/rhino.js");
4 | steal('steal/clean',function(){
5 | steal.clean('<%= path %>/<%= application_name %>.html',{
6 | indent_size: 1,
7 | indent_char: '\t',
8 | jslint : false,
9 | ignore: /jquery\/jquery.js/,
10 | predefined: {
11 | steal: true,
12 | jQuery: true,
13 | $ : true,
14 | window : true
15 | }
16 | });
17 | });
18 |
--------------------------------------------------------------------------------
/generate/templates/app/scripts/crawl.js.ejs:
--------------------------------------------------------------------------------
1 | // load('<%= path %>/scripts/crawl.js')
2 |
3 | load('steal/rhino/rhino.js')
4 |
5 | steal('steal/html/crawl', function(){
6 | steal.html.crawl("<%= path %>/<%= application_name %>.html","<%= path %>/out")
7 | });
8 |
--------------------------------------------------------------------------------
/generate/templates/app/scripts/docs.js.ejs:
--------------------------------------------------------------------------------
1 | //js <%= path %>/scripts/doc.js
2 |
3 | load('steal/rhino/rhino.js');
4 | steal("documentjs").then(function(){
5 | DocumentJS('<%= path %>/<%= application_name %>.html', {
6 | markdown : ['<%= application_name %>']
7 | });
8 | });
--------------------------------------------------------------------------------
/generate/templates/app/test/funcunit/(application_name)_test.js.ejs:
--------------------------------------------------------------------------------
1 | steal("funcunit", function(){
2 | module("<%=application_name%> test", {
3 | setup: function(){
4 | S.open("//<%= path %>/<%=application_name%>.html");
5 | }
6 | });
7 |
8 | test("Copy Test", function(){
9 | equals(S("h1").text(), "Welcome to JavaScriptMVC 3.2!","welcome text");
10 | });
11 | })
--------------------------------------------------------------------------------
/generate/templates/app/test/funcunit/funcunit.js.ejs:
--------------------------------------------------------------------------------
1 | steal("funcunit")
2 | .then("./<%= application_name %>_test.js");
--------------------------------------------------------------------------------
/generate/templates/app/test/qunit/(application_name)_test.js.ejs:
--------------------------------------------------------------------------------
1 | steal("funcunit/qunit", function(){
2 | module("<%= application_name %>");
3 |
4 | test("<%= application_name %> testing works", function(){
5 | ok(true,"an assert is run");
6 | });
7 | })
--------------------------------------------------------------------------------
/generate/templates/app/test/qunit/qunit.js.ejs:
--------------------------------------------------------------------------------
1 | steal("funcunit/qunit", "./<%= application_name %>_test.js");
--------------------------------------------------------------------------------
/generate/templates/controller/(underscore).html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
<%= name %>
5 |
11 |
12 |
13 |
<%= name %> Demo
14 |
15 |
18 |
24 |
25 |
--------------------------------------------------------------------------------
/generate/templates/controller/(underscore).js.ejs:
--------------------------------------------------------------------------------
1 | steal( 'jquery/controller','jquery/view/ejs' )
2 | .then( './views/init.ejs', function($){
3 |
4 | /**
5 | * @class <%= name %>
6 | */
7 | $.Controller('<%= name %>',
8 | /** @Static */
9 | {
10 | defaults : {}
11 | },
12 | /** @Prototype */
13 | {
14 | init : function(){
15 | this.element.html("//<%= path %>/<%= underscore %>/views/init.ejs",{
16 | message: "Hello World"
17 | });
18 | }
19 | })
20 |
21 | });
--------------------------------------------------------------------------------
/generate/templates/controller/(underscore)_test.js.ejs:
--------------------------------------------------------------------------------
1 | steal('funcunit').then(function(){
2 |
3 | module("<%= fullName %>", {
4 | setup: function(){
5 | S.open("//<%= path %>/<%=underscore%>/<%=underscore%>.html");
6 | }
7 | });
8 |
9 | test("Text Test", function(){
10 | equals(S("h1").text(), "<%= fullName %> Demo","demo text");
11 | });
12 |
13 |
14 | });
--------------------------------------------------------------------------------
/generate/templates/controller/funcunit.html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
<%= name %> FuncUnit Test
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/generate/templates/controller/views/.ignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jupiterjs/jquerymx/0f917a85327a6c0196c2cf28c1d90a9095e0eae1/generate/templates/controller/views/.ignore
--------------------------------------------------------------------------------
/generate/templates/controller/views/init.ejs.ejs:
--------------------------------------------------------------------------------
1 | <%%= this.message %>
--------------------------------------------------------------------------------
/generate/templates/fixturemake.ejs:
--------------------------------------------------------------------------------
1 | $.fixture.make("<%= underscore %>", 5, function(i, <%= underscore %>){
2 | var descriptions = ["grill fish", "make ice", "cut onions"]
3 | return {
4 | name: "<%= underscore %> "+i,
5 | description: $.fixture.rand( descriptions , 1)[0]
6 | }
7 | })
--------------------------------------------------------------------------------
/generate/templates/model.js:
--------------------------------------------------------------------------------
1 | steal( 'steal/generate',
2 | 'steal/generate/system.js',
3 | 'steal/generate/inflector.js',
4 | function(steal){
5 |
6 |
7 |
8 | var upper = function(parts){
9 | for(var i =0; i < parts.length; i++){
10 | parts[i] = parts[i].charAt(0).toUpperCase()+parts[i].substr(1)
11 | }
12 | return parts
13 | }
14 |
15 | steal.generate.model = function(arg){
16 |
17 | if(arg.charAt(0) !== arg.charAt(0).toUpperCase()){
18 | var caps = upper( arg.split(/_|-/) ).join(''),
19 | name = upper(caps.split("/")).join('.');
20 |
21 | print(" Creating "+name);
22 | arg = name;
23 | }
24 |
25 | var md = steal.generate.convert(arg),
26 | path = arg.toLowerCase().replace('.',"/");
27 |
28 | var folder = md.path.replace(/\/\w+$/, "")
29 | if(!folder){
30 | print("! Error: Models need to be part of an app");
31 | quit();
32 | }
33 | if(!steal.File(folder).exists()){
34 | print("! Error: folder "+folder+" does not exist!");
35 | quit();
36 | }
37 |
38 | md.path_to_steal = new steal.File(path).pathToRoot();
39 | md.appPath = md.path.replace(/\/models$/,"");
40 |
41 | //check pluralization of last part
42 | if(steal.Inflector.singularize(md.underscore) !== md.underscore){
43 | print("! Warning: Model names should be singular. I don't think "+md.underscore+" is singular!")
44 | }
45 |
46 | // generate the files
47 | steal.generate("jquery/generate/templates/model", md.appPath, md)
48 |
49 | try{
50 | // steal this model in models.js
51 | steal.generate.insertSteal(md.appPath+"/models/models.js", "./"+md.underscore+".js");
52 |
53 | // steal this model's unit test in qunit.js
54 | steal.generate.insertSteal(md.appPath+"/test/qunit/qunit.js", "./"+md.underscore+"_test.js");
55 | } catch (e) {
56 | if(e.type && e.type == "DUPLICATE"){
57 | print("! Error: This model was already created!")
58 | quit();
59 | }
60 | }
61 | // $.fixture.make for this model in fixtures.js
62 |
63 |
64 |
65 | var text = readFile("jquery/generate/templates/fixturemake.ejs");
66 | var fixturetext = new steal.EJS({
67 | text: text
68 | }).render(md);
69 | steal.generate.insertCode(md.appPath+"/fixtures/fixtures.js", fixturetext);
70 |
71 | }
72 |
73 |
74 |
75 | });
--------------------------------------------------------------------------------
/generate/templates/model/models/(underscore).js.ejs:
--------------------------------------------------------------------------------
1 | steal('jquery/model', function(){
2 |
3 | /**
4 | * @class <%=name%>
5 | * @parent index
6 | * @inherits jQuery.Model
7 | * Wraps backend <%=underscore%> services.
8 | */
9 | $.Model('<%=name%>',
10 | /* @Static */
11 | {
12 | findAll: "/<%= plural %>.json",
13 | findOne : "/<%= plural %>/{id}.json",
14 | create : "/<%= plural %>.json",
15 | update : "/<%= plural %>/{id}.json",
16 | destroy : "/<%= plural %>/{id}.json"
17 | },
18 | /* @Prototype */
19 | {});
20 |
21 | })
--------------------------------------------------------------------------------
/generate/templates/model/test/qunit/(underscore)_test.js.ejs:
--------------------------------------------------------------------------------
1 | steal("funcunit/qunit", "<%= appPath %>/fixtures", "<%= appPath %>/models/<%= underscore %>.js", function(){
2 | module("Model: <%= name %>")
3 |
4 | test("findAll", function(){
5 | expect(4);
6 | stop();
7 | <%= name %>.findAll({}, function(<%= plural %>){
8 | ok(<%= plural %>)
9 | ok(<%= plural %>.length)
10 | ok(<%= plural %>[0].name)
11 | ok(<%= plural %>[0].description)
12 | start();
13 | });
14 |
15 | })
16 |
17 | test("create", function(){
18 | expect(3)
19 | stop();
20 | new <%= name %>({name: "dry cleaning", description: "take to street corner"}).save(function(<%= underscore %>){
21 | ok(<%= underscore %>);
22 | ok(<%= underscore %>.id);
23 | equals(<%= underscore %>.name,"dry cleaning")
24 | <%= underscore %>.destroy()
25 | start();
26 | })
27 | })
28 | test("update" , function(){
29 | expect(2);
30 | stop();
31 | new <%= name %>({name: "cook dinner", description: "chicken"}).
32 | save(function(<%= underscore %>){
33 | equals(<%= underscore %>.description,"chicken");
34 | <%= underscore %>.update({description: "steak"},function(<%= underscore %>){
35 | equals(<%= underscore %>.description,"steak");
36 | <%= underscore %>.destroy();
37 | start();
38 | })
39 | })
40 |
41 | });
42 | test("destroy", function(){
43 | expect(1);
44 | stop();
45 | new <%= name %>({name: "mow grass", description: "use riding mower"}).
46 | destroy(function(<%= underscore %>){
47 | ok( true ,"Destroy called" )
48 | start();
49 | })
50 | })
51 | })
--------------------------------------------------------------------------------
/generate/templates/page.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
<%= application_name %>
5 |
11 |
12 |
13 |
Welcome to JavaScriptMVC 3.2!
14 |
15 | Steal plugins and files in <%= path %>/<%= application_name %>.js .
16 | Change to production mode by changing steal.js to steal.production.js in this file.
17 |
18 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/generate/templates/plugin/(application_name).html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
<%= application_name %>
5 |
11 |
12 |
13 |
<%= application_name %> Demo
14 |
This is a dummy page to show off your plugin
15 |
18 |
23 |
24 |
--------------------------------------------------------------------------------
/generate/templates/plugin/(application_name).js.ejs:
--------------------------------------------------------------------------------
1 | steal('jquery',function($){
2 |
3 | });
--------------------------------------------------------------------------------
/generate/templates/plugin/(application_name)_test.js.ejs:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit','./<%= application_name %>',function(){
2 |
3 | module("<%= application_name %>");
4 |
5 | test("<%= application_name %> testing works", function(){
6 | ok(true,"an assert is run");
7 | });
8 |
9 |
10 | });
--------------------------------------------------------------------------------
/generate/templates/plugin/qunit.html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
<%= application_name%> QUnit Test
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/generate/templates/scaffold/create/create.html.ejs:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
<%=baseName %>.Create
6 |
9 |
10 |
11 |
<%=baseName %>.Create Demo
12 |
13 |
14 |
17 |
28 |
29 |
--------------------------------------------------------------------------------
/generate/templates/scaffold/create/create.js.ejs:
--------------------------------------------------------------------------------
1 | steal( 'jquery/controller',
2 | 'jquery/view/ejs',
3 | 'jquery/dom/form_params',
4 | 'jquery/controller/view',
5 | '<%= appPath %>/models' )
6 | .then('./views/init.ejs', function($){
7 |
8 | /**
9 | * @class <%=baseName%>.Create
10 | * @parent index
11 | * @inherits jQuery.Controller
12 | * Creates <%= plural %>
13 | */
14 | $.Controller('<%=baseName%>.Create',
15 | /** @Prototype */
16 | {
17 | init : function(){
18 | this.element.html(this.view());
19 | },
20 | submit : function(el, ev){
21 | ev.preventDefault();
22 | this.element.find('[type=submit]').val('Creating...')
23 | new <%= name %>(el.formParams()).save(this.callback('saved'));
24 | },
25 | saved : function(){
26 | this.element.find('[type=submit]').val('Create');
27 | this.element[0].reset()
28 | }
29 | })
30 |
31 | });
--------------------------------------------------------------------------------
/generate/templates/scaffold/create/create_test.js.ejs:
--------------------------------------------------------------------------------
1 | steal('funcunit',function(){
2 |
3 | module("<%=baseName%>.Create", {
4 | setup: function(){
5 | S.open("//<%= appPath %>/<%= underscore %>/create/create.html");
6 | }
7 | });
8 |
9 | test("create <%= plural %>", function(){
10 | S("[name=name]").type("Ice Water");
11 | S("[name=description]").type("Pour water in a glass. Add ice cubes.");
12 | S("[type=submit]").click();
13 | S('h3:contains(Ice Water)')
14 | .exists(function(){
15 | ok(true, "Ice Water added");
16 | equals(S("[name=name]").val() , "", "form reset");
17 | equals(S("[name=description]").val() , "", "form reset");
18 | })
19 | });
20 |
21 |
22 | });
--------------------------------------------------------------------------------
/generate/templates/scaffold/create/funcunit.html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
<%=baseName%>.Create FuncUnit Test
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/generate/templates/scaffold/create/views/init.ejs.ejs:
--------------------------------------------------------------------------------
1 |
New <%= underscore %>
2 |
3 | Name
4 |
5 |
6 |
Description
7 |
8 |
9 |
--------------------------------------------------------------------------------
/generate/templates/scaffold/list/funcunit.html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
<%= baseName %>.List Test
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/generate/templates/scaffold/list/list.html.ejs:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
<%= baseName %>.List Demo
6 |
9 |
10 |
11 |
<%= baseName %>.List Demo
12 |
13 |
Create <%= className %>
14 |
17 |
30 |
31 |
--------------------------------------------------------------------------------
/generate/templates/scaffold/list/list.js.ejs:
--------------------------------------------------------------------------------
1 | steal( 'jquery/controller',
2 | 'jquery/view/ejs',
3 | 'jquery/controller/view',
4 | '<%= appPath %>/models' )
5 | .then( './views/init.ejs',
6 | './views/<%= underscore %>.ejs',
7 | function($){
8 |
9 | /**
10 | * @class <%=baseName%>.List
11 | * @parent index
12 | * @inherits jQuery.Controller
13 | * Lists <%= plural %> and lets you destroy them.
14 | */
15 | $.Controller('<%=baseName%>.List',
16 | /** @Static */
17 | {
18 | defaults : {}
19 | },
20 | /** @Prototype */
21 | {
22 | init : function(){
23 | this.element.html(this.view('init',<%= name %>.findAll()) )
24 | },
25 | '.destroy click': function( el ){
26 | if(confirm("Are you sure you want to destroy?")){
27 | el.closest('.<%= underscore %>').model().destroy();
28 | }
29 | },
30 | "{<%= name %>} destroyed" : function(<%= className %>, ev, <%= underscore %>) {
31 | <%= underscore %>.elements(this.element).remove();
32 | },
33 | "{<%= name %>} created" : function(<%= className %>, ev, <%= underscore %>){
34 | this.element.append(this.view('init', [<%= underscore %>]))
35 | },
36 | "{<%= name %>} updated" : function(<%= className %>, ev, <%= underscore %>){
37 | <%= underscore %>.elements(this.element)
38 | .html(this.view('<%= underscore %>', <%= underscore %>) );
39 | }
40 | });
41 |
42 | });
--------------------------------------------------------------------------------
/generate/templates/scaffold/list/list_test.js.ejs:
--------------------------------------------------------------------------------
1 | steal('funcunit',function(){
2 |
3 | module("<%=baseName%>.List", {
4 | setup: function(){
5 | S.open("//<%= appPath %>/<%= underscore %>/list/list.html");
6 | }
7 | });
8 |
9 | test("delete <%= plural %>", function(){
10 | S('#create').click()
11 |
12 | // wait until grilled cheese has been added
13 | S('h3:contains(Grilled Cheese X)').exists();
14 |
15 | S.confirm(true);
16 | S('h3:last a').click();
17 |
18 |
19 | S('h3:contains(Grilled Cheese)').missing(function(){
20 | ok(true,"Grilled Cheese Removed")
21 | });
22 |
23 | });
24 |
25 |
26 | });
--------------------------------------------------------------------------------
/generate/templates/scaffold/list/views/(underscore).ejs.ejs:
--------------------------------------------------------------------------------
1 |
<%%= name %> X
2 |
<%%= description %>
--------------------------------------------------------------------------------
/generate/templates/scaffold/list/views/init.ejs.ejs:
--------------------------------------------------------------------------------
1 | <%%for(var i = 0; i < this.length ; i++){%>
2 |
>
3 | <%%== $.View('//<%= appPath %>/<%= underscore %>/list/views/<%= underscore %>.ejs', this[i] )%>
4 |
5 | <%%}%>
--------------------------------------------------------------------------------
/generate/templates/scaffoldHookup.ejs:
--------------------------------------------------------------------------------
1 | $('#<%= plural %>').<%=appPath%>_<%= underscore %>_list();
2 | $('#create').<%=appPath%>_<%= underscore %>_create();
--------------------------------------------------------------------------------
/generate/test/app_plugin_model_controller.js:
--------------------------------------------------------------------------------
1 | load('steal/rhino/rhino.js')
2 | load('steal/rhino/test.js');
3 |
4 | (function(rhinoSteal){
5 | _S = steal.test;
6 |
7 |
8 | _S.module("jquery/generate")
9 | STEALPRINT = false;
10 |
11 | _S.test("app" , function(t){
12 | _args = ['cnu'];
13 | load('jquery/generate/app');
14 | _S.clear();
15 | _S.open('cnu/cnu.html')
16 | t.ok(typeof steal !== 'undefined', "steal is fine")
17 | _S.clear();
18 | })
19 |
20 | _S.test("app 2 levels deep" , function(t){
21 | _args = ['cnu/widget'];
22 | load('jquery/generate/plugin');
23 | _S.clear();
24 | _S.open('cnu/widget/widget.html')
25 | t.ok(typeof steal !== 'undefined', "steal is fine")
26 | _S.clear();
27 | })
28 |
29 | /**
30 | * Tests generating a very basic controller and model
31 | */
32 |
33 | _S.test("controller, model, and page" , function(t){
34 | _args = ['Cnu.Todos'];
35 | load('jquery/generate/controller');
36 | _S.clear();
37 |
38 | _args = ['Cnu.Models.Todo'];
39 | load('jquery/generate/model');
40 | _S.clear();
41 | cnuContent = readFile('cnu/cnu.js')
42 | +"\n.then('./models/todo.js')"
43 | +"\n.then('./todos/todos.js')";
44 | load('steal/rhino/rhino.js')
45 | new steal.File('cnu/cnu.js').save( cnuContent );
46 |
47 |
48 | _args = ['cnu','cnugen.html'];
49 | load('jquery/generate/page');
50 | _S.clear();
51 |
52 | _S.open('cnu/cnugen.html');
53 |
54 | t.ok(typeof Cnu.Todos !== 'undefined',"load Cnu.Controllers.Todos")
55 | t.ok(typeof Cnu.Models.Todo !== 'undefined', "load Cnu.Models.Todo")
56 |
57 | rhinoSteal.File("cnu").removeDir();
58 | })
59 |
60 | })(steal);
61 |
--------------------------------------------------------------------------------
/generate/test/run.js:
--------------------------------------------------------------------------------
1 | load("jquery/generate/test/app_plugin_model_controller.js");
2 |
3 | load("jquery/generate/test/scaffold.js");
4 |
--------------------------------------------------------------------------------
/generate/test/scaffold.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | load('steal/rhino/rhino.js');
4 | load('steal/test/test.js');
5 |
6 | steal('steal/test', function(s){
7 |
8 | s.test.module("jquery/generate/scaffold")
9 |
10 | STEALPRINT = false;
11 |
12 | s.test.test("make app and scaffold", function(t){
13 | _args = ['cookbook'];
14 | load('jquery/generate/app');
15 | _args = ['Cookbook.Models.Recipe'];
16 | load('jquery/generate/scaffold');
17 |
18 |
19 | load('steal/rhino/rhino.js');
20 | var cookbookContent = readFile('cookbook/cookbook.js')
21 | +"\n.then('./models/recipe.js')"
22 | +"\n.then('./controllers/recipe_controller.js')";
23 | new steal.File('cookbook/cookbook.js').save( cookbookContent );
24 |
25 | var qunitContent = readFile('cookbook/test/qunit/qunit.js').
26 | replace("cookbook_test", "recipe_test");
27 | new steal.File('cookbook/test/qunit/qunit.js').save( qunitContent );
28 |
29 | var funcunitContent = readFile('cookbook/test/funcunit/funcunit.js').
30 | replace("cookbook_test", "recipe_controller_test");
31 | new steal.File('cookbook/test/funcunit/funcunit.js').save( funcunitContent );
32 |
33 | t.clear();
34 | print('trying to open ...')
35 | t.open('cookbook/cookbook.html', false)
36 | t.ok(Cookbook.Controllers.Recipe, "Recipe Controller")
37 | t.ok(Cookbook.Models.Recipe, "Recipe Controller")
38 | t.clear();
39 | });
40 |
41 | //now see if unit and functional run
42 |
43 | // s.test.test("scaffold unit tests", function(t){
44 | //
45 | // load('steal/rhino/rhino.js');
46 | // load('funcunit/loader.js');
47 | // FuncUnit.load('cookbook/qunit.html');
48 | // });
49 | //
50 | // s.test.test("scaffold functional tests", function(t){
51 | // load('steal/rhino/rhino.js');
52 | // load('funcunit/loader.js');
53 | // FuncUnit.load('cookbook/funcunit.html');
54 | //
55 | // });
56 | //
57 | // s.test.test("documentjs", function(t){
58 | // t.clear();
59 | // load('steal/rhino/rhino.js');
60 | // _args = ['cookbook/cookbook.html']
61 | // load("documentjs/documentjs.js");
62 | // DocumentJS('cookbook/cookbook.html');
63 | // });
64 |
65 | s.test.test("compress", function(t){
66 | t.clear();
67 | load("cookbook/scripts/build.js")
68 |
69 | var cookbookPage = readFile('cookbook/cookbook.html').
70 | replace("steal.js?cookbook,development", "steal.js?cookbook,production");
71 | new steal.File('cookbook/cookbook.html').save( cookbookPage );
72 |
73 | t.clear();
74 | t.open('cookbook/cookbook.html', false)
75 | t.ok(Cookbook.Controllers.Recipe, "Recipe Controller")
76 | t.ok(Cookbook.Models.Recipe, "Recipe Controller")
77 | t.clear();
78 | });
79 |
80 |
81 | //print("-- cleanup --");
82 | // s.File("cookbook").removeDir();
83 |
84 | })
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/lang/lang_test.js:
--------------------------------------------------------------------------------
1 | steal('./object/object_test','./observe/observe_test','./string/string_test')
2 |
--------------------------------------------------------------------------------
/lang/object/object.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
object
6 |
12 |
13 |
14 |
object Demo
15 |
This is a dummy page to show off your plugin
16 |
19 |
24 |
25 |
--------------------------------------------------------------------------------
/lang/object/object_test.js:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit','./object',function(){
2 |
3 | module("object");
4 |
5 | test("same", function(){
6 |
7 |
8 | ok( $.Object.same({type: "FOLDER"},{type: "FOLDER", count: 5}, {
9 | count: null
10 | }), "count ignored" );
11 |
12 | ok( $.Object.same({type: "folder"},{type: "FOLDER"}, {
13 | type: "i"
14 | }), "folder case ignored" );
15 | })
16 |
17 | test("subsets", function(){
18 |
19 | var res1 = $.Object.subsets({parentId: 5, type: "files"},
20 | [{parentId: 6}, {type: "folders"}, {type: "files"}]);
21 |
22 | same(res1,[{type: "files"}])
23 |
24 | var res2 = $.Object.subsets({parentId: 5, type: "files"},
25 | [{}, {type: "folders"}, {type: "files"}]);
26 |
27 | same(res2,[{},{type: "files"}]);
28 |
29 | var res3 = $.Object.subsets({parentId: 5, type: "folders"},
30 | [{parentId: 5},{type: "files"}]);
31 |
32 | same(res3,[{parentId: 5}])
33 | });
34 |
35 | test("subset compare", function(){
36 |
37 | ok( $.Object.subset(
38 | {type: "FOLDER"},
39 | {type: "FOLDER"}),
40 |
41 | "equal sets" );
42 |
43 | ok( $.Object.subset(
44 | {type: "FOLDER", parentId: 5},
45 | {type: "FOLDER"}),
46 |
47 | "sub set" );
48 |
49 | ok(! $.Object.subset(
50 | {type: "FOLDER"},
51 | {type: "FOLDER", parentId: 5}),
52 |
53 | "wrong way" );
54 |
55 |
56 | ok(! $.Object.subset(
57 | {type: "FOLDER", parentId: 7},
58 | {type: "FOLDER", parentId: 5}),
59 |
60 | "different values" );
61 |
62 | ok( $.Object.subset(
63 | {type: "FOLDER", count: 5}, // subset
64 | {type: "FOLDER"},
65 | {count: null} ),
66 |
67 | "count ignored" );
68 |
69 |
70 | ok( $.Object.subset(
71 | {type: "FOLDER", kind: "tree"}, // subset
72 | {type: "FOLDER", foo: true, bar: true },
73 | {foo: null, bar: null} ),
74 |
75 | "understands a subset" );
76 | ok( $.Object.subset(
77 | {type: "FOLDER", foo: true, bar: true },
78 | {type: "FOLDER", kind: "tree"}, // subset
79 |
80 | {foo: null, bar: null, kind : null} ),
81 |
82 | "ignores nulls" );
83 | });
84 |
85 | test("searchText", function(){
86 | var item = {
87 | id: 1,
88 | name: "thinger"
89 | },
90 | searchText = {
91 | searchText : "foo"
92 | },
93 | compare = {
94 | searchText : function(items, paramsText, itemr, params){
95 | equals(item,itemr);
96 | equals(searchText, params)
97 | return true;
98 | }
99 | };
100 |
101 | ok( $.Object.subset( item, searchText, compare ), "searchText" );
102 | });
103 |
104 |
105 | });
--------------------------------------------------------------------------------
/lang/object/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
object QUnit Test
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/lang/observe/observe.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
object
6 |
20 |
21 |
22 |
$.Observe Demo
23 |
Make changes to the JSON in the following textarea.
24 | Click Update Attrs to merge the JSON and see the events produced.
25 |
o = new $.Observe({})
26 |
o.attrs(
27 |
, true)
33 |
34 |
o.bind('change', function( ev, attr, how, newValue, prevValue, where ) {
35 |
36 |
37 | attr
38 | how
39 | newValue
40 | prevValue
41 | where
42 |
43 |
44 |
45 |
46 |
47 |
50 |
82 |
83 |
--------------------------------------------------------------------------------
/lang/observe/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
associations
14 |
list
15 |
16 |
17 |
--------------------------------------------------------------------------------
/lang/openajax/openajax.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
Lang Performance Test
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
24 |
--------------------------------------------------------------------------------
/lang/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
associations
14 |
list
15 |
16 |
17 |
--------------------------------------------------------------------------------
/lang/string/deparam/deparam.js:
--------------------------------------------------------------------------------
1 | steal('jquery', function($){
2 |
3 | var digitTest = /^\d+$/,
4 | keyBreaker = /([^\[\]]+)|(\[\])/g,
5 | plus = /\+/g,
6 | paramTest = /([^?#]*)(#.*)?$/;
7 |
8 | /**
9 | * @add jQuery.String
10 | */
11 | $.String = $.extend($.String || {}, {
12 |
13 | /**
14 | * @function deparam
15 | *
16 | * Takes a string of name value pairs and returns a Object literal that represents those params.
17 | *
18 | * @param {String} params a string like
"foo=bar&person[age]=3"
19 | * @return {Object} A JavaScript Object that represents the params:
20 | *
21 | * {
22 | * foo: "bar",
23 | * person: {
24 | * age: "3"
25 | * }
26 | * }
27 | */
28 | deparam: function(params){
29 |
30 | if(! params || ! paramTest.test(params) ) {
31 | return {};
32 | }
33 |
34 |
35 | var data = {},
36 | pairs = params.split('&'),
37 | current;
38 |
39 | for(var i=0; i < pairs.length; i++){
40 | current = data;
41 | var pair = pairs[i].split('=');
42 |
43 | // if we find foo=1+1=2
44 | if(pair.length != 2) {
45 | pair = [pair[0], pair.slice(1).join("=")]
46 | }
47 |
48 | var key = decodeURIComponent(pair[0].replace(plus, " ")),
49 | value = decodeURIComponent(pair[1].replace(plus, " ")),
50 | parts = key.match(keyBreaker);
51 |
52 | for ( var j = 0; j < parts.length - 1; j++ ) {
53 | var part = parts[j];
54 | if (!current[part] ) {
55 | // if what we are pointing to looks like an array
56 | current[part] = digitTest.test(parts[j+1]) || parts[j+1] == "[]" ? [] : {}
57 | }
58 | current = current[part];
59 | }
60 | lastPart = parts[parts.length - 1];
61 | if(lastPart == "[]"){
62 | current.push(value)
63 | }else{
64 | current[lastPart] = value;
65 | }
66 | }
67 | return data;
68 | }
69 | });
70 |
71 | })
72 |
--------------------------------------------------------------------------------
/lang/string/deparam/deparam_test.js:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit','./deparam').then(function(){
2 |
3 | module('jquery/lang/deparam')
4 |
5 | test("Basic deparam",function(){
6 |
7 | var data = $.String.deparam("a=b");
8 | equals(data.a,"b")
9 |
10 | var data = $.String.deparam("a=b&c=d");
11 | equals(data.a,"b")
12 | equals(data.c,"d")
13 | })
14 | test("Nested deparam",function(){
15 |
16 | var data = $.String.deparam("a[b]=1&a[c]=2");
17 | equals(data.a.b,1)
18 | equals(data.a.c,2)
19 |
20 | var data = $.String.deparam("a[]=1&a[]=2");
21 | equals(data.a[0],1)
22 | equals(data.a[1],2)
23 |
24 | var data = $.String.deparam("a[b][]=1&a[b][]=2");
25 | equals(data.a.b[0],1)
26 | equals(data.a.b[1],2)
27 |
28 | var data = $.String.deparam("a[0]=1&a[1]=2");
29 | equals(data.a[0],1)
30 | equals(data.a[1],2)
31 | });
32 |
33 |
34 | test("deparam an array", function(){
35 | var data = $.String.deparam("a[0]=1&a[1]=2");
36 |
37 | ok($.isArray(data.a), "is array")
38 |
39 | equals(data.a[0],1)
40 | equals(data.a[1],2)
41 | })
42 |
43 | test("deparam object with spaces", function(){
44 | var data = $.String.deparam("a+b=c+d&+e+f+=+j+h+");
45 |
46 | equals(data["a b"], "c d")
47 | equals(data[" e f "], " j h ")
48 | })
49 |
50 | })
51 |
--------------------------------------------------------------------------------
/lang/string/deparam/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
associations
14 |
list
15 |
16 |
17 |
--------------------------------------------------------------------------------
/lang/string/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
string QUnit Test
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/lang/string/rsplit/rsplit.js:
--------------------------------------------------------------------------------
1 | steal('jquery/lang/string',function( $ ) {
2 | /**
3 | * @add jQuery.String
4 | */
5 | $.String.
6 | /**
7 | * Splits a string with a regex correctly cross browser
8 | *
9 | * $.String.rsplit("a.b.c.d", /\./) //-> ['a','b','c','d']
10 | *
11 | * @param {String} string The string to split
12 | * @param {RegExp} regex A regular expression
13 | * @return {Array} An array of strings
14 | */
15 | rsplit = function( string, regex ) {
16 | var result = regex.exec(string),
17 | retArr = [],
18 | first_idx, last_idx;
19 | while ( result !== null ) {
20 | first_idx = result.index;
21 | last_idx = regex.lastIndex;
22 | if ( first_idx !== 0 ) {
23 | retArr.push(string.substring(0, first_idx));
24 | string = string.slice(first_idx);
25 | }
26 | retArr.push(result[0]);
27 | string = string.slice(result[0].length);
28 | result = regex.exec(string);
29 | }
30 | if ( string !== '' ) {
31 | retArr.push(string);
32 | }
33 | return retArr;
34 | };
35 | });
--------------------------------------------------------------------------------
/lang/string/string.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
string
6 |
12 |
13 |
14 |
string Demo
15 |
This is a dummy page to show off your plugin
16 |
19 |
24 |
25 |
--------------------------------------------------------------------------------
/lang/string/string_test.js:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit','./string').then(function(){
2 |
3 | module("jquery/lang/string")
4 |
5 | test("$.String.sub", function(){
6 | equals($.String.sub("a{b}",{b: "c"}),"ac")
7 |
8 | var foo = {b: "c"};
9 |
10 | equals($.String.sub("a{b}",foo,true),"ac");
11 |
12 | ok(!foo.b, "removed this b");
13 |
14 |
15 | });
16 |
17 | test("$.String.sub double", function(){
18 | equals($.String.sub("{b} {d}",[{b: "c", d: "e"}]),"c e");
19 | })
20 |
21 | test("String.underscore", function(){
22 | equals($.String.underscore("Foo.Bar.ZarDar"),"foo.bar.zar_dar")
23 | })
24 |
25 |
26 | test("$.String.getObject", function(){
27 | var obj = $.String.getObject("foo", [{a: 1}, {foo: 'bar'}]);
28 |
29 | equals(obj,'bar', 'got bar')
30 |
31 |
32 | // test null data
33 |
34 | var obj = $.String.getObject("foo", [{a: 1}, {foo: 0}]);
35 |
36 | equals(obj,0, 'got 0 (falsey stuff)')
37 | });
38 |
39 | test("$.String.niceName", function(){
40 | var str = "some_underscored_string";
41 | var niceStr = $.String.niceName(str);
42 | equals(niceStr, 'Some Underscored String', 'got correct niceName');
43 | })
44 |
45 |
46 | }).then('./deparam/deparam_test');
47 |
--------------------------------------------------------------------------------
/model/backup/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/model/backup/qunit/qunit.js:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit')
2 | .then("jquery/model/backup").then(function(){
3 |
4 |
5 | module("jquery/model/backup",{
6 | setup : function(){
7 | $.Model.extend("Recipe")
8 | }
9 | })
10 |
11 | test("backing up", function(){
12 | var recipe = new Recipe({name: "cheese"});
13 | ok(!recipe.isDirty(), "not backedup, but clean")
14 |
15 | recipe.backup();
16 | ok(!recipe.isDirty(), "backedup, but clean");
17 |
18 | recipe.name = 'blah'
19 |
20 | ok(recipe.isDirty(), "dirty");
21 |
22 | recipe.restore();
23 |
24 | ok(!recipe.isDirty(), "restored, clean");
25 |
26 | equals(recipe.name, "cheese" ,"name back");
27 |
28 | });
29 |
30 | test("backup / restore with associations", function(){
31 | $.Model("Instruction");
32 | $.Model("Cookbook");
33 |
34 | $.Model("Recipe",{
35 | attributes : {
36 | instructions : "Instruction.models",
37 | cookbook: "Cookbook.model"
38 | }
39 | },{});
40 |
41 |
42 |
43 |
44 | var recipe = new Recipe({
45 | name: "cheese burger",
46 | instructions : [
47 | {
48 | description: "heat meat"
49 | },
50 | {
51 | description: "add cheese"
52 | }
53 | ],
54 | cookbook: {
55 | title : "Justin's Grillin Times"
56 | }
57 | });
58 |
59 | //test basic is dirty
60 |
61 | ok(!recipe.isDirty(), "not backedup, but clean")
62 |
63 | recipe.backup();
64 | ok(!recipe.isDirty(), "backedup, but clean");
65 |
66 | recipe.name = 'blah'
67 |
68 | ok(recipe.isDirty(), "dirty");
69 |
70 | recipe.restore();
71 |
72 | ok(!recipe.isDirty(), "restored, clean");
73 |
74 | equals(recipe.name, "cheese burger" ,"name back");
75 |
76 | // test belongs too
77 |
78 | ok(!recipe.cookbook.isDirty(), "cookbook not backedup, but clean");
79 |
80 | recipe.cookbook.backup();
81 |
82 | recipe.cookbook.attr("title","Brian's Burgers");
83 |
84 | ok(!recipe.isDirty(), "recipe itself is clean");
85 |
86 | ok(recipe.isDirty(true), "recipe is dirty if checking associations");
87 |
88 | recipe.cookbook.restore()
89 |
90 | ok(!recipe.isDirty(true), "recipe is now clean with checking associations");
91 |
92 | equals(recipe.cookbook.title, "Justin's Grillin Times" ,"cookbook title back");
93 |
94 | //try belongs to recursive restore
95 |
96 | recipe.cookbook.attr("title","Brian's Burgers");
97 | recipe.restore();
98 | ok(recipe.isDirty(true), "recipe is dirty if checking associations, after a restore");
99 |
100 | recipe.restore(true);
101 | ok(!recipe.isDirty(true), "cleaned all of recipe and its associations");
102 |
103 |
104 | })
105 |
106 | })
107 |
--------------------------------------------------------------------------------
/model/demo-convert.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
Model Convert Demo
6 |
12 |
13 |
14 |
15 |
Model Convert Demo
16 |
This demo shows converting date strings sent by the
17 | server to JavaScript dates with attributes and convert.
18 |
19 |
22 |
25 |
76 |
77 |
--------------------------------------------------------------------------------
/model/demo-dom.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
Model Convert Demo
6 |
12 |
13 |
14 |
15 |
Model DOM Helpers Demo
16 |
This demo shows using models to set an instance on an element.
17 |
18 |
21 |
24 |
80 |
81 |
--------------------------------------------------------------------------------
/model/demo-setter.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
Model Events Demo
6 |
12 |
13 |
14 |
15 |
Model Setter Demo
16 |
This demo shows converting date strings sent by the
17 | server to JavaScript dates with Setters.
18 |
19 |
22 |
25 |
26 |
77 |
78 |
--------------------------------------------------------------------------------
/model/fixtures/school.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": 4,
3 | "name" : "Highland"
4 | }
--------------------------------------------------------------------------------
/model/fixtures/schools.json:
--------------------------------------------------------------------------------
1 | [{
2 | "id": 1,
3 | "name" : "adler"
4 | }]
5 |
--------------------------------------------------------------------------------
/model/list/cookie/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/model/list/cookie/qunit/qunit.js:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit','jquery/model/list/cookie').then(function($){
2 |
3 | module("jquery/model/list/cookie",{
4 | setup: function(){
5 | // clear any existing cookie ...
6 | $.cookie("list", "", {expires: -1})
7 | $.Model.extend("Search", {}, {});
8 |
9 | $.Model.List.Cookie.extend("Search.Store")
10 | }
11 | })
12 |
13 | test("storing and retrieving",function(){
14 |
15 | var store = new Search.Store([]) //should be able to look up by namespace ....
16 |
17 | ok(!store.length, "empty list");
18 |
19 | store.push( new Search({id: 1}), new Search({id: 2}) )
20 | store.store("list");
21 |
22 | var store2 = new Search.Store([]).retrieve("list");
23 | equals(store2.length, 2, "there are 2 items")
24 |
25 | })
26 |
27 | })
28 |
--------------------------------------------------------------------------------
/model/list/local/local.js:
--------------------------------------------------------------------------------
1 | steal('jquery/dom/cookie','jquery/model/list').then(function($){
2 | /**
3 | * @class jQuery.Model.List.Local
4 | * @plugin jquery/model/list/local
5 | * @download http://jmvcsite.heroku.com/pluginify?plugins[]=jquery/model/list/local/local.js
6 | * @parent jQuery.Model.List
7 | * Works exactly the same as [jQuery.Model.List.Cookie] except uses
8 | * a local store instead of cookies.
9 | */
10 | $.Model.List("jQuery.Model.List.Local",
11 | {
12 | retrieve : function(name){
13 | // each also needs what they are referencd by ?
14 | var props = window.localStorage[ name ] || "[]",
15 | instances = [],
16 | Class = props.type ? $.String.getObject(props.type) : null;
17 | for(var i =0; i < props.ids.length;i++){
18 | var identity = props.ids[i],
19 | instanceData = window.localStorage[ identity ];
20 | instances.push( new Class(instanceData) )
21 | }
22 | this.push.apply(this,instances);
23 | return this;
24 | },
25 | store : function(name){
26 | // go through and listen to instance updating
27 | var ids = [], days = this.days;
28 | this.each(function(i, inst){
29 | window.localStorage[inst.identity()] = inst.attrs();
30 | ids.push(inst.identity());
31 | });
32 | window.localStorage[name] = {
33 | type: this[0] && this[0].constructor.fullName,
34 | ids: ids
35 | };
36 | return this;
37 | }
38 |
39 | });
40 |
41 | })
42 |
43 |
--------------------------------------------------------------------------------
/model/list/memory.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
List Helper Demo
6 |
12 |
13 |
14 |
Start
15 |
16 |
17 |
18 |
21 |
86 |
87 |
--------------------------------------------------------------------------------
/model/list/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/model/modelBinder.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
slider
6 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | 1
34 | 2
35 | 3
36 | 4
37 | 5
38 | 6
39 | 7
40 | 8
41 | 9
42 | 10
43 |
44 |
47 |
48 |
91 |
92 |
--------------------------------------------------------------------------------
/model/pages/deferreds.md:
--------------------------------------------------------------------------------
1 | @page jquery.model.deferreds Deferreds
2 | @parent jQuery.Model
3 |
4 | Models (and views) work
5 | with [http://api.jquery.com/category/deferred-object/ jQuery.Deferred]. If
6 | you properly fill out a model's [jquery.model.services service API], asynchronous
7 | requests done via the model will return a jQuery.Deferred.
8 |
9 | ## findAll example
10 |
11 | The following example, requests tasks and people and waits for both requests
12 | to be complete before alerting the user:
13 |
14 | var tasksDef = Task.findAll(),
15 | peopleDef = People.findAll();
16 |
17 | $.when(tasksDef,peopleDef).done(function(taskResponse, peopleResponse){
18 | alert("There are "+taskRespone[0].length+" tasks and "+
19 | peopleResponse[0].length+" people.");
20 | });
21 |
22 | __Note__ taskResponse[0] is an Array of tasks.
23 |
24 | ## save and destroy example
25 |
26 | Calls to [jQuery.Model.prototype.save save] and [jQuery.Model.prototype.destroy] also
27 | return a deferred. The deferred is resolved to the newly created, destroyed, or updated
28 | model instance.
29 |
30 | The following creates a task, updates it, and destroys it:
31 |
32 | var taskD = new Task({name: "dishes"}).save();
33 |
34 | taskD.done(function(task){
35 |
36 | var taskD2 = task.update({name: "all the dishes"})
37 |
38 | taskD2.done(function(task){
39 |
40 | var taskD3 = task.destroy();
41 |
42 | taskD3.done(function(){
43 | console.log("task destroyed");
44 | })
45 |
46 | })
47 |
48 | });
49 |
--------------------------------------------------------------------------------
/model/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
associations
14 |
list
15 |
16 |
17 |
--------------------------------------------------------------------------------
/model/service/service.js:
--------------------------------------------------------------------------------
1 | steal('jquery/model').then(function(){
2 | var convert = function(method, func){
3 |
4 | return typeof method == 'function' ? function(){
5 | var old = this._service,
6 | ret;
7 | this._service = func;
8 | ret = method.apply(this, arguments);
9 | this._service = old;
10 | return ret;
11 | } : method
12 | }
13 | /**
14 | * Creates a service
15 | * @param {Object} defaults
16 | * @param {Object} methods
17 | */
18 | $.Model.service = function(properties){
19 |
20 | var func = function(newProps){
21 | return $.Model.service( $.extend({}, properties, newProps) );
22 | };
23 |
24 | for(var name in properties){
25 | func[name] = convert(properties[name], func)
26 | }
27 |
28 | return func;
29 | }
30 | });
31 |
--------------------------------------------------------------------------------
/model/service/twitter/twitter.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
associations
6 |
12 |
13 |
14 |
JavaScriptMVC Tweets
15 |
16 |
19 |
30 |
31 |
--------------------------------------------------------------------------------
/model/service/twitter/twitter.js:
--------------------------------------------------------------------------------
1 | steal('jquery/model/service').then(function(){
2 |
3 | $.Model.service.twitter = $.Model.service({
4 | url : "http://api.twitter.com/1/",
5 | select : "*",
6 | from : "statuses/user_timeline.json",
7 | where : {screen_name : "javascriptmvc"},
8 | /**
9 | *
10 | * @param {Object} params
11 | */
12 | findAll : function(params, success, error){
13 |
14 |
15 | var url = (params.url || this._service.url)+(params.from || this._service.from),
16 | self = this;
17 |
18 | var twitterJson = {
19 | url: url,
20 | dataType: "jsonp",
21 | data: params.where || this._service.where,
22 | error : error
23 | }
24 |
25 | if(this.wrapMany){
26 | twitterJson.success = function (data) {
27 | if(data.results){
28 | data = data.results
29 | }
30 | success(self.wrapMany(data))
31 |
32 | }
33 | }else{
34 | twitterJson.success = success;
35 | }
36 |
37 | $.ajax(twitterJson);
38 | }
39 | });
40 |
41 | })
42 |
43 |
44 |
--------------------------------------------------------------------------------
/model/service/yql/yql.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
associations
6 |
12 |
13 |
14 |
19 |
26 |
27 |
--------------------------------------------------------------------------------
/model/service/yql/yql.js:
--------------------------------------------------------------------------------
1 | steal('jquery/model/service').then(function(){
2 |
3 | $.Model.service.yql = $.Model.service({
4 | select : "*",
5 | from : "flickr.photos.search",
6 | convert : function (query, params) {
7 | $.each( params, function (key) {
8 | var name = new RegExp( "#\{" + key + "\}","g" );
9 | var value = $.trim(this);
10 | //if (!value.match(/^[0-9]+$/)) {
11 | // value = '"' + value + '"';
12 | //}
13 | query = query.replace(name, value);
14 | }
15 | );
16 | return query;
17 | },
18 | /**
19 | *
20 | * @param {Object} params
21 | */
22 | findAll : function(params, success, error){
23 | params = $.extend({}, this._service, params);
24 | var query = ["SELECT",params.select,"FROM",params.from];
25 |
26 |
27 | if(params.where){
28 | query.push("WHERE",typeof params.where == "string" || this._service.convert(params.where[0],params.where[1]))
29 | }
30 | var self = this;
31 |
32 |
33 | var yqlJson = {
34 | url: "http://query.yahooapis.com/v1/public/yql",
35 | dataType: "jsonp",
36 | data: {
37 | q: query.join(" "),
38 | format: "json",
39 | env: 'store://datatables.org/alltableswithkeys',
40 | callback: "?"
41 | }
42 | }
43 | if (error) {
44 | yqlJson.error = error;
45 | }
46 | if(this.wrapMany){
47 | yqlJson.success = function (data) {
48 | var results = data.query.results
49 | if(results){
50 | for(var name in results){
51 | success(self.wrapMany(data.query.results[name]));
52 | break;
53 | }
54 | }else{
55 | success([]);
56 | }
57 | }
58 | }else{
59 | yqlJson.success = success;
60 | }
61 |
62 | $.ajax(yqlJson);
63 | }
64 | });
65 |
66 | })
--------------------------------------------------------------------------------
/model/store/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
store QUnit Test
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/model/test/4.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": 4,
3 | "name" : "adler"
4 | }
--------------------------------------------------------------------------------
/model/test/create.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": 4,
3 | "name" : "Highland"
4 | }
--------------------------------------------------------------------------------
/model/test/people.json:
--------------------------------------------------------------------------------
1 | [{
2 | "id" : 5,
3 | "name" : "Justin"
4 | }]
5 |
--------------------------------------------------------------------------------
/model/test/person.json:
--------------------------------------------------------------------------------
1 | {
2 | "id" : 5,
3 | "name" : "Justin"
4 | }
5 |
--------------------------------------------------------------------------------
/model/test/qunit/findAll.json:
--------------------------------------------------------------------------------
1 | [{
2 | "id" : 1,
3 | "name" : "Thing 1"
4 | }]
5 |
--------------------------------------------------------------------------------
/model/test/qunit/qunit.js:
--------------------------------------------------------------------------------
1 | //we probably have to have this only describing where the tests are
2 | steal("jquery/model","jquery/dom/fixture") //load your app
3 | .then('funcunit/qunit') //load qunit
4 | .then("./model_test.js")//,"./associations_test.js")
5 | .then(
6 | "jquery/model/backup/qunit",
7 | "jquery/model/list/list_test.js"
8 | )
9 | .then("jquery/model/validations/qunit/validations_test.js")
10 |
--------------------------------------------------------------------------------
/model/test/schools.json:
--------------------------------------------------------------------------------
1 | [{
2 | "id": 1,
3 | "name" : "adler"
4 | }]
5 |
--------------------------------------------------------------------------------
/model/test/update4.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": 4,
3 | "name" : "LHS"
4 | }
--------------------------------------------------------------------------------
/model/validations/demo.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
Model Validations Demo
6 |
12 |
13 |
14 |
17 |
18 |
21 |
104 |
105 |
--------------------------------------------------------------------------------
/model/validations/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/qunit.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/test/qunit/integration.js:
--------------------------------------------------------------------------------
1 | steal('funcunit/qunit',
2 | 'jquery/model',
3 | 'jquery/controller',
4 | 'jquery/view/ejs',
5 | 'jquery/dom/fixture')
6 | .then(function(){
7 |
8 | module('integration',{
9 | setup : function(){
10 | $("#qunit-test-area").html("")
11 | }
12 | });
13 |
14 | test("controller can listen to model instances and model classes", function(){
15 |
16 |
17 | $("#qunit-test-area").html("");
18 |
19 |
20 |
21 | $.Controller("Test.BinderThing",{
22 | "{model} created" : function(){
23 | ok(true,"model called");
24 | start();
25 | },
26 | "{instance} created" : function(){
27 | ok(true, "instance updated")
28 | }
29 | });
30 |
31 | $.Model("Test.ModelThing",{
32 | create : function(attrs, success){
33 | success({id: 1})
34 | }
35 | });
36 |
37 |
38 | var inst = new Test.ModelThing();
39 |
40 | $("