sproutcore 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.txt +19 -0
  2. data/Manifest.txt +15 -1
  3. data/clients/view_builder/builders/builder.js +339 -0
  4. data/clients/view_builder/builders/button.js +81 -0
  5. data/clients/view_builder/controllers/document.js +21 -0
  6. data/clients/view_builder/core.js +19 -0
  7. data/clients/view_builder/english.lproj/body.css +77 -0
  8. data/clients/view_builder/english.lproj/body.rhtml +39 -0
  9. data/clients/view_builder/english.lproj/controls.css +0 -0
  10. data/clients/view_builder/english.lproj/strings.js +14 -0
  11. data/clients/view_builder/main.js +38 -0
  12. data/clients/view_builder/mixins/design_mode.js +92 -0
  13. data/clients/view_builder/tests/controllers/document.rhtml +20 -0
  14. data/clients/view_builder/tests/views/builder.rhtml +20 -0
  15. data/clients/view_builder/tests/views/palette.rhtml +21 -0
  16. data/clients/view_builder/views/builder.js +26 -0
  17. data/clients/view_builder/views/palette.js +30 -0
  18. data/frameworks/sproutcore/Core.js +6 -4
  19. data/frameworks/sproutcore/README +1 -3
  20. data/frameworks/sproutcore/controllers/array.js +5 -5
  21. data/frameworks/sproutcore/drag/drag.js +2 -0
  22. data/frameworks/sproutcore/english.lproj/panes.css +16 -35
  23. data/frameworks/sproutcore/foundation/application.js +29 -8
  24. data/frameworks/sproutcore/foundation/object.js +5 -1
  25. data/frameworks/sproutcore/foundation/run_loop.js +65 -2
  26. data/frameworks/sproutcore/foundation/timer.js +1 -0
  27. data/frameworks/sproutcore/globals/window.js +23 -18
  28. data/frameworks/sproutcore/mixins/array.js +2 -2
  29. data/frameworks/sproutcore/mixins/observable.js +127 -52
  30. data/frameworks/sproutcore/panes/dialog.js +1 -1
  31. data/frameworks/sproutcore/panes/overlay.js +6 -2
  32. data/frameworks/sproutcore/panes/pane.js +27 -0
  33. data/frameworks/sproutcore/views/collection/collection.js +1 -1
  34. data/frameworks/sproutcore/views/collection/grid.js +3 -15
  35. data/frameworks/sproutcore/views/collection/source_list.js +10 -5
  36. data/frameworks/sproutcore/views/field/select_field.js +11 -2
  37. data/frameworks/sproutcore/views/field/text_field.js +1 -1
  38. data/frameworks/sproutcore/views/label.js +2 -7
  39. data/frameworks/sproutcore/views/view.js +254 -213
  40. data/generators/client/README +2 -2
  41. data/generators/client/USAGE +2 -2
  42. data/lib/sproutcore/build_tools/html_builder.rb +2 -2
  43. data/lib/sproutcore/bundle_manifest.rb +28 -22
  44. data/lib/sproutcore/merb/bundle_controller.rb +4 -3
  45. data/lib/sproutcore/version.rb +1 -1
  46. metadata +17 -3
  47. data/frameworks/sproutcore/animation/animation.js +0 -411
data/History.txt CHANGED
@@ -1,5 +1,24 @@
1
1
  == SVN HEAD
2
2
 
3
+ * [FIX] Build system now generates index.html files for client bundles, even
4
+ if they do not include .rhtml resources.
5
+
6
+ * [FIX] Typos in the readme docs for the client generator.
7
+
8
+ * Added automaticOutletFor() that will cause a view to be configured
9
+ automatically instead of forcing you to use an outlets array. Useful for when
10
+ you are manually constructing your views.
11
+
12
+ * Initial changes required to eventually implement improved observer
13
+ notification system.
14
+
15
+ * Improved documentation for a variety of classes
16
+
17
+ * [FIX] Only fixtures ending in ".js" will now be loaded. This allows you to include fixtures named .json or whatever and actually load them via XHR.
18
+
19
+ * [FIX] The build system now ignored any rhtml files that does not appear in
20
+ an lproj directory since this is where templates are stored.
21
+
3
22
  * Basic changes to get IE working. All non-view tests now pass and the doc app and test runner both load and run in IE7. Lots of visual fixes are still required for the sc-theme as well as IE-specific perf optimization and bug fixes.
4
23
 
5
24
  * [BUG] Default template for both client and template included a stray comma in their core.js file that breaks IE and Safari 2. This is fixed in the templates and in the clients included with the framework, though you will need to make this change manually in your own apps.
data/Manifest.txt CHANGED
@@ -39,10 +39,24 @@ clients/sc_test_runner/main.js
39
39
  clients/sc_test_runner/models/test.js
40
40
  clients/sc_test_runner/views/runner_frame.js
41
41
  clients/sc_test_runner/views/test_label.js
42
+ clients/view_builder/builders/builder.js
43
+ clients/view_builder/builders/button.js
44
+ clients/view_builder/controllers/document.js
45
+ clients/view_builder/core.js
46
+ clients/view_builder/english.lproj/body.css
47
+ clients/view_builder/english.lproj/body.rhtml
48
+ clients/view_builder/english.lproj/controls.css
49
+ clients/view_builder/english.lproj/strings.js
50
+ clients/view_builder/main.js
51
+ clients/view_builder/mixins/design_mode.js
52
+ clients/view_builder/tests/controllers/document.rhtml
53
+ clients/view_builder/tests/views/builder.rhtml
54
+ clients/view_builder/tests/views/palette.rhtml
55
+ clients/view_builder/views/builder.js
56
+ clients/view_builder/views/palette.js
42
57
  config/hoe.rb
43
58
  config/requirements.rb
44
59
  frameworks/prototype/prototype.js
45
- frameworks/sproutcore/animation/animation.js
46
60
  frameworks/sproutcore/controllers/array.js
47
61
  frameworks/sproutcore/controllers/collection.js
48
62
  frameworks/sproutcore/controllers/controller.js
@@ -0,0 +1,339 @@
1
+ // ==========================================================================
2
+ // Basic View Builder
3
+ // ==========================================================================
4
+
5
+ /**
6
+ A Builder can generate HTML, JavaScript and CSS based on a set of input
7
+ attributes. It expects to have the following attributes defined:
8
+
9
+ - targetClass: The name of the output class for JavaScript purposes.
10
+ - name: the human readable name
11
+ - guid: an internally unique id used to identify the resource.
12
+
13
+ - htmlTemplate: the html template to render.
14
+ - tagName: the tag name
15
+ - htmlId: ID used for tag
16
+ - cssClassNames: class names to add to tag.
17
+ - attributes: { src: "item" } -- HTML attrs to include.
18
+
19
+ - targetClass: name of output class.
20
+ - key: name of object when added to parent.
21
+ - properties: properties to place on JS object.
22
+ - bind: named bindings. each binding is like:
23
+ { to: path, kind: 'SC.Binding.Kind', isEnabled: YES }
24
+
25
+ - children: Array of child view builder records, in order. If any.
26
+ - parent: parent builder or null if top level.
27
+ - inPage: YES if should be added to SC.page.
28
+
29
+ You can add any other properties as well. Use them when your callbacks are
30
+ invoked to enhance these properties before they are generated.
31
+ */
32
+ SC.Builder = SC.Record.extend({
33
+
34
+ _targetClass: 'SC.Object',
35
+
36
+ /**
37
+ Defined by subclasses. If this is true, then the content of the view
38
+ is the HTML generated by children.
39
+ */
40
+ isContainer: NO,
41
+
42
+ /**
43
+ Defined by subclasses. If true, then views will be generated with an
44
+ outletFor() attached to them.
45
+ */
46
+ isOutletView: YES,
47
+
48
+ childrenType: 'SC.Builder',
49
+
50
+ parentType: 'SC.Builder',
51
+
52
+ /**
53
+ The default profile. New records will inherit a cloned set of these
54
+ attributes.
55
+ */
56
+ defaultAttributes: {
57
+ propertySettings: {},
58
+ bindSettings: {},
59
+ attributeSettings: {},
60
+ htmlTemplate: '<{%TagName%}{%Attributes%}>{%Content%}</{%TagName%}>',
61
+ cssClassNames: [],
62
+ innerHtml: '',
63
+ lazyOutlet: NO
64
+ },
65
+
66
+ init: function() {
67
+ arguments.callee.base.apply(this) ;
68
+ if (this.get('newRecord')) {
69
+ var attrs = this._deepClone(this.get('defaultAttributes'));
70
+ attrs.name = attrs.targetClass = this._targetClass ;
71
+ attrs.guid = attrs.htmlId = 'id%@'.fmt(Date.now().toString());
72
+ this.updateAttributes(attrs, YES, YES);
73
+ }
74
+ },
75
+
76
+ /**
77
+ Invoked just before the attributes are written out. You can add anything
78
+ you want here.
79
+ */
80
+ prepareAttributes: function(attrs) {
81
+ return attrs ;
82
+ },
83
+
84
+ /**
85
+ Invoked just before the class name is set. Add anything you want here.
86
+ */
87
+ prepareClassNames: function(classNames) {
88
+ return classNames ;
89
+ },
90
+
91
+ /**
92
+ Invoked just before outlets are added and the final JS is generated. Add
93
+ anything here you might pull from specialized preferences.
94
+ */
95
+ prepareProperties: function(props) { return props; },
96
+
97
+ /**
98
+ Invoked just before bindings are blended into properties. Add your own.
99
+ */
100
+ prepareBindings: function(binds) { return binds; },
101
+
102
+ // ..........................................
103
+ // HTML RENDERING
104
+ //
105
+
106
+ /**
107
+ Computes the HTML for this builder. HTML is built by interpolating the
108
+ htmlTemplate. Any variables must match a corresponding property on the
109
+ record with 'html' added to the beginning.
110
+ */
111
+ htmlPart: function() {
112
+ var template = this.get('htmlTemplate') ;
113
+ if (!template) return null ;
114
+
115
+ var that = this;
116
+ return template.replace(/{%(.+?)%}/g,function(m,p) {
117
+ return (p[0] == '%') ? p.slice(1,p.length) : that.get('html' + p) ;
118
+ }) ;
119
+ }.property('htmlTemplate', 'htmlContent', 'htmlTagName', 'htmlAttributes'),
120
+
121
+ /**
122
+ The tag name for the HTML. Usually specified by tagName in the
123
+ attributes.
124
+ */
125
+ htmlTagName: function() {
126
+ return this.get('tagName') || 'div';
127
+ }.property('tagName'),
128
+
129
+ /**
130
+ The attributes for the HTML. Combines attributes hash, css classes,
131
+ and id. It then calls prepareAttributes() so you can do any extra
132
+ processing you need.
133
+ */
134
+ htmlAttributes: function() {
135
+ // start with attributeSettings.
136
+ var attrs = this._deepClone(this.get('attributeSettings')) || {} ;
137
+
138
+ // add id
139
+ attrs.id = this.get('htmlId') ;
140
+
141
+ // merge in CSS class names
142
+ var cssClassNames = this.get('cssClassNames') || [] ;
143
+ if ($type(cssClassNames) === T_STRING) {
144
+ cssClassNames = cssClassNames.split(' ') ;
145
+ }
146
+
147
+ var cur = attrs['class'] || [] ;
148
+ if ($type(cur) === T_STRING) {
149
+ cur = cur.split(' ') ;
150
+ }
151
+
152
+ cur = cur.concat(cssClassNames).uniq().compact().sort() ;
153
+ cur.push(attrs.id) ;
154
+ cur = this.prepareClassNames(cur) || cur;
155
+ if (cur.length > 0) {
156
+ attrs['class'] = cur.join(' ') ;
157
+ } else delete attrs['class'] ;
158
+
159
+ attrs = this.prepareAttributes(attrs) || attrs ;
160
+
161
+ // now convert to a string.
162
+ var ret = [''];
163
+ for(var key in attrs) {
164
+ if (!attrs.hasOwnProperty(key)) continue ;
165
+ ret.push('%@="%@"'.fmt(key, attrs[key])) ;
166
+ }
167
+
168
+ return (ret.length > 1) ? ret.join(' ') : '';
169
+ }.property('cssClassNames', 'attributeSettings', 'htmlId'),
170
+
171
+ /**
172
+ The inner content for the HTML. If isContainer is true, then we get
173
+ the children for this view and use their HTML, otherwise get the
174
+ innerHtml property.
175
+ */
176
+ htmlContent: function() {
177
+ if (this.get('isContainer')) {
178
+ var children = this.get('children') || [] ;
179
+ var ret = [];
180
+ for(var idx=0;idx<children.length;idx++) {
181
+ var child = children.objectAt(idx) ;
182
+ ret.push(child.get('htmlPart')) ;
183
+ }
184
+
185
+ return ret.join('') ;
186
+ } else return this.get('innerHtml') ;
187
+ }.property('innerHtml', 'isContainer', 'children'),
188
+
189
+ // ..........................................
190
+ // JAVASCRIPT RENDERING
191
+ //
192
+
193
+ /**
194
+ Generates the JavaScript for this part.
195
+
196
+ This works by merging the propertySettings and bindSettings. Then it
197
+ calls your prepareProperties and finally merges in any outlets. With the
198
+ properties combined, it then generates the code to build a view.
199
+ */
200
+ javascriptPart: function() {
201
+ var props = this.get('javascriptProperties') ;
202
+
203
+ var outlets = this.get('javascriptOutlets') ;
204
+ for(var key in outlets) {
205
+ if (!outlets.hasOwnProperty(key)) continue ;
206
+ props[key] = outlets[key] ;
207
+ }
208
+
209
+ var outletDeclaration = '' ;
210
+ var verb = 'create' ;
211
+ if (this.get('isOutletView')) {
212
+ verb = 'extend' ;
213
+ outletDeclaration = '.outletFor(".%@?")'.fmt(this.get('htmlId'));
214
+ }
215
+
216
+ return '%@.%@(%@)%@'.fmt(this.get('targetClass'), verb, this._stringify(props), outletDeclaration) ;
217
+ }.property(),
218
+
219
+ /**
220
+ Generates the properties for the JavaScript sans any outlets.
221
+ */
222
+ javascriptProperties: function() {
223
+ var props = this._deepClone(this.get('propertySettings')) ;
224
+ props = this.prepareProperties(props) || props ;
225
+
226
+ var binds = this._deepClone(this.get('bindSettings')) ;
227
+ binds = this.prepareBindings(binds) || binds ;
228
+ for(var key in binds) {
229
+ if (!binds.hasOwnProperty(key)) continue ;
230
+
231
+ var bind = binds[key] ;
232
+ if (!bind.isEnabled) continue ;
233
+ bind = (bind.kind) ? "%@('%@')".fmt(bind.kind, bind.to) : "'%@'".fmt(bind.to) ;
234
+ props[key + 'Binding'] = bind ;
235
+ }
236
+
237
+ return props ;
238
+ }.property(),
239
+
240
+ /**
241
+ Generates the outlet properties for the JavaScript.
242
+ */
243
+ javascriptOutlets: function() {
244
+ var ret = {} ;
245
+ var outlets = [] ;
246
+
247
+ // loop through children.
248
+ var children = this.get('children') || [];
249
+ var idx = children.length ;
250
+ if (idx <= 0) return {} ;
251
+ while(--idx >= 0) {
252
+ var child = children.objectAt(idx) ;
253
+ var outletName = child.get('outletName') ;
254
+ var js = child.get('javascriptPart') ;
255
+ ret[outletName] = js ;
256
+ if (!child.get('lazyOutlet')) outlets.push(outletName) ;
257
+ }
258
+
259
+ ret.outlets = outletName ;
260
+ return ret ;
261
+ }.property(),
262
+
263
+ outletName: function(key, value) {
264
+ if (value !== undefined) this.writeAttribute('outletName', value) ;
265
+ return this.readAttribute('outletName') || this.get('htmlId') ;
266
+ }.property(),
267
+
268
+ // ..........................................
269
+ // INTERNAL METHODS
270
+ //
271
+
272
+ // deep clones a hash of properties. expects only Hash, Array or
273
+ // primitives.
274
+ _deepClone: function(obj) {
275
+ var ret = obj ;
276
+
277
+ switch($type(obj)) {
278
+ case T_HASH:
279
+ ret = {} ;
280
+ for(var key in obj) {
281
+ if (!obj.hasOwnProperty(key)) continue ;
282
+ ret[key] = this._deepClone(obj[key]) ;
283
+ }
284
+ break ;
285
+ case T_ARRAY:
286
+ ret = [] ;
287
+ for(var idx=0;idx < obj.length; idx++) {
288
+ ret.push(this._deepClone(obj[idx])) ;
289
+ }
290
+ break ;
291
+ }
292
+ return ret ;
293
+ },
294
+
295
+ // converts the input object into a eval-able string
296
+ _stringify: function(obj) {
297
+ var ret = obj ;
298
+ switch($type(obj)) {
299
+ case T_HASH:
300
+ ret = [] ;
301
+ for(var key in obj) {
302
+ if (!obj.hasOwnProperty(key)) continue ;
303
+ ret.push([key, this._stringify(obj[key])].join(': ')) ;
304
+ }
305
+ ret = "{ %@ }".fmt(ret.join(",\n ")) ;
306
+ break ;
307
+
308
+ case T_ARRAY:
309
+ ret = [] ;
310
+ for(var idx=0; idx < obj.length; idx++) {
311
+ ret.push(this._stringify(obj[idx])) ;
312
+ }
313
+ ret = '[%@]'.fmt(ret.join(', ')) ;
314
+ break ;
315
+
316
+ case T_NULL:
317
+ ret = 'null' ;
318
+ break ;
319
+
320
+ // Strings can be either property paths or quoted strings. They are
321
+ // quoted strings if they are in "quotes". If they are strings they
322
+ // should be already quoted, etc.
323
+ case T_STRING:
324
+ ret = obj ;
325
+ break ;
326
+
327
+ default:
328
+ ret = (obj.toString) ? obj.toString() : obj ;
329
+ }
330
+ return ret ;
331
+ }
332
+
333
+ }) ;
334
+
335
+ SC.Builder.newBuilder = function(attrs) {
336
+ if (!attrs) attrs = {} ;
337
+ attrs.newRecord = YES ;
338
+ return this.create(attrs) ;
339
+ } ;
@@ -0,0 +1,81 @@
1
+ // ==========================================================================
2
+ // Button View Builder
3
+ // ==========================================================================
4
+
5
+ require('builders/builder') ;
6
+
7
+ /**
8
+ */
9
+ SC.ButtonView.Builder = SC.Builder.extend({
10
+
11
+ _targetClass: 'SC.ButtonView',
12
+
13
+ /**
14
+ Defined by subclasses. If this is true, then the content of the view
15
+ is the HTML generated by children.
16
+ */
17
+ isContainer: NO,
18
+
19
+ /**
20
+ Defined by subclasses. If true, then views will be generated with an
21
+ outletFor() attached to them.
22
+ */
23
+ isOutletView: YES,
24
+
25
+ /**
26
+ The default profile. New records will inherit a cloned set of these
27
+ attributes.
28
+ */
29
+ defaultAttributes: {
30
+ propertySettings: {},
31
+ bindSettings: {},
32
+ attributeSettings: {},
33
+ htmlTemplate: '<{%TagName%}{%Attributes%}><span class="button-inner"><span class="label">{%Content%}</span></span></{%TagName%}>',
34
+ cssClassNames: ['sc-button-view', 'regular', 'normal'],
35
+ lazyOutlet: NO,
36
+ tagName: 'a',
37
+
38
+ title: 'Hello!'
39
+ },
40
+
41
+ init: function() {
42
+ arguments.callee.base.apply(this) ;
43
+ if (this.get('newRecord')) {
44
+ var attrs = this._deepClone(this.get('defaultAttributes'));
45
+ attrs.name = attrs.targetClass = this._targetClass ;
46
+ attrs.guid = attrs.htmlId = 'id%@'.fmt(Date.now().toString());
47
+ this.updateAttributes(attrs, YES, YES);
48
+ }
49
+ },
50
+
51
+ /**
52
+ Invoked just before the attributes are written out. You can add anything
53
+ you want here.
54
+ */
55
+ prepareAttributes: function(attrs) {
56
+ return attrs ;
57
+ },
58
+
59
+ /**
60
+ Invoked just before the class name is set. Add anything you want here.
61
+ */
62
+ prepareClassNames: function(classNames) {
63
+ return classNames ;
64
+ },
65
+
66
+ /**
67
+ Invoked just before outlets are added and the final JS is generated. Add
68
+ anything here you might pull from specialized preferences.
69
+ */
70
+ prepareProperties: function(props) { return props; },
71
+
72
+ /**
73
+ Invoked just before bindings are blended into properties. Add your own.
74
+ */
75
+ prepareBindings: function(binds) { return binds; },
76
+
77
+ innerHtml: function() {
78
+ return this.get('title') ;
79
+ }.property('title')
80
+
81
+ }) ;