cedar 0.2.4.pre → 0.2.5.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 +4 -4
- data/README.md +7 -0
- data/lib/assets/javascripts/cedar.handlebars.js +19 -15
- data/lib/assets/javascripts/cedar.js +180 -163
- data/lib/assets/stylesheets/{cedar_source.css → cedar_source.scss} +0 -0
- data/lib/cedar/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0f2cbdbbb9763368001f31b5043e6b2cff566c6
|
4
|
+
data.tar.gz: ba87685c025eefc461df4b023b5278e58036e132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 549c7b01125f1f5a50334004121c2f4221d8d23a1217da830f5fc7899e011ec94ebe6f2d88226ccafb5d9b51e544efcfc843d223d565816476048c0a21ebbc89
|
7
|
+
data.tar.gz: 1cf2652b3f6eb73965b525a47b0aabb58f01da62a1d0d28d0c26df062e672ee9a35cb757a954ac369ac7746e101388685ce55aa25563f22bfce6653e4f2e6223
|
data/README.md
CHANGED
@@ -47,6 +47,13 @@ You can also use the block-helper style which allows you to define a template th
|
|
47
47
|
|
48
48
|
## Ply Dev Notes
|
49
49
|
|
50
|
+
### Updating Project Assets
|
51
|
+
|
52
|
+
The authoritative source of the majority of the assets in this gem is the `cedar` Bower package. To update this gem with the latest version, you will need `bower` installed. You will also need to specify which version of `cedar` you want in the `bower.json` file. Finally you will need to run the following command from the root of this project:
|
53
|
+
|
54
|
+
`bower install`
|
55
|
+
|
56
|
+
### Publishing Gem
|
50
57
|
|
51
58
|
add yourself as a user at:
|
52
59
|
|
@@ -33,6 +33,24 @@ Handlebars.registerHelper('cedar', function(options) {
|
|
33
33
|
} else {
|
34
34
|
return false;
|
35
35
|
}
|
36
|
+
};
|
37
|
+
|
38
|
+
var replaceElement = function(id, content) {
|
39
|
+
// If rendered element exists than insert the content
|
40
|
+
var renderedEl = document.getElementById(id);
|
41
|
+
if (renderedEl !== null) {
|
42
|
+
var parentEl = renderedEl.parentNode;
|
43
|
+
var tempEl = document.createElement("div");
|
44
|
+
tempEl.innerHTML = content;
|
45
|
+
|
46
|
+
// Insert content node by node and then remove the existing element
|
47
|
+
var nodeList = tempEl.childNodes;
|
48
|
+
var nodeListLength = nodeList.length;
|
49
|
+
for(var i = 0; i < nodeListLength; i++) {
|
50
|
+
parentEl.insertBefore(nodeList[0], renderedEl);
|
51
|
+
}
|
52
|
+
parentEl.removeChild(renderedEl);
|
53
|
+
}
|
36
54
|
}
|
37
55
|
|
38
56
|
var tagName = options.hash.tagName || "span";
|
@@ -58,21 +76,7 @@ Handlebars.registerHelper('cedar', function(options) {
|
|
58
76
|
output = contentEntry.getContent();
|
59
77
|
}
|
60
78
|
|
61
|
-
|
62
|
-
var renderedEl = document.getElementById(outputEl.id);
|
63
|
-
if (renderedEl !== null) {
|
64
|
-
var parentEl = renderedEl.parentNode;
|
65
|
-
var tempEl = document.createElement("div");
|
66
|
-
tempEl.innerHTML = output;
|
67
|
-
|
68
|
-
// Insert content node by node and then remove the existing element
|
69
|
-
var nodeList = tempEl.childNodes;
|
70
|
-
var nodeListLength = nodeList.length;
|
71
|
-
for(var i = 0; i < nodeListLength; i++) {
|
72
|
-
parentEl.insertBefore(nodeList[0], renderedEl);
|
73
|
-
}
|
74
|
-
parentEl.removeChild(renderedEl);
|
75
|
-
}
|
79
|
+
replaceElement(outputEl.id, output);
|
76
80
|
});
|
77
81
|
|
78
82
|
return new Handlebars.SafeString(output || outputEl.outerHTML);
|
@@ -1,15 +1,11 @@
|
|
1
1
|
/**
|
2
2
|
* Global object for settings and storage
|
3
3
|
*/
|
4
|
-
|
4
|
+
window.Cedar = {
|
5
5
|
initialized: false,
|
6
6
|
store: null,
|
7
7
|
auth: null,
|
8
|
-
config: {
|
9
|
-
api: '',
|
10
|
-
server: '',
|
11
|
-
debug: false
|
12
|
-
}
|
8
|
+
config: {}
|
13
9
|
};
|
14
10
|
|
15
11
|
|
@@ -21,7 +17,7 @@ var Cedar = {
|
|
21
17
|
*/
|
22
18
|
Cedar.Init = function(options) {
|
23
19
|
return new Cedar.Application(options);
|
24
|
-
}
|
20
|
+
};
|
25
21
|
|
26
22
|
/**
|
27
23
|
* Global function to display message to console if Cedar.debug = true
|
@@ -30,9 +26,9 @@ Cedar.Init = function(options) {
|
|
30
26
|
*/
|
31
27
|
Cedar.debug = function(msg) {
|
32
28
|
if (Cedar.config.debug) {
|
33
|
-
console.log(msg);
|
29
|
+
window.console.log(msg);
|
34
30
|
}
|
35
|
-
}
|
31
|
+
};
|
36
32
|
|
37
33
|
/**
|
38
34
|
* Cedar.Application
|
@@ -59,7 +55,7 @@ Cedar.Application = function(options) {
|
|
59
55
|
|
60
56
|
this.options = $.extend({}, defaults, options);
|
61
57
|
|
62
|
-
if (
|
58
|
+
if (this.options.server === undefined) {
|
63
59
|
throw 'Cedar Error: must provide "server" value on Init()';
|
64
60
|
}
|
65
61
|
|
@@ -69,8 +65,8 @@ Cedar.Application = function(options) {
|
|
69
65
|
Cedar.config.wait = this.options.wait;
|
70
66
|
Cedar.config.fetch = this.options.fetch;
|
71
67
|
|
72
|
-
if (
|
73
|
-
Cedar
|
68
|
+
if (Cedar.events === undefined) {
|
69
|
+
Cedar.events = jQuery({});
|
74
70
|
}
|
75
71
|
|
76
72
|
if ( Cedar.store === null ) {
|
@@ -85,14 +81,10 @@ Cedar.Application = function(options) {
|
|
85
81
|
this.showGlobalActions();
|
86
82
|
}
|
87
83
|
|
88
|
-
if (Cedar.config.fetch) {
|
89
|
-
Cedar.store.fetched = Cedar.store.fetch();
|
90
|
-
}
|
91
|
-
|
92
84
|
Cedar.initialized = true;
|
93
85
|
|
94
|
-
this.initializeHTML()
|
95
|
-
}
|
86
|
+
this.initializeHTML();
|
87
|
+
};
|
96
88
|
|
97
89
|
Cedar.Application.prototype.initializeHTML = function() {
|
98
90
|
$('[data-cedar-id]').each(function(){
|
@@ -102,12 +94,12 @@ Cedar.Application.prototype.initializeHTML = function() {
|
|
102
94
|
cedarId: $this.data("cedarId")
|
103
95
|
}));
|
104
96
|
|
105
|
-
Cedar
|
97
|
+
Cedar.events.on("content:loaded", function() {
|
106
98
|
$this.data("cedarObject").render();
|
107
99
|
}.bind(this));
|
108
100
|
});
|
109
|
-
Cedar
|
110
|
-
}
|
101
|
+
Cedar.events.trigger("content:loaded");
|
102
|
+
};
|
111
103
|
|
112
104
|
Cedar.Application.prototype.getProtocol = function() {
|
113
105
|
if (this.options.forceHttps || window.location.protocol === 'https:') {
|
@@ -115,7 +107,7 @@ Cedar.Application.prototype.getProtocol = function() {
|
|
115
107
|
} else {
|
116
108
|
return 'http://';
|
117
109
|
}
|
118
|
-
}
|
110
|
+
};
|
119
111
|
|
120
112
|
Cedar.Application.prototype.showGlobalActions = function() {
|
121
113
|
$(document).ready(function() {
|
@@ -132,7 +124,7 @@ Cedar.Application.prototype.showGlobalActions = function() {
|
|
132
124
|
'</div>';
|
133
125
|
$body.append(globalActions);
|
134
126
|
});
|
135
|
-
}
|
127
|
+
};
|
136
128
|
|
137
129
|
|
138
130
|
/**
|
@@ -141,24 +133,32 @@ Cedar.Application.prototype.showGlobalActions = function() {
|
|
141
133
|
* responsible for determining if we're in edit mode
|
142
134
|
*/
|
143
135
|
Cedar.Auth = function() {
|
144
|
-
|
136
|
+
return;
|
137
|
+
};
|
138
|
+
|
145
139
|
Cedar.Auth.prototype.isEditMode = function() {
|
146
140
|
return this.isEditUrl();
|
147
|
-
}
|
141
|
+
};
|
142
|
+
|
148
143
|
Cedar.Auth.prototype.isEditUrl = function() {
|
149
144
|
var sPageURL = window.location.search.substring(1);
|
150
145
|
var sURLVariables = sPageURL.split('&');
|
151
|
-
|
152
|
-
|
146
|
+
var i = 0;
|
147
|
+
while (i < sURLVariables.length) {
|
148
|
+
if (sURLVariables[i] === 'cdrlogin') {
|
153
149
|
return true;
|
154
150
|
}
|
151
|
+
i++;
|
155
152
|
}
|
156
153
|
return false;
|
157
|
-
}
|
154
|
+
};
|
155
|
+
|
158
156
|
Cedar.Auth.prototype.getLogOffURL = function() {
|
159
157
|
return this.removeURLParameter(window.location.href, 'cdrlogin');
|
160
|
-
}
|
161
|
-
|
158
|
+
};
|
159
|
+
|
160
|
+
// adapted from stackoverflow:
|
161
|
+
// http://stackoverflow.com/questions/1634748/how-can-i-delete-a-query-string-parameter-in-javascript
|
162
162
|
Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
|
163
163
|
var splitUrl = url.split('#');
|
164
164
|
var serverUrl = splitUrl[0];
|
@@ -166,7 +166,7 @@ Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
|
|
166
166
|
if (clientUrl) {
|
167
167
|
clientUrl = '#' + clientUrl;
|
168
168
|
}
|
169
|
-
//prefer to use l.search if you have a location/link object
|
169
|
+
// prefer to use l.search if you have a location/link object
|
170
170
|
var splitServerUrl= serverUrl.split('?');
|
171
171
|
if (splitServerUrl.length>=2) {
|
172
172
|
|
@@ -174,11 +174,13 @@ Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
|
|
174
174
|
var pars = splitServerUrl[1].split(/[&;]/g);
|
175
175
|
|
176
176
|
//reverse iteration as may be destructive
|
177
|
-
|
178
|
-
|
177
|
+
var i = pars.length - 1;
|
178
|
+
while (i >= 0) {
|
179
|
+
// idiom for string.startsWith
|
179
180
|
if (pars[i].lastIndexOf(prefix, 0) !== -1) {
|
180
181
|
pars.splice(i, 1);
|
181
182
|
}
|
183
|
+
i--;
|
182
184
|
}
|
183
185
|
|
184
186
|
var updatedServerUrl= splitServerUrl[0];
|
@@ -189,7 +191,7 @@ Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
|
|
189
191
|
} else {
|
190
192
|
return url;
|
191
193
|
}
|
192
|
-
}
|
194
|
+
};
|
193
195
|
|
194
196
|
|
195
197
|
/**
|
@@ -203,12 +205,19 @@ Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
|
|
203
205
|
Cedar.Store = function() {
|
204
206
|
this.loaded = false;
|
205
207
|
|
208
|
+
this.cache = window.hasOwnProperty('localStorage') ? window.localStorage : {};
|
209
|
+
|
210
|
+
if (Cedar.config.fetch) {
|
211
|
+
this.refresh();
|
212
|
+
}
|
213
|
+
|
206
214
|
try {
|
207
|
-
return
|
215
|
+
return window.hasOwnProperty('localStorage');
|
208
216
|
} catch (e) {
|
209
217
|
return false;
|
210
218
|
}
|
211
|
-
}
|
219
|
+
};
|
220
|
+
|
212
221
|
/**
|
213
222
|
* store a single json item by key
|
214
223
|
*
|
@@ -216,95 +225,92 @@ Cedar.Store = function() {
|
|
216
225
|
* @param <json> 'item'
|
217
226
|
*/
|
218
227
|
Cedar.Store.prototype.put = function ( key, item ) {
|
219
|
-
|
220
|
-
}
|
221
|
-
/**
|
222
|
-
* get a single item based on id (key)
|
223
|
-
* if the item isn't in the local store, then get it from the server
|
224
|
-
*
|
225
|
-
* @param <Cedar> 'object'
|
226
|
-
* @param <string> 'key'
|
227
|
-
*/
|
228
|
-
Cedar.Store.prototype.get = function ( object, key ) {
|
229
|
-
if ( object.apiGet() === null ) {
|
230
|
-
throw 'Cedar Error: must provide api "get" path';
|
231
|
-
}
|
228
|
+
this.cache[key] = JSON.stringify(item);
|
229
|
+
};
|
232
230
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
231
|
+
// Return local content immediately if possible. Otherwise return deferred remote content
|
232
|
+
Cedar.Store.prototype.get = function(key) {
|
233
|
+
var cachedDeferred = this.cachedDeferred(key);
|
234
|
+
var remoteDeferred = this.remoteDeferred(key);
|
237
235
|
|
236
|
+
if (Cedar.config.wait || !this.cache[key]) {
|
237
|
+
Cedar.debug('checking remote: ' + key);
|
238
|
+
return remoteDeferred;
|
238
239
|
} else {
|
239
|
-
Cedar.debug(
|
240
|
-
return
|
241
|
-
Cedar.debug('get from server: ' + key);
|
242
|
-
Cedar.store.put(key, json);
|
243
|
-
});
|
244
|
-
}
|
245
|
-
}
|
246
|
-
/**
|
247
|
-
* fetch records from the server if necessary
|
248
|
-
*
|
249
|
-
* @param options <Array>
|
250
|
-
* - filter:<string> return only objects which match object IDs containing the string
|
251
|
-
* - path:<string> provide an api path other than the default (content entry query)
|
252
|
-
* - clear:<bool> clear local storage first
|
253
|
-
*/
|
254
|
-
Cedar.Store.prototype.fetch = function ( options ) {
|
255
|
-
var apiPath = '/queries/contententries/';
|
256
|
-
var queryParams = {};
|
257
|
-
|
258
|
-
if ( typeof options !== 'undefined' && typeof options.path !== 'undefined' ) {
|
259
|
-
apiPath = options.path;
|
260
|
-
}
|
261
|
-
if ( typeof options !== 'undefined' && typeof options.filter !== 'undefined' ) {
|
262
|
-
queryParams['guidfilter'] = options.filter;
|
263
|
-
}
|
264
|
-
if ( typeof options !== 'undefined' && typeof options.clear !== 'undefined' && options.clear) {
|
265
|
-
this.clear();
|
240
|
+
Cedar.debug('get from cache: ' + key);
|
241
|
+
return cachedDeferred;
|
266
242
|
}
|
243
|
+
};
|
267
244
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
if (Cedar.store.loaded) {
|
245
|
+
// Deferred object containing local content
|
246
|
+
Cedar.Store.prototype.cachedDeferred = function(key) {
|
247
|
+
return $.Deferred().resolve(this.cache[key]);
|
248
|
+
};
|
273
249
|
|
274
|
-
|
275
|
-
|
250
|
+
// Refresh local storage if needed and then return content
|
251
|
+
Cedar.Store.prototype.remoteDeferred = function(key) {
|
252
|
+
return this.refresh().then(function() {
|
253
|
+
return this.cachedDeferred(key);
|
254
|
+
}.bind(this));
|
255
|
+
};
|
276
256
|
|
257
|
+
// Check content version and update if needed
|
258
|
+
Cedar.Store.prototype.refresh = function() {
|
259
|
+
return this.checkVersion().then(function() {
|
260
|
+
if (this.loaded) {
|
261
|
+
return $.Deferred().resolve();
|
277
262
|
} else {
|
278
|
-
|
279
|
-
Cedar.debug("loaded: " + Cedar.store.loaded);
|
280
|
-
return $.getJSON(Cedar.config.api + apiPath, queryParams ).done( function(json) {
|
281
|
-
$.each(json, function (key, val) {
|
282
|
-
if ( typeof val.id !== 'undefined' && typeof val.settings.content !== 'undefined') {
|
283
|
-
Cedar.store.put(val.id, val);
|
284
|
-
Cedar.debug("storing: " + val.id);
|
285
|
-
}
|
286
|
-
});
|
287
|
-
Cedar.debug("setting loaded to true");
|
288
|
-
Cedar.store.loaded = true;
|
289
|
-
Cedar.$.trigger("content:loaded");
|
290
|
-
});
|
263
|
+
return this.getRemote();
|
291
264
|
}
|
265
|
+
}.bind(this));
|
266
|
+
};
|
267
|
+
|
268
|
+
// Get content objects from server and save to local storage
|
269
|
+
Cedar.Store.prototype.getRemote = function(options) {
|
270
|
+
var defaultOptions = {
|
271
|
+
path: '/queries/contententries/'
|
272
|
+
};
|
273
|
+
options = $.extend({}, defaultOptions, options);
|
274
|
+
var defaultParams = {};
|
275
|
+
var params = $.extend({}, defaultParams, {
|
276
|
+
guidfilter: options.filter
|
277
|
+
});
|
292
278
|
|
279
|
+
return this.lockedRequest({
|
280
|
+
path: options.path,
|
281
|
+
params: params,
|
282
|
+
success: function(response) {
|
283
|
+
$.each(response, function (index, value) {
|
284
|
+
if (value.hasOwnProperty('id') && value.settings.hasOwnProperty('content')) {
|
285
|
+
this.put(value.id, value);
|
286
|
+
Cedar.debug("storing: " + value.id);
|
287
|
+
}
|
288
|
+
}.bind(this));
|
289
|
+
Cedar.debug("local storage was updated");
|
290
|
+
this.loaded = true;
|
291
|
+
Cedar.events.trigger("content:loaded");
|
292
|
+
}.bind(this)
|
293
293
|
});
|
294
|
-
}
|
294
|
+
};
|
295
|
+
|
295
296
|
/**
|
296
297
|
* clear the local storage or remove a single locally store item by key
|
297
298
|
*
|
298
299
|
* @param {ID} key
|
299
300
|
*/
|
300
|
-
Cedar.Store.prototype.clear = function(
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
}
|
301
|
+
Cedar.Store.prototype.clear = function(key) {
|
302
|
+
if (key === undefined) {
|
303
|
+
if (window.hasOwnProperty('localStorage')) {
|
304
|
+
this.cache.clear();
|
305
|
+
} else {
|
306
|
+
this.cache = {};
|
307
|
+
}
|
308
|
+
}
|
309
|
+
else {
|
310
|
+
delete this.cache[key];
|
311
|
+
}
|
312
|
+
};
|
313
|
+
|
308
314
|
/**
|
309
315
|
* set the locally stored data version number
|
310
316
|
*
|
@@ -312,37 +318,55 @@ Cedar.Store.prototype.clear = function( key ) {
|
|
312
318
|
*/
|
313
319
|
Cedar.Store.prototype.setVersion = function(id) {
|
314
320
|
Cedar.debug("updating to version #" + id);
|
315
|
-
|
316
|
-
}
|
321
|
+
this.cache["___CEDAR__DATA__FINGERPRINT___"] = id;
|
322
|
+
};
|
323
|
+
|
317
324
|
/**
|
318
325
|
* return the currently stored data version number
|
319
326
|
*
|
320
327
|
* @return <string> data version number
|
321
328
|
*/
|
322
329
|
Cedar.Store.prototype.getVersion = function() {
|
323
|
-
return
|
324
|
-
}
|
330
|
+
return this.cache["___CEDAR__DATA__FINGERPRINT___"];
|
331
|
+
};
|
332
|
+
|
325
333
|
/**
|
326
334
|
* Query the server for the latest data version number
|
327
335
|
*
|
328
336
|
* @return <Deferred>
|
329
337
|
*/
|
330
|
-
Cedar.Store.prototype.
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
338
|
+
Cedar.Store.prototype.checkVersion = function() {
|
339
|
+
return this.lockedRequest({
|
340
|
+
path: '/queries/status',
|
341
|
+
success: function(response) {
|
342
|
+
Cedar.debug("checking version #" + this.getVersion());
|
343
|
+
|
344
|
+
// response.settings.version is being returned as an array and must be converted
|
345
|
+
if ( this.getVersion() !== response.settings.version.toString() ) {
|
346
|
+
Cedar.debug('setting version: ' + response.settings.version);
|
347
|
+
this.loaded = false;
|
348
|
+
this.setVersion(response.settings.version);
|
349
|
+
} else {
|
350
|
+
Cedar.debug("version is up to date");
|
351
|
+
this.loaded = true;
|
352
|
+
Cedar.events.trigger("content:loaded");
|
353
|
+
}
|
354
|
+
}.bind(this)
|
344
355
|
});
|
345
|
-
}
|
356
|
+
};
|
357
|
+
|
358
|
+
// Returns an already resolving getJSON request if it matches
|
359
|
+
Cedar.Store.prototype.lockedRequest = function(options) {
|
360
|
+
options = options || {};
|
361
|
+
this.requestCache || (this.requestCache = {});
|
362
|
+
|
363
|
+
var requestKey = JSON.stringify({path: options.path, params: options.params});
|
364
|
+
|
365
|
+
return this.requestCache[requestKey] || (this.requestCache[requestKey] = $
|
366
|
+
.getJSON(Cedar.config.api + options.path, options.params).then(function(response){
|
367
|
+
options.success(response);
|
368
|
+
}.bind(this)));
|
369
|
+
};
|
346
370
|
|
347
371
|
/**
|
348
372
|
* Cedar.ContentEntry
|
@@ -365,7 +389,7 @@ Cedar.ContentEntry = function(options) {
|
|
365
389
|
this.cedarId = this.options.cedarId;
|
366
390
|
this.el = this.options.el;
|
367
391
|
this.$el = $(this.el);
|
368
|
-
}
|
392
|
+
};
|
369
393
|
|
370
394
|
Cedar.ContentEntry.prototype.apiGet = function() {
|
371
395
|
return '/objects/contententries/';
|
@@ -383,39 +407,26 @@ Cedar.ContentEntry.prototype.apiList = function() {
|
|
383
407
|
return 'guidlist';
|
384
408
|
};
|
385
409
|
|
386
|
-
Cedar.ContentEntry.prototype.hasLocalContent = function() {
|
387
|
-
if (typeof this.localContentExists === "undefined") {
|
388
|
-
var content = localStorage[this.cedarId];
|
389
|
-
this.localContentExists = false;
|
390
|
-
if (typeof content !== "undefined") {
|
391
|
-
var json = JSON.parse(content);
|
392
|
-
if (typeof json.id !== "undefined") {
|
393
|
-
this.localContentExists = true;
|
394
|
-
}
|
395
|
-
}
|
396
|
-
}
|
397
|
-
return this.localContentExists;
|
398
|
-
}
|
399
|
-
|
400
410
|
/**
|
401
411
|
* parse the json for content and set this object's content
|
402
412
|
*
|
403
413
|
* @param <json>
|
404
414
|
*/
|
405
415
|
Cedar.ContentEntry.prototype.setContent = function(data) {
|
406
|
-
if (typeof data === 'undefined') return;
|
407
416
|
if (typeof data === 'string') {
|
408
417
|
data = JSON.parse(data);
|
409
418
|
}
|
410
|
-
|
419
|
+
|
420
|
+
if (!data || data.code === 'UNKNOWN_ID'){
|
411
421
|
this.content = '';
|
412
|
-
} else if (
|
422
|
+
} else if (data.settings.hasOwnProperty('content')) {
|
413
423
|
this.content = data.settings.content;
|
414
424
|
} else {
|
415
425
|
this.content = '';
|
416
426
|
Cedar.debug('Cedar Error: Unable to parse json');
|
417
427
|
}
|
418
|
-
}
|
428
|
+
};
|
429
|
+
|
419
430
|
/**
|
420
431
|
* return the object's content - takes into account edit mode styling
|
421
432
|
*
|
@@ -428,7 +439,8 @@ Cedar.ContentEntry.prototype.getContent = function(){
|
|
428
439
|
else {
|
429
440
|
return this.content;
|
430
441
|
}
|
431
|
-
}
|
442
|
+
};
|
443
|
+
|
432
444
|
/**
|
433
445
|
* is this a content entry json structure?
|
434
446
|
*
|
@@ -436,44 +448,48 @@ Cedar.ContentEntry.prototype.getContent = function(){
|
|
436
448
|
* @return <bool>
|
437
449
|
*/
|
438
450
|
Cedar.ContentEntry.prototype.isContentEntry = function (json) {
|
439
|
-
if (
|
451
|
+
if (json === undefined) {
|
440
452
|
return false;
|
441
453
|
}
|
442
|
-
if (
|
454
|
+
if (json.hasOwnProperty('settings') && json.settings.hasOwnProperty('content')) {
|
443
455
|
return false;
|
444
456
|
}
|
445
457
|
|
446
458
|
return true;
|
447
|
-
}
|
459
|
+
};
|
460
|
+
|
448
461
|
/**
|
449
462
|
* @return <json>
|
450
463
|
*/
|
451
464
|
Cedar.ContentEntry.prototype.toJSON = function(){
|
452
465
|
return {
|
453
466
|
content: this.content
|
454
|
-
}
|
467
|
+
};
|
455
468
|
};
|
469
|
+
|
456
470
|
/**
|
457
471
|
* fill self or provided element with content
|
458
472
|
*
|
459
473
|
* @param <element> optional
|
460
474
|
*/
|
461
475
|
Cedar.ContentEntry.prototype.fill = function(element) {
|
462
|
-
if (
|
476
|
+
if (element !== undefined) {
|
463
477
|
$(element).html(this.getContent());
|
464
|
-
} else if (
|
478
|
+
} else if (this.$el instanceof jQuery) {
|
465
479
|
this.$el.html(this.getContent());
|
466
480
|
}
|
467
|
-
}
|
481
|
+
};
|
482
|
+
|
468
483
|
/**
|
469
484
|
* check store for this object's content
|
470
485
|
*/
|
471
486
|
Cedar.ContentEntry.prototype.retrieve = function() {
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
}
|
487
|
+
return Cedar.store.get(this.cedarId).then(function(response) {
|
488
|
+
this.setContent(response);
|
489
|
+
return this;
|
490
|
+
}.bind(this));
|
491
|
+
};
|
492
|
+
|
477
493
|
/**
|
478
494
|
* retrive and fill the associated element
|
479
495
|
*/
|
@@ -481,7 +497,7 @@ Cedar.ContentEntry.prototype.render = function() {
|
|
481
497
|
this.retrieve().done(function() {
|
482
498
|
this.fill();
|
483
499
|
}.bind(this));
|
484
|
-
}
|
500
|
+
};
|
485
501
|
|
486
502
|
/**
|
487
503
|
* provides styling for edit box
|
@@ -500,7 +516,8 @@ Cedar.ContentEntry.prototype.getEditOpen = function() {
|
|
500
516
|
block += '<i class="cedar-cms-icon cedar-cms-icon-right cedar-cms-icon-edit"></i></a>';
|
501
517
|
block += '</span>';
|
502
518
|
return block;
|
503
|
-
}
|
519
|
+
};
|
520
|
+
|
504
521
|
Cedar.ContentEntry.prototype.getEditClose = function(){
|
505
522
|
return '</span>';
|
506
|
-
}
|
523
|
+
};
|
File without changes
|
data/lib/cedar/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.5.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-05-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,7 +51,7 @@ files:
|
|
51
51
|
- lib/assets/javascripts/cedar.handlebars.js
|
52
52
|
- lib/assets/javascripts/cedar.js
|
53
53
|
- lib/assets/stylesheets/cedar.scss
|
54
|
-
- lib/assets/stylesheets/cedar_source.
|
54
|
+
- lib/assets/stylesheets/cedar_source.scss
|
55
55
|
- lib/cedar.rb
|
56
56
|
- lib/cedar/version.rb
|
57
57
|
homepage: http://plyinteractive.com
|