cedar 0.2.75.pre → 0.2.77.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8253c7cd2893000d1de5444f423af695008e01fc
4
- data.tar.gz: b6262ffdb67d035a7256d022c41bd5e662cbe845
3
+ metadata.gz: b63877f8b178af1ed5069637495d6aeb9006e933
4
+ data.tar.gz: f03d617296b6bd81a5947174b11cf0fa38294763
5
5
  SHA512:
6
- metadata.gz: 52eb54e19bceb547f2d670798343809715ad43813397a493497963d7cbc983638e84a65d8d50f61efbbac45567c483cc145f669182cd9fa50e7cf8620ff460e7
7
- data.tar.gz: b7b54fbf1f0adb1347b3189bedc775cf9a7e12a4032b1e97128922a5da0d3269b2a0bc21bafbca939075c72d5eabd5e53878025e202ae4644df216e8c30e4383
6
+ metadata.gz: 8e4763372fb260e068e9372900311372b5c1f4bdbb856a19658b7946959c84f20a49b27ad1e2eb0d276364601d658aec76e57ce3e327a22058117e7c2fe42537
7
+ data.tar.gz: d62a6ace3bac056ee9517f046e389fbb73c401732615f81f7bf31afefcc95bdc43e2a45acd892fec9223a424d9de906c264171846caf80100a8bf78eefb1b09d
@@ -1,3 +1,9 @@
1
1
  window.Cedar = window.Cedar || {};
2
2
  window.Cedar.config = window.Cedar.config || {};
3
+ window.Cedar.config.server = "<%= Cedar.config.server %>"
4
+ window.Cedar.config.debug = <%= Cedar.config.debug %>
5
+ window.Cedar.config.wait = <%= Cedar.config.wait %>
6
+ window.Cedar.config.fetch = <%= Cedar.config.fetch %>
7
+ window.Cedar.config.forceHttps = <%= Cedar.config.force_https %>
8
+ window.Cedar.config.objectNameFilter = "<%= Cedar.config.object_name_filter %>"
3
9
  window.Cedar.config.liveMode = <%= Cedar.config.live_mode %>
@@ -64,18 +64,22 @@ Handlebars.registerHelper('cedar', function(options) {
64
64
  var output = '';
65
65
 
66
66
  var type = options.hash.type || 'ContentEntry';
67
+ var cedarClass = blockHelperStyle() ? 'ContentObject' : 'ContentEntry'
68
+
69
+ Cedar.store.get(type, {id: options.hash.id}).then(function(data){
70
+ var cedarObject = new window.Cedar[cedarClass]({ cedarId: options.hash.id, cedarType: type, defaultContent: options.hash.default });
71
+ cedarObject.setContent(data);
67
72
 
68
- new window.Cedar[type]({ cedarId: options.hash.id, defaultContent: options.hash.default }).load().then(function(contentEntry){
69
73
  if (blockHelperStyle()) {
70
74
  if (Cedar.auth.isEditMode()) {
71
- output += contentEntry.getEditOpen();
75
+ output += cedarObject.getEditOpen();
72
76
  }
73
- output += unescapeHtml(options.fn(contentEntry.toJSON()));
77
+ output += unescapeHtml(options.fn(cedarObject.toJSON()));
74
78
  if (Cedar.auth.isEditMode()) {
75
- output += contentEntry.getEditClose();
79
+ output += cedarObject.getEditClose();
76
80
  }
77
81
  } else {
78
- output = contentEntry.toString();
82
+ output = cedarObject.toString();
79
83
  }
80
84
 
81
85
  replaceElement(outputEl.id, output);
@@ -7,9 +7,7 @@ window.Cedar = $.extend({}, window.Cedar, {
7
7
  store: null,
8
8
  auth: null
9
9
  });
10
- window.Cedar.config = window.Cedar.config || {
11
- liveMode: true
12
- };
10
+ window.Cedar.config = window.Cedar.config || {};
13
11
 
14
12
  /**
15
13
  * Cedar.Init
@@ -52,10 +50,12 @@ Cedar.Application = function(options) {
52
50
  debug: false,
53
51
  fetch: true,
54
52
  wait: false,
55
- forceHttps: false
53
+ forceHttps: false,
54
+ objectNameFilter: '',
55
+ liveMode: true
56
56
  };
57
57
 
58
- this.options = $.extend({}, defaults, options);
58
+ this.options = $.extend({}, $.extend({}, window.Cedar.config, defaults), options);
59
59
 
60
60
  if (this.options.server === undefined) {
61
61
  throw 'Cedar Error: must provide "server" value on Init()';
@@ -66,6 +66,8 @@ Cedar.Application = function(options) {
66
66
  Cedar.config.debug = this.options.debug;
67
67
  Cedar.config.wait = this.options.wait;
68
68
  Cedar.config.fetch = this.options.fetch;
69
+ Cedar.config.objectNameFilter = this.options.objectNameFilter;
70
+ Cedar.config.liveMode = this.options.liveMode;
69
71
 
70
72
  if (Cedar.events === undefined) {
71
73
  Cedar.events = new Cedar.Events();
@@ -243,18 +245,23 @@ Cedar.Store = function() {
243
245
  };
244
246
 
245
247
  /**
246
- * store a single json item by key
247
- *
248
- * @param <string> 'key'
249
- * @param <json> 'item'
248
+ * get formatted version of type
249
+ */
250
+ Cedar.Store.prototype.formattedType = function (type) {
251
+ return "cedar_" + s(_(type).pluralize()).underscored().value();
252
+ };
253
+
254
+ /**
255
+ * store a collection of items by type
250
256
  */
251
- Cedar.Store.prototype.put = function ( key, item ) {
252
- this.cache[key] = typeof item === "string" ? item : JSON.stringify(item);
257
+ Cedar.Store.prototype.putCollection = function ( type, collection ) {
258
+ var formattedType = this.formattedType(type);
259
+ this.cache[formattedType] = JSON.stringify(collection);
253
260
  };
254
261
 
255
262
  // Return promise of parsed content from local or remote storage
256
- Cedar.Store.prototype.get = function(key) {
257
- return this.getDeferred(key).then(function(data) {
263
+ Cedar.Store.prototype.get = function(type, attributes) {
264
+ return this.getDeferred(this.formattedType(type), attributes).then(function(data) {
258
265
  try {
259
266
  return JSON.parse(data);
260
267
  } catch (e) {
@@ -263,29 +270,43 @@ Cedar.Store.prototype.get = function(key) {
263
270
  });
264
271
  };
265
272
 
273
+ // Retrieve the locally-stored model or collection if it exists
274
+ Cedar.Store.prototype.cachedObject = function(type, attributes) {
275
+ var cachedCollection = _((this.cache[type] && JSON.parse(this.cache[type]) || []));
276
+ var result;
277
+ if (attributes && attributes.hasOwnProperty('id')) {
278
+ result = cachedCollection.findWhere(attributes);
279
+ } else {
280
+ result = cachedCollection.where(attributes);
281
+ }
282
+ return result;
283
+ };
284
+
266
285
  // Return local content immediately if possible. Otherwise return deferred remote content
267
- Cedar.Store.prototype.getDeferred = function(key) {
268
- var cachedDeferred = this.cachedDeferred(key);
269
- var remoteDeferred = this.remoteDeferred(key);
286
+ Cedar.Store.prototype.getDeferred = function(type, attributes) {
287
+ var cachedDeferred = this.cachedDeferred(type, attributes);
288
+ var remoteDeferred = this.remoteDeferred(type, attributes);
270
289
 
271
- if (Cedar.config.wait || !this.cache[key]) {
272
- Cedar.debug('checking remote: ' + key);
290
+ if (Cedar.config.wait || _(this.cachedObject(type, attributes)).isEmpty()) {
291
+ if (Cedar.config.liveMode) {
292
+ Cedar.debug('checking remote: ' + type + '/' + JSON.stringify(attributes));
293
+ }
273
294
  return remoteDeferred;
274
295
  } else {
275
- Cedar.debug('get from cache: ' + key);
296
+ Cedar.debug('get from cache: ' + type + '/' + JSON.stringify(attributes));
276
297
  return cachedDeferred;
277
298
  }
278
299
  };
279
300
 
280
301
  // Deferred object containing local content
281
- Cedar.Store.prototype.cachedDeferred = function(key) {
282
- return $.Deferred().resolve(this.cache[key]);
302
+ Cedar.Store.prototype.cachedDeferred = function(type, attributes) {
303
+ return $.Deferred().resolve(this.cachedObject(type, attributes));
283
304
  };
284
305
 
285
306
  // Refresh local storage if needed and then return content
286
- Cedar.Store.prototype.remoteDeferred = function(key) {
307
+ Cedar.Store.prototype.remoteDeferred = function(type, attributes) {
287
308
  return this.refresh().then(function() {
288
- return this.cachedDeferred(key);
309
+ return this.cachedDeferred(type, attributes);
289
310
  }.bind(this));
290
311
  };
291
312
 
@@ -303,23 +324,23 @@ Cedar.Store.prototype.refresh = function() {
303
324
  // Get content objects from server and save to local storage
304
325
  Cedar.Store.prototype.getRemote = function(options) {
305
326
  var defaultOptions = {
306
- path: '/queries/contententries/'
327
+ path: '/queries/all/'
307
328
  };
308
329
  options = $.extend({}, defaultOptions, options);
309
330
  var defaultParams = {};
310
331
  var params = $.extend({}, defaultParams, {
311
- guidfilter: options.filter
332
+ filter: Cedar.config.objectNameFilter,
333
+ references: "all",
334
+ expand: "yes"
312
335
  });
313
336
 
314
337
  return this.lockedRequest({
315
338
  path: options.path,
316
339
  params: params,
317
340
  success: function(response) {
318
- $.each(response, function (index, value) {
319
- if (value.hasOwnProperty('id') && value.settings.hasOwnProperty('content')) {
320
- this.put(value.id, value);
321
- Cedar.debug("storing: " + value.id);
322
- }
341
+ _.chain(response).each(function(collection, type) {
342
+ this.putCollection(type, collection);
343
+ Cedar.debug("storing: " + type);
323
344
  }.bind(this));
324
345
  Cedar.debug("local storage was updated");
325
346
  this.loaded = true;
@@ -415,6 +436,7 @@ Parent class for all Cedar content object types
415
436
  */
416
437
  Cedar.ContentObject = function(options) {
417
438
  var defaults = {
439
+ cedarType: 'ContentEntry',
418
440
  el: '<div />'
419
441
  };
420
442
  this.options = $.extend({}, defaults, options);
@@ -429,18 +451,18 @@ Cedar.ContentObject.prototype = {
429
451
  },
430
452
 
431
453
  load: function() {
432
- return Cedar.store.get(this.options.cedarId).then(function(data) {
454
+ return Cedar.store.get(this.options.cedarType, this.options.cedarId).then(function(data) {
433
455
  this.setContent(data);
434
456
  return this;
435
457
  }.bind(this));
436
458
  },
437
459
 
438
460
  getContent: function() {
439
- return this.content || this.options.defaultContent;
461
+ return (this.content || this.options.defaultContent) || '';
440
462
  },
441
463
 
442
464
  setContent: function(data) {
443
- this.content = data;
465
+ this.content = data || '';
444
466
  },
445
467
 
446
468
  getContentWithEditTools: function() {
@@ -452,9 +474,11 @@ Cedar.ContentObject.prototype = {
452
474
  },
453
475
 
454
476
  toJSON: function() {
455
- return {
456
- content: this.getContent()
457
- };
477
+ return _.chain(this.content)
478
+ .pairs()
479
+ .map(function(pair) { return [ s.camelize(pair[0]), pair[1] ]; })
480
+ .object()
481
+ .value();
458
482
  },
459
483
 
460
484
  getEditOpen: function() {
@@ -466,7 +490,9 @@ Cedar.ContentObject.prototype = {
466
490
  var block = '<span class="cedar-cms-editable clearfix">';
467
491
  block += '<span class="cedar-cms-edit-tools">';
468
492
  block += '<a onclick="' + jsString + '" href="' + Cedar.config.server +
469
- '/cmsadmin/EditData?cdr=1&t=ContentEntry&o=' +
493
+ '/cmsadmin/EditData?cdr=1&t=' +
494
+ this.options.cedarType +
495
+ '&o=' +
470
496
  encodeURIComponent(this.options.cedarId) +
471
497
  '" class="cedar-cms-edit-icon cedar-js-edit" >';
472
498
  block += '<i class="cedar-cms-icon cedar-cms-icon-right cedar-cms-icon-edit"></i></a>';
@@ -492,23 +518,11 @@ Cedar.ContentEntry.prototype = Object.create(Cedar.ContentObject.prototype);
492
518
  Cedar.ContentEntry.prototype.constructor = Cedar.ContentEntry;
493
519
 
494
520
  Cedar.ContentEntry.prototype.setContent = function(data) {
495
- this.content = (data && (data.settings && data.settings.content)) || '';
496
- };
497
-
498
- /*
499
- Cedar.Program
500
- program object class
501
- */
502
- Cedar.Program = function(options) {
503
- Cedar.ContentObject.call(this, options);
521
+ this.content = (data && data.content) || '';
504
522
  };
505
- Cedar.Program.prototype = Object.create(Cedar.ContentObject.prototype);
506
- Cedar.Program.prototype.constructor = Cedar.Program;
507
523
 
508
- Cedar.Program.prototype.setContent = function(data) {
509
- this.content = (data && (data.settings && JSON.parse(data.settings.content))) || '';
510
- };
511
-
512
- Cedar.Program.prototype.toJSON = function(data) {
513
- return this.content;
524
+ Cedar.ContentEntry.prototype.toJSON = function(data) {
525
+ return {
526
+ content: this.getContent()
527
+ };
514
528
  };
data/lib/cedar/config.rb CHANGED
@@ -5,9 +5,15 @@
5
5
 
6
6
  module Cedar
7
7
  class Config
8
- attr_accessor :live_mode
8
+ attr_accessor :server, :debug, :wait, :fetch, :force_https, :object_name_filter, :live_mode
9
9
 
10
10
  def initialize
11
+ @server = ''
12
+ @debug = false
13
+ @wait = false
14
+ @fetch = true
15
+ @force_https = false
16
+ @object_name_filter = ''
11
17
  @live_mode = true
12
18
  end
13
19
  end
data/lib/cedar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cedar
2
- VERSION = "0.2.75.pre"
2
+ VERSION = "0.2.77.pre"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cedar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.75.pre
4
+ version: 0.2.77.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jed Murdock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-22 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler