cedar 0.1.6.pre → 0.1.7.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 +2 -1
- data/lib/assets/javascripts/cedar.handlebars.js +12 -12
- data/lib/assets/javascripts/cedar.js +120 -77
- data/lib/cedar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6463db6fe87cf5fa52432c57f921967b4c392114
|
4
|
+
data.tar.gz: 2f3c7a6016e9c5e0e9488c8540dc690b7db1eda2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2c3a7c4f125b200b2abf5472762b218d0fe952d7e76be65f6176b82652a526daf58681db3ce92500110f97e75934dc00915c142ac765d207b293202aae2ea20
|
7
|
+
data.tar.gz: 96d2f9995ab6592b1f6c5932e4df18c763cc07fa5dc7ab18fce711f6849be533cebd824e4cdbae6b3783c7a743c826379248d945297663ec300c18d19e724ac5
|
data/README.md
CHANGED
@@ -23,9 +23,10 @@ Or install it yourself as:
|
|
23
23
|
To retrieve all available content and save it to `localStorage`, use the following function (returns a promise)
|
24
24
|
|
25
25
|
```javascript
|
26
|
-
Cedar.store.
|
26
|
+
Cedar.store.fetch();
|
27
27
|
```
|
28
28
|
|
29
|
+
|
29
30
|
### Handlebars
|
30
31
|
|
31
32
|
To add Cedar-managed content to your Handlebars templates, use the following helper:
|
@@ -40,18 +40,13 @@ Handlebars.registerHelper('cedar', function(options) {
|
|
40
40
|
tagName = options.hash.tagName || "div";
|
41
41
|
}
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
var outputEl = document.createElement(tagName);
|
44
|
+
outputEl.id = "cedar-js-" + hashCode(options.hash.id);
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
var domEl = document.getElementById(options.el.id);
|
49
|
-
if (domEl === null) {
|
50
|
-
domEl = options.el;
|
51
|
-
}
|
46
|
+
var output = '';
|
52
47
|
|
48
|
+
new Cedar.ContentEntry({ cedarId: options.hash.id }).retrieve().then(function(contentEntry){
|
53
49
|
if (blockHelperStyle()) {
|
54
|
-
var output = '';
|
55
50
|
if (Cedar.auth.isEditMode()) {
|
56
51
|
output += contentEntry.getEditOpen();
|
57
52
|
}
|
@@ -59,11 +54,16 @@ Handlebars.registerHelper('cedar', function(options) {
|
|
59
54
|
if (Cedar.auth.isEditMode()) {
|
60
55
|
output += contentEntry.getEditClose();
|
61
56
|
}
|
62
|
-
domEl.innerHTML = output;
|
63
57
|
} else {
|
64
|
-
|
58
|
+
output = contentEntry.getContent();
|
59
|
+
}
|
60
|
+
|
61
|
+
// If rendered element exists than insert the content
|
62
|
+
var renderedEl = document.getElementById(outputEl.id);
|
63
|
+
if (renderedEl !== null) {
|
64
|
+
renderedEl.innerHTML = output;
|
65
65
|
}
|
66
66
|
});
|
67
67
|
|
68
|
-
return new Handlebars.SafeString(
|
68
|
+
return new Handlebars.SafeString(output || outputEl.outerHTML);
|
69
69
|
});
|
@@ -17,6 +17,10 @@ var Cedar = {
|
|
17
17
|
* Cedar.Init
|
18
18
|
*
|
19
19
|
* take care of global initializations
|
20
|
+
*
|
21
|
+
* @param <Array> options
|
22
|
+
* - server : 'test.cdr.plyinc.com' - *required
|
23
|
+
* - debug : true | false
|
20
24
|
*/
|
21
25
|
Cedar.Init = function(options) {
|
22
26
|
if ( Cedar.initialized ) {
|
@@ -61,17 +65,22 @@ Cedar.Init = function(options) {
|
|
61
65
|
|
62
66
|
Cedar.initialized = true;
|
63
67
|
}
|
64
|
-
|
68
|
+
/**
|
69
|
+
* display message to console if Cedar.debug = true
|
70
|
+
*
|
71
|
+
* @param <string> message
|
72
|
+
*/
|
65
73
|
Cedar.debug = function(msg) {
|
66
74
|
if (Cedar.config.debug) {
|
67
75
|
console.log(msg);
|
68
76
|
}
|
69
77
|
}
|
70
78
|
|
79
|
+
|
71
80
|
/**
|
72
81
|
* Cedar.Auth
|
73
82
|
*
|
74
|
-
* responsible for determining if we're
|
83
|
+
* responsible for determining if we're in edit mode
|
75
84
|
*/
|
76
85
|
Cedar.Auth = function() {
|
77
86
|
}
|
@@ -91,7 +100,6 @@ Cedar.Auth.prototype.isEditUrl = function() {
|
|
91
100
|
Cedar.Auth.prototype.getLogOffURL = function() {
|
92
101
|
return this.removeURLParameter(window.location.href, 'cdrlogin');
|
93
102
|
}
|
94
|
-
|
95
103
|
// adapted from stackoverflow: http://stackoverflow.com/questions/1634748/how-can-i-delete-a-query-string-parameter-in-javascript
|
96
104
|
Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
|
97
105
|
var splitUrl = url.split('#');
|
@@ -133,14 +141,19 @@ Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
|
|
133
141
|
*/
|
134
142
|
Cedar.Store = function() {
|
135
143
|
this.loaded = false;
|
136
|
-
|
144
|
+
|
137
145
|
try {
|
138
146
|
return 'localStorage' in window && window['localStorage'] !== null;
|
139
147
|
} catch (e) {
|
140
148
|
return false;
|
141
149
|
}
|
142
150
|
}
|
143
|
-
|
151
|
+
/**
|
152
|
+
* store a single json item by key
|
153
|
+
*
|
154
|
+
* @param <string> 'key'
|
155
|
+
* @param <json> 'item'
|
156
|
+
*/
|
144
157
|
Cedar.Store.prototype.put = function ( key, item ) {
|
145
158
|
localStorage[key] = JSON.stringify(item);
|
146
159
|
}
|
@@ -148,99 +161,110 @@ Cedar.Store.prototype.put = function ( key, item ) {
|
|
148
161
|
* get a single item based on id (key)
|
149
162
|
* if the item isn't in the local store, then get it from the server
|
150
163
|
*
|
151
|
-
* @param Cedar 'object'
|
152
|
-
* @param string 'key'
|
164
|
+
* @param <Cedar> 'object'
|
165
|
+
* @param <string> 'key'
|
153
166
|
*/
|
154
167
|
Cedar.Store.prototype.get = function ( object, key ) {
|
155
168
|
if ( object.apiGet() === null ) {
|
156
169
|
throw 'Cedar Error: must provide api "get" path';
|
157
170
|
}
|
158
171
|
if (typeof localStorage[key] !== "undefined") {
|
159
|
-
Cedar.debug('
|
172
|
+
Cedar.debug('get from cache: ' + key);
|
160
173
|
return $.Deferred().resolve(localStorage[key]);
|
161
174
|
} else {
|
162
|
-
Cedar.debug('
|
175
|
+
Cedar.debug('checking server...');
|
163
176
|
return $.getJSON(Cedar.config.api + object.apiGet() + key, function(json) {
|
164
|
-
Cedar.debug('
|
177
|
+
Cedar.debug('get from server: ' + key);
|
165
178
|
Cedar.store.put(key, json);
|
166
179
|
});
|
167
180
|
}
|
168
181
|
}
|
169
|
-
|
170
182
|
/**
|
171
|
-
*
|
172
|
-
*
|
173
|
-
* @param string 'path'
|
174
|
-
* @param string 'param'
|
175
|
-
* @param string 'value'
|
183
|
+
* fetch records from the server if necessary
|
176
184
|
*
|
185
|
+
* @param options <Array>
|
186
|
+
* - filter:<string> return only objects which match object IDs containing the string
|
187
|
+
* - path:<string> provide an api path other than the default (content entry query)
|
188
|
+
* - clear:<bool> clear local storage first
|
177
189
|
*/
|
178
|
-
Cedar.Store.prototype.
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
190
|
+
Cedar.Store.prototype.fetch = function ( options ) {
|
191
|
+
var apiPath = '/queries/contententries/';
|
192
|
+
var queryParams = {};
|
193
|
+
|
194
|
+
if ( typeof options !== 'undefined' && typeof options.path !== 'undefined' ) {
|
195
|
+
apiPath = options.path;
|
196
|
+
}
|
197
|
+
if ( typeof options !== 'undefined' && typeof options.filter !== 'undefined' ) {
|
198
|
+
queryParams['guidfilter'] = options.filter;
|
199
|
+
}
|
200
|
+
if ( typeof options !== 'undefined' && typeof options.clear !== 'undefined' && options.clear) {
|
201
|
+
this.clear();
|
202
|
+
}
|
187
203
|
|
188
|
-
/**
|
189
|
-
* get all objects and store locally
|
190
|
-
* TODO: (currently hardcoded to content entries - should be avail to any type in future)
|
191
|
-
*/
|
192
|
-
Cedar.Store.prototype.getAll = function () {
|
193
|
-
Cedar.debug("loaded: " + Cedar.store.loaded);
|
194
204
|
return $.when(Cedar.store.checkData()).then( function() {
|
195
205
|
|
196
|
-
Cedar.debug("loaded: " + Cedar.store.loaded);
|
197
206
|
if (Cedar.store.loaded) {
|
198
207
|
|
199
|
-
Cedar.debug("
|
208
|
+
Cedar.debug("loaded: " + Cedar.store.loaded);
|
200
209
|
return $.Deferred().resolve({});
|
201
210
|
|
202
211
|
} else {
|
203
212
|
|
204
|
-
Cedar.debug("
|
205
|
-
return $.getJSON(Cedar.config.api +
|
206
|
-
Cedar.debug("Got new stuff from the server");
|
213
|
+
Cedar.debug("loaded: " + Cedar.store.loaded);
|
214
|
+
return $.getJSON(Cedar.config.api + apiPath, queryParams ).done( function(json) {
|
207
215
|
$.each(json, function (key, val) {
|
208
|
-
|
209
|
-
|
216
|
+
if ( typeof val.id !== 'undefined' && typeof val.settings.content !== 'undefined') {
|
217
|
+
Cedar.store.put(val.id, val);
|
218
|
+
Cedar.debug("storing: " + val.id);
|
219
|
+
}
|
210
220
|
});
|
211
221
|
Cedar.store.loaded = true;
|
212
222
|
});
|
213
|
-
|
214
223
|
}
|
215
224
|
|
216
225
|
});
|
217
226
|
}
|
218
|
-
|
219
227
|
/**
|
220
|
-
* remove a single locally store item by key
|
228
|
+
* clear the local storage or remove a single locally store item by key
|
221
229
|
*
|
222
|
-
* @param ID key
|
230
|
+
* @param {ID} key
|
223
231
|
*/
|
224
|
-
Cedar.Store.prototype.clear = function(key) {
|
225
|
-
|
232
|
+
Cedar.Store.prototype.clear = function( key ) {
|
233
|
+
if ( typeof key === 'undefined' ) {
|
234
|
+
localStorage.clear();
|
235
|
+
}
|
236
|
+
else {
|
237
|
+
localStorage.removeItem(key);
|
238
|
+
}
|
226
239
|
}
|
227
|
-
|
240
|
+
/**
|
241
|
+
* set the locally stored data version number
|
242
|
+
*
|
243
|
+
* @return <string> data version number
|
244
|
+
*/
|
228
245
|
Cedar.Store.prototype.setVersion = function(id) {
|
229
246
|
Cedar.debug("updating to version #" + id);
|
230
247
|
localStorage["___CEDAR__DATA__FINGERPRINT___"] = id;
|
231
248
|
}
|
249
|
+
/**
|
250
|
+
* return the currently stored data version number
|
251
|
+
*
|
252
|
+
* @return <string> data version number
|
253
|
+
*/
|
232
254
|
Cedar.Store.prototype.getVersion = function() {
|
233
255
|
return localStorage["___CEDAR__DATA__FINGERPRINT___"];
|
234
256
|
}
|
235
257
|
/**
|
236
|
-
* Query the server for the latest version number
|
258
|
+
* Query the server for the latest data version number
|
259
|
+
*
|
260
|
+
* @return <Deferred>
|
237
261
|
*/
|
238
262
|
Cedar.Store.prototype.checkData = function() {
|
239
263
|
Cedar.debug("checking version #" + Cedar.store.getVersion());
|
240
264
|
return $.getJSON(Cedar.config.api + '/queries/status').done( function(json) {
|
241
265
|
|
242
266
|
if ( Cedar.store.getVersion() != json.settings.version ) {
|
243
|
-
Cedar.debug(
|
267
|
+
Cedar.debug('setting version: ' + json.settings.version);
|
244
268
|
Cedar.store.loaded = false;
|
245
269
|
Cedar.store.setVersion(json.settings.version);
|
246
270
|
}
|
@@ -255,8 +279,6 @@ Cedar.Store.prototype.checkData = function() {
|
|
255
279
|
*
|
256
280
|
* basic content block class
|
257
281
|
*
|
258
|
-
*
|
259
|
-
*
|
260
282
|
* options:
|
261
283
|
*
|
262
284
|
* {
|
@@ -275,31 +297,30 @@ Cedar.ContentEntry = function(options) {
|
|
275
297
|
this.$el = $(this.el);
|
276
298
|
}
|
277
299
|
|
278
|
-
Cedar.ContentEntry.query = function(thing) {
|
279
|
-
Cedar.store.query( "/queries/contententries/", "guidfilter", thing );
|
280
|
-
}
|
281
|
-
|
282
300
|
Cedar.ContentEntry.prototype.apiGet = function() {
|
283
|
-
return
|
301
|
+
return '/objects/contententries/';
|
284
302
|
};
|
285
303
|
|
286
304
|
Cedar.ContentEntry.prototype.apiQuery = function() {
|
287
|
-
return
|
305
|
+
return '/queries/contententries/';
|
288
306
|
};
|
289
307
|
|
290
308
|
Cedar.ContentEntry.prototype.apiFilter = function() {
|
291
|
-
return
|
309
|
+
return 'guidfilter';
|
292
310
|
};
|
293
311
|
|
294
312
|
Cedar.ContentEntry.prototype.apiList = function() {
|
295
|
-
return
|
313
|
+
return 'guidlist';
|
296
314
|
};
|
297
315
|
|
298
|
-
|
299
|
-
|
316
|
+
/**
|
317
|
+
* parse the json for content and set this object's content
|
318
|
+
*
|
319
|
+
* @param <json>
|
320
|
+
*/
|
300
321
|
Cedar.ContentEntry.prototype.setContent = function(json) {
|
301
|
-
if (typeof json ===
|
302
|
-
if (json.code ==
|
322
|
+
if (typeof json === 'undefined') return;
|
323
|
+
if (json.code == 'UNKNOWN_ID'){
|
303
324
|
this.content = ' '; // if an element is new, fill with blank space to allow edit box to display
|
304
325
|
}
|
305
326
|
else if (typeof json.settings.content !== 'undefined') {
|
@@ -310,8 +331,11 @@ Cedar.ContentEntry.prototype.setContent = function(json) {
|
|
310
331
|
Cedar.debug('Cedar Error: Unable to parse json');
|
311
332
|
}
|
312
333
|
}
|
313
|
-
|
314
|
-
|
334
|
+
/**
|
335
|
+
* return the object's content - takes into account edit mode styling
|
336
|
+
*
|
337
|
+
* @return <HTML>
|
338
|
+
*/
|
315
339
|
Cedar.ContentEntry.prototype.getContent = function(){
|
316
340
|
if (Cedar.auth.isEditMode()) {
|
317
341
|
return this.getEditOpen() + this.content + this.getEditClose();
|
@@ -320,14 +344,35 @@ Cedar.ContentEntry.prototype.getContent = function(){
|
|
320
344
|
return this.content;
|
321
345
|
}
|
322
346
|
}
|
347
|
+
/**
|
348
|
+
* is this a content entry json structure?
|
349
|
+
*
|
350
|
+
* @param <json>
|
351
|
+
* @return <bool>
|
352
|
+
*/
|
353
|
+
Cedar.ContentEntry.prototype.isContentEntry = function (json) {
|
354
|
+
if (typeof json === 'undefined') {
|
355
|
+
return false;
|
356
|
+
}
|
357
|
+
if (typeof json.settings === 'undefined' && typeof json.settings.content === 'undefined') {
|
358
|
+
return false;
|
359
|
+
}
|
323
360
|
|
361
|
+
return true;
|
362
|
+
}
|
363
|
+
/**
|
364
|
+
* @return <json>
|
365
|
+
*/
|
324
366
|
Cedar.ContentEntry.prototype.toJSON = function(){
|
325
367
|
return {
|
326
368
|
content: this.content
|
327
369
|
}
|
328
370
|
};
|
329
|
-
|
330
|
-
|
371
|
+
/**
|
372
|
+
* fill self or provided element with content
|
373
|
+
*
|
374
|
+
* @param <element> optional
|
375
|
+
*/
|
331
376
|
Cedar.ContentEntry.prototype.fill = function(element) {
|
332
377
|
if (typeof element !== 'undefined') {
|
333
378
|
$(element).html(this.getContent());
|
@@ -336,31 +381,29 @@ Cedar.ContentEntry.prototype.fill = function(element) {
|
|
336
381
|
this.$el.html(this.getContent());
|
337
382
|
}
|
338
383
|
}
|
339
|
-
|
340
|
-
|
384
|
+
/**
|
385
|
+
* check store for this object's content
|
386
|
+
*/
|
341
387
|
Cedar.ContentEntry.prototype.retrieve = function() {
|
342
388
|
return Cedar.store.get(this, this.cedarId).then(function(response) {
|
343
|
-
if (typeof response ===
|
389
|
+
if (typeof response === 'string') {
|
344
390
|
response = JSON.parse(response);
|
345
391
|
}
|
346
392
|
this.setContent(response);
|
347
393
|
return this;
|
348
394
|
}.bind(this));
|
349
395
|
}
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
// return Cedar.store.query(filter, this);
|
354
|
-
//}
|
355
|
-
|
356
|
-
// fill the asssociated element with the retrieved content
|
396
|
+
/**
|
397
|
+
* retrive and fill the associated element
|
398
|
+
*/
|
357
399
|
Cedar.ContentEntry.prototype.render = function() {
|
358
400
|
this.retrieve().done(function() {
|
359
401
|
this.fill();
|
360
402
|
}.bind(this));
|
361
403
|
}
|
362
|
-
|
363
|
-
|
404
|
+
/**
|
405
|
+
* provides styling for edit box
|
406
|
+
*/
|
364
407
|
Cedar.ContentEntry.prototype.getEditOpen = function() {
|
365
408
|
var jsString = "if(event.stopPropagation){event.stopPropagation();}" +
|
366
409
|
"event.cancelBubble=true;" +
|
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.1.
|
4
|
+
version: 0.1.7.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-04-
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|