rasputin 0.13.2 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,8 +25,7 @@ The new default is '/'
25
25
 
26
26
  Precompilation :
27
27
 
28
- Starting with 0.9.0 release, Rasputin will precompile your handlebars templates.
29
- Starting with 0.12.1 release, default behavior is to precompile templates only in production environment.
28
+ Rasputin can precompile your handlebars templates. Default behavior is to precompile templates only in production environment.
30
29
  If you don't want this behavior you can turn it off in your rails configuration block :
31
30
 
32
31
  config.rasputin.precompile_handlebars = false
@@ -72,15 +71,13 @@ And any of the following you want to include:
72
71
 
73
72
  //= require ember-data
74
73
 
75
- In your stylesheet assets manifest (app/assets/stylesheets/application.css) add the following:
76
-
77
- /*
78
- * = require normalize
79
- */
80
-
81
74
  ChangeLog
82
75
  ----------
83
76
 
77
+ 0.14.0
78
+
79
+ * Update to Ember.js 0.9.4
80
+
84
81
  0.13.2
85
82
 
86
83
  * Rails 3.2 support
@@ -45,7 +45,7 @@ module Rasputin
45
45
 
46
46
  def compile(template)
47
47
  template = template.read if template.respond_to?(:read)
48
- Source.context.call("EmberHandlebars.precompile", template)
48
+ Source.context.call("precompileEmberHandlebars", template)
49
49
  end
50
50
  end
51
51
  end
@@ -1,3 +1,3 @@
1
1
  module Rasputin
2
- VERSION = "0.13.2"
2
+ VERSION = "0.14.0"
3
3
  end
@@ -1,12 +1,12 @@
1
1
 
2
2
  (function(exports) {
3
- window.DS = SC.Namespace.create();
3
+ window.DS = Ember.Namespace.create();
4
4
 
5
5
  })({});
6
6
 
7
7
 
8
8
  (function(exports) {
9
- DS.Adapter = SC.Object.extend({
9
+ DS.Adapter = Ember.Object.extend({
10
10
  commit: function(store, commitDetails) {
11
11
  commitDetails.updated.eachType(function(type, array) {
12
12
  this.updateRecords(store, type, array.slice());
@@ -71,9 +71,198 @@ DS.fixtureAdapter = DS.Adapter.create({
71
71
 
72
72
 
73
73
  (function(exports) {
74
- var get = SC.get, set = SC.set;
74
+ var get = Ember.get, set = Ember.set, getPath = Ember.getPath;
75
75
 
76
- DS.ModelArray = SC.ArrayProxy.extend({
76
+ DS.RESTAdapter = DS.Adapter.extend({
77
+ createRecord: function(store, type, model) {
78
+ var root = this.rootForType(type);
79
+
80
+ var data = {};
81
+ data[root] = get(model, 'data');
82
+
83
+ this.ajax("/" + this.pluralize(root), "POST", {
84
+ data: data,
85
+ success: function(json) {
86
+ store.didCreateRecord(model, json[root]);
87
+ }
88
+ });
89
+ },
90
+
91
+ createRecords: function(store, type, models) {
92
+ if (get(this, 'bulkCommit') === false) {
93
+ return this._super(store, type, models);
94
+ }
95
+
96
+ var root = this.rootForType(type),
97
+ plural = this.pluralize(root);
98
+
99
+ var data = {};
100
+ data[plural] = models.map(function(model) {
101
+ return get(model, 'data');
102
+ });
103
+
104
+ this.ajax("/" + this.pluralize(root), "POST", {
105
+ data: data,
106
+ success: function(json) {
107
+ store.didCreateRecords(type, models, json[plural]);
108
+ }
109
+ });
110
+ },
111
+
112
+ updateRecord: function(store, type, model) {
113
+ var id = get(model, 'id');
114
+ var root = this.rootForType(type);
115
+
116
+ var data = {};
117
+ data[root] = get(model, 'data');
118
+
119
+ var url = ["", this.pluralize(root), id].join("/");
120
+
121
+ this.ajax(url, "PUT", {
122
+ data: data,
123
+ success: function(json) {
124
+ store.didUpdateRecord(model, json[root]);
125
+ }
126
+ });
127
+ },
128
+
129
+ updateRecords: function(store, type, models) {
130
+ if (get(this, 'bulkCommit') === false) {
131
+ return this._super(store, type, models);
132
+ }
133
+
134
+ var root = this.rootForType(type),
135
+ plural = this.pluralize(root);
136
+
137
+ var data = {};
138
+ data[plural] = models.map(function(model) {
139
+ return get(model, 'data');
140
+ });
141
+
142
+ this.ajax("/" + this.pluralize(root), "POST", {
143
+ data: data,
144
+ success: function(json) {
145
+ store.didUpdateRecords(models, json[plural]);
146
+ }
147
+ });
148
+ },
149
+
150
+ deleteRecord: function(store, type, model) {
151
+ var id = get(model, 'id');
152
+ var root = this.rootForType(type);
153
+
154
+ var url = ["", this.pluralize(root), id].join("/");
155
+
156
+ this.ajax(url, "DELETE", {
157
+ success: function(json) {
158
+ store.didDeleteRecord(model);
159
+ }
160
+ });
161
+ },
162
+
163
+ deleteRecords: function(store, type, models) {
164
+ if (get(this, 'bulkCommit') === false) {
165
+ return this._super(store, type, models);
166
+ }
167
+
168
+ var root = this.rootForType(type),
169
+ plural = this.pluralize(root),
170
+ primaryKey = getPath(type, 'proto.primaryKey');
171
+
172
+ var data = {};
173
+ data[plural] = models.map(function(model) {
174
+ return get(model, primaryKey);
175
+ });
176
+
177
+ this.ajax("/" + this.pluralize(root) + "/delete", "POST", {
178
+ data: data,
179
+ success: function(json) {
180
+ store.didDeleteRecords(models);
181
+ }
182
+ });
183
+ },
184
+
185
+ find: function(store, type, id) {
186
+ var root = this.rootForType(type);
187
+
188
+ var url = ["", this.pluralize(root), id].join("/");
189
+
190
+ this.ajax(url, "GET", {
191
+ success: function(json) {
192
+ store.load(type, json[root]);
193
+ }
194
+ });
195
+ },
196
+
197
+ findMany: function(store, type, ids) {
198
+ var root = this.rootForType(type), plural = this.pluralize(root);
199
+
200
+ this.ajax("/" + plural, "GET", {
201
+ data: { ids: ids },
202
+ success: function(json) {
203
+ store.loadMany(type, ids, json[plural]);
204
+ }
205
+ });
206
+ var url = "/" + plural;
207
+ },
208
+
209
+ findAll: function(store, type) {
210
+ var root = this.rootForType(type), plural = this.pluralize(root);
211
+
212
+ this.ajax("/" + plural, "GET", {
213
+ success: function(json) {
214
+ store.loadMany(type, json[plural]);
215
+ }
216
+ });
217
+ },
218
+
219
+ findQuery: function(store, type, query, modelArray) {
220
+ var root = this.rootForType(type), plural = this.pluralize(root);
221
+
222
+ this.ajax("/" + plural, "GET", {
223
+ data: query,
224
+ success: function(json) {
225
+ modelArray.load(json[plural]);
226
+ }
227
+ });
228
+ },
229
+
230
+ // HELPERS
231
+
232
+ plurals: {},
233
+
234
+ // define a plurals hash in your subclass to define
235
+ // special-case pluralization
236
+ pluralize: function(name) {
237
+ return this.plurals[name] || name + "s";
238
+ },
239
+
240
+ rootForType: function(type) {
241
+ if (type.url) { return type.url; }
242
+
243
+ // use the last part of the name as the URL
244
+ var parts = type.toString().split(".");
245
+ var name = parts[parts.length - 1];
246
+ return name.replace(/([A-Z])/g, '_$1').toLowerCase().slice(1);
247
+ },
248
+
249
+ ajax: function(url, type, hash) {
250
+ hash.url = url;
251
+ hash.type = type;
252
+ hash.dataType = "json";
253
+
254
+ jQuery.ajax(hash);
255
+ }
256
+ });
257
+
258
+
259
+ })({});
260
+
261
+
262
+ (function(exports) {
263
+ var get = Ember.get, set = Ember.set;
264
+
265
+ DS.ModelArray = Ember.ArrayProxy.extend({
77
266
  type: null,
78
267
  content: null,
79
268
  store: null,
@@ -86,7 +275,7 @@ DS.ModelArray = SC.ArrayProxy.extend({
86
275
  arrayDidChange: function(array, index, removed, added) {
87
276
  var modelCache = get(this, 'modelCache');
88
277
  modelCache.replace(index, 0, Array(added));
89
-
278
+
90
279
  this._super(array, index, removed, added);
91
280
  },
92
281
 
@@ -120,7 +309,7 @@ DS.ModelArray = SC.ArrayProxy.extend({
120
309
  DS.FilteredModelArray = DS.ModelArray.extend({
121
310
  filterFunction: null,
122
311
 
123
- updateFilter: SC.observer(function() {
312
+ updateFilter: Ember.observer(function() {
124
313
  var store = get(this, 'store');
125
314
  store.updateModelArrayFilter(this, get(this, 'type'), get(this, 'filterFunction'));
126
315
  }, 'filterFunction')
@@ -148,18 +337,18 @@ DS.AdapterPopulatedModelArray = DS.ModelArray.extend({
148
337
  (function(exports) {
149
338
  var get = Ember.get, set = Ember.set, getPath = Ember.getPath, fmt = Ember.String.fmt;
150
339
 
151
- var OrderedSet = SC.Object.extend({
340
+ var OrderedSet = Ember.Object.extend({
152
341
  init: function() {
153
342
  this.clear();
154
343
  },
155
344
 
156
345
  clear: function() {
157
346
  this.set('presenceSet', {});
158
- this.set('list', SC.NativeArray.apply([]));
347
+ this.set('list', Ember.NativeArray.apply([]));
159
348
  },
160
349
 
161
350
  add: function(obj) {
162
- var guid = SC.guidFor(obj),
351
+ var guid = Ember.guidFor(obj),
163
352
  presenceSet = get(this, 'presenceSet'),
164
353
  list = get(this, 'list');
165
354
 
@@ -170,7 +359,7 @@ var OrderedSet = SC.Object.extend({
170
359
  },
171
360
 
172
361
  remove: function(obj) {
173
- var guid = SC.guidFor(obj),
362
+ var guid = Ember.guidFor(obj),
174
363
  presenceSet = get(this, 'presenceSet'),
175
364
  list = get(this, 'list');
176
365
 
@@ -210,7 +399,7 @@ var OrderedSet = SC.Object.extend({
210
399
  we delete its entry in `keys` and `values`.
211
400
  */
212
401
 
213
- var Hash = SC.Object.extend({
402
+ var Hash = Ember.Object.extend({
214
403
  init: function() {
215
404
  set(this, 'keys', OrderedSet.create());
216
405
  set(this, 'values', {});
@@ -336,20 +525,20 @@ DS.Transaction = Ember.Object.extend({
336
525
 
337
526
 
338
527
  (function(exports) {
339
- var get = SC.get, set = SC.set, getPath = SC.getPath, fmt = SC.String.fmt;
528
+ var get = Ember.get, set = Ember.set, getPath = Ember.getPath, fmt = Ember.String.fmt;
340
529
 
341
- var OrderedSet = SC.Object.extend({
530
+ var OrderedSet = Ember.Object.extend({
342
531
  init: function() {
343
532
  this.clear();
344
533
  },
345
534
 
346
535
  clear: function() {
347
536
  this.set('presenceSet', {});
348
- this.set('list', SC.NativeArray.apply([]));
537
+ this.set('list', Ember.NativeArray.apply([]));
349
538
  },
350
539
 
351
540
  add: function(obj) {
352
- var guid = SC.guidFor(obj),
541
+ var guid = Ember.guidFor(obj),
353
542
  presenceSet = get(this, 'presenceSet'),
354
543
  list = get(this, 'list');
355
544
 
@@ -360,7 +549,7 @@ var OrderedSet = SC.Object.extend({
360
549
  },
361
550
 
362
551
  remove: function(obj) {
363
- var guid = SC.guidFor(obj),
552
+ var guid = Ember.guidFor(obj),
364
553
  presenceSet = get(this, 'presenceSet'),
365
554
  list = get(this, 'list');
366
555
 
@@ -415,7 +604,7 @@ var OrderedSet = SC.Object.extend({
415
604
  You can learn more about writing a custom adapter by reading the `DS.Adapter`
416
605
  documentation.
417
606
  */
418
- DS.Store = SC.Object.extend({
607
+ DS.Store = Ember.Object.extend({
419
608
 
420
609
  /**
421
610
  Many methods can be invoked without specifying which store should be used.
@@ -431,7 +620,7 @@ DS.Store = SC.Object.extend({
431
620
  }
432
621
 
433
622
  set(this, 'data', []);
434
- set(this, 'ids', {});
623
+ set(this, '_typeMap', {});
435
624
  set(this, 'models', []);
436
625
  set(this, 'modelArrays', []);
437
626
  set(this, 'modelArraysByClientId', {});
@@ -465,7 +654,7 @@ DS.Store = SC.Object.extend({
465
654
  */
466
655
  adapter: null,
467
656
 
468
- _adapter: SC.computed(function() {
657
+ _adapter: Ember.computed(function() {
469
658
  var adapter = get(this, 'adapter');
470
659
  if (typeof adapter === 'string') {
471
660
  return getPath(this, adapter);
@@ -500,7 +689,7 @@ DS.Store = SC.Object.extend({
500
689
  set(model, 'clientId', clientId);
501
690
 
502
691
  models[clientId] = model;
503
-
692
+
504
693
  this.updateModelArrays(type, clientId, hash);
505
694
 
506
695
  return model;
@@ -543,11 +732,11 @@ DS.Store = SC.Object.extend({
543
732
 
544
733
  if (query !== undefined) {
545
734
  return this.findMany(type, id, query);
546
- } else if (SC.typeOf(id) === 'object') {
735
+ } else if (Ember.typeOf(id) === 'object') {
547
736
  return this.findQuery(type, id);
548
737
  }
549
738
 
550
- if (SC.isArray(id)) {
739
+ if (Ember.isArray(id)) {
551
740
  return this.findMany(type, id);
552
741
  }
553
742
 
@@ -636,12 +825,19 @@ DS.Store = SC.Object.extend({
636
825
  },
637
826
 
638
827
  findAll: function(type) {
828
+
829
+ var typeMap = this.typeMapFor(type),
830
+ findAllCache = typeMap.findAllCache;
831
+
832
+ if (findAllCache) { return findAllCache; }
833
+
639
834
  var array = DS.ModelArray.create({ type: type, content: Ember.A([]), store: this });
640
835
  this.registerModelArray(array, type);
641
836
 
642
837
  var adapter = get(this, '_adapter');
643
838
  if (adapter && adapter.findAll) { adapter.findAll(this, type); }
644
839
 
840
+ typeMap.findAllCache = array;
645
841
  return array;
646
842
  },
647
843
 
@@ -842,14 +1038,14 @@ DS.Store = SC.Object.extend({
842
1038
  // . TYPE MAP .
843
1039
  // ............
844
1040
 
845
- typeMap: function(type) {
846
- var ids = get(this, 'ids');
847
- var guidForType = SC.guidFor(type);
1041
+ typeMapFor: function(type) {
1042
+ var ids = get(this, '_typeMap');
1043
+ var guidForType = Ember.guidFor(type);
848
1044
 
849
- var idToClientIdMap = ids[guidForType];
1045
+ var typeMap = ids[guidForType];
850
1046
 
851
- if (idToClientIdMap) {
852
- return idToClientIdMap;
1047
+ if (typeMap) {
1048
+ return typeMap;
853
1049
  } else {
854
1050
  return (ids[guidForType] =
855
1051
  {
@@ -862,19 +1058,19 @@ DS.Store = SC.Object.extend({
862
1058
  },
863
1059
 
864
1060
  idToClientIdMap: function(type) {
865
- return this.typeMap(type).idToCid;
1061
+ return this.typeMapFor(type).idToCid;
866
1062
  },
867
1063
 
868
1064
  idList: function(type) {
869
- return this.typeMap(type).idList;
1065
+ return this.typeMapFor(type).idList;
870
1066
  },
871
1067
 
872
1068
  clientIdList: function(type) {
873
- return this.typeMap(type).cidList;
1069
+ return this.typeMapFor(type).cidList;
874
1070
  },
875
1071
 
876
1072
  clientIdToHashMap: function(type) {
877
- return this.typeMap(type).cidToHash;
1073
+ return this.typeMapFor(type).cidToHash;
878
1074
  },
879
1075
 
880
1076
  /** @private
@@ -886,7 +1082,7 @@ DS.Store = SC.Object.extend({
886
1082
  @param {String|Number} id
887
1083
  */
888
1084
  clientIdForId: function(type, id) {
889
- return this.typeMap(type).idToCid[id];
1085
+ return this.typeMapFor(type).idToCid[id];
890
1086
  },
891
1087
 
892
1088
  idForHash: function(type, hash) {
@@ -920,7 +1116,6 @@ DS.Store = SC.Object.extend({
920
1116
  id = hash[primaryKey];
921
1117
  }
922
1118
 
923
- var ids = get(this, 'ids');
924
1119
  var data = this.clientIdToHashMap(type);
925
1120
  var models = get(this, 'models');
926
1121
 
@@ -1016,16 +1211,16 @@ DS.Store = SC.Object.extend({
1016
1211
 
1017
1212
 
1018
1213
  (function(exports) {
1019
- var get = SC.get, set = SC.set, getPath = SC.getPath;
1214
+ var get = Ember.get, set = Ember.set, getPath = Ember.getPath;
1020
1215
 
1021
- var stateProperty = SC.computed(function(key) {
1216
+ var stateProperty = Ember.computed(function(key) {
1022
1217
  var parent = get(this, 'parentState');
1023
1218
  if (parent) {
1024
1219
  return get(parent, key);
1025
1220
  }
1026
1221
  }).property();
1027
1222
 
1028
- DS.State = SC.State.extend({
1223
+ DS.State = Ember.State.extend({
1029
1224
  isLoaded: stateProperty,
1030
1225
  isDirty: stateProperty,
1031
1226
  isSaving: stateProperty,
@@ -1134,7 +1329,7 @@ var DirtyState = DS.State.extend({
1134
1329
  });
1135
1330
 
1136
1331
  var states = {
1137
- rootState: SC.State.create({
1332
+ rootState: Ember.State.create({
1138
1333
  isLoaded: false,
1139
1334
  isDirty: false,
1140
1335
  isSaving: false,
@@ -1156,7 +1351,7 @@ var states = {
1156
1351
  }),
1157
1352
 
1158
1353
  loading: DS.State.create({
1159
- willLoadData: SC.K,
1354
+ willLoadData: Ember.K,
1160
1355
 
1161
1356
  exit: function(manager) {
1162
1357
  var model = get(manager, 'model');
@@ -1180,7 +1375,7 @@ var states = {
1180
1375
  loaded: DS.State.create({
1181
1376
  isLoaded: true,
1182
1377
 
1183
- willLoadData: SC.K,
1378
+ willLoadData: Ember.K,
1184
1379
 
1185
1380
  setProperty: function(manager, context) {
1186
1381
  setProperty(manager, context);
@@ -1266,11 +1461,11 @@ DS.StateManager = Ember.StateManager.extend({
1266
1461
  states: states
1267
1462
  });
1268
1463
 
1269
- var retrieveFromCurrentState = SC.computed(function(key) {
1464
+ var retrieveFromCurrentState = Ember.computed(function(key) {
1270
1465
  return get(getPath(this, 'stateManager.currentState'), key);
1271
1466
  }).property('stateManager.currentState').cacheable();
1272
1467
 
1273
- DS.Model = SC.Object.extend({
1468
+ DS.Model = Ember.Object.extend({
1274
1469
  isLoaded: retrieveFromCurrentState,
1275
1470
  isDirty: retrieveFromCurrentState,
1276
1471
  isSaving: retrieveFromCurrentState,
@@ -1383,7 +1578,7 @@ DS.attr = function(type, options) {
1383
1578
  var transformFrom = transform.from;
1384
1579
  var transformTo = transform.to;
1385
1580
 
1386
- return SC.computed(function(key, value) {
1581
+ return Ember.computed(function(key, value) {
1387
1582
  var data = get(this, 'data');
1388
1583
 
1389
1584
  key = (options && options.key) ? options.key : key;
@@ -1402,65 +1597,70 @@ DS.attr = function(type, options) {
1402
1597
  }).property('data');
1403
1598
  };
1404
1599
 
1405
- var embeddedFindMany = function(store, type, data, key) {
1406
- var association = data ? get(data, key) : [];
1407
- return store.loadMany(type, association).ids;
1600
+ var embeddedFindRecord = function(store, type, data, key, one) {
1601
+ var association = data ? get(data, key) : one ? null : [];
1602
+ if (one) {
1603
+ return association ? store.load(type, association).id : null;
1604
+ } else {
1605
+ return association ? store.loadMany(type, association).ids : [];
1606
+ }
1408
1607
  };
1409
1608
 
1410
- var referencedFindMany = function(store, type, data, key) {
1411
- return data ? get(data, key) : [];
1609
+ var referencedFindRecord = function(store, type, data, key, one) {
1610
+ return data ? get(data, key) : one ? null : [];
1412
1611
  };
1413
1612
 
1414
- DS.hasMany = function(type, options) {
1415
- var embedded = options && options.embedded, load;
1613
+ var hasAssociation = function(type, options, one) {
1614
+ var embedded = options && options.embedded,
1615
+ findRecord = embedded ? embeddedFindRecord : referencedFindRecord;
1416
1616
 
1417
- findMany = embedded ? embeddedFindMany : referencedFindMany;
1617
+ return Ember.computed(function(key) {
1618
+ var data = get(this, 'data'), ids, id, association,
1619
+ store = get(this, 'store');
1418
1620
 
1419
- return SC.computed(function(key) {
1420
- var data = get(this, 'data'), ids;
1421
- var store = get(this, 'store');
1621
+ if (typeof type === 'string') { type = getPath(this, type); }
1422
1622
 
1423
1623
  key = (options && options.key) ? options.key : key;
1424
- ids = findMany(store, type, data, key);
1425
- var hasMany = store.findMany(type, ids);
1426
-
1427
- SC.addObserver(this, 'data', function() {
1428
- var data = get(this, 'data');
1429
-
1430
- var ids = findMany(store, type, data, key);
1431
- store.findMany(type, ids);
1432
-
1433
- var idToClientIdMap = store.idToClientIdMap(type);
1624
+ if (one) {
1625
+ id = findRecord(store, type, data, key, true);
1626
+ association = id ? store.find(type, id) : null;
1627
+ } else {
1628
+ ids = findRecord(store, type, data, key);
1629
+ association = store.findMany(type, ids);
1630
+ }
1434
1631
 
1435
- var clientIds = ids.map(function(id) {
1436
- return idToClientIdMap[id];
1437
- });
1632
+ return association;
1633
+ }).property('data').cacheable();
1634
+ };
1438
1635
 
1439
- set(hasMany, 'content', Ember.A(clientIds));
1440
- });
1636
+ DS.hasMany = function(type, options) {
1637
+ ember_assert("The type passed to DS.hasMany must be defined", !!type);
1638
+ return hasAssociation(type, options);
1639
+ };
1441
1640
 
1442
- return hasMany;
1443
- }).property().cacheable();
1641
+ DS.hasOne = function(type, options) {
1642
+ ember_assert("The type passed to DS.hasOne must be defined", !!type);
1643
+ return hasAssociation(type, options, true);
1444
1644
  };
1445
1645
 
1446
1646
  DS.attr.transforms = {
1447
1647
  string: {
1448
1648
  from: function(serialized) {
1449
- return String(serialized);
1649
+ return Em.none(serialized) ? null : String(serialized);
1450
1650
  },
1451
1651
 
1452
1652
  to: function(deserialized) {
1453
- return String(deserialized);
1653
+ return Em.none(deserialized) ? null : String(deserialized);
1454
1654
  }
1455
1655
  },
1456
1656
 
1457
1657
  integer: {
1458
1658
  from: function(serialized) {
1459
- return Number(serialized);
1659
+ return Em.none(serialized) ? null : Number(serialized);
1460
1660
  },
1461
1661
 
1462
1662
  to: function(deserialized) {
1463
- return Number(deserialized);
1663
+ return Em.none(deserialized) ? null : Number(deserialized);
1464
1664
  }
1465
1665
  },
1466
1666