cedar 0.1.1.pre → 0.1.2.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/lib/assets/javascripts/cedar.handlebars.js +48 -0
- data/lib/assets/javascripts/cedar.js +106 -17
- data/lib/cedar/version.rb +1 -1
- data/pkg/cedar-0.1.1.pre.gem +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3988489729a5845dbe10d9de748a5dda45fecc1b
|
4
|
+
data.tar.gz: eb6c4a3546167231d00c5897af33684041594ca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35109e6090763faadbea1fb0f6f7ebf562ab79ccf2cf272f085b9c697e761aec545f1094857b84237376baea9062e1d99105390f8d737874da55dc2d2d1e4080
|
7
|
+
data.tar.gz: a875809c4d21d0a15d3329e4b5fea6714c1aa70795aa24a156171c99551da74ab85bf68099fdb8e29e94ae23e5021c77d1c2ed01f0492c9f8d65e689f7ed0fcf
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Handlebars.registerHelper('cedar', function(options) {
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
var hashCode = function(string) {
|
5
|
+
var hash = 0;
|
6
|
+
if (string.length == 0) return hash;
|
7
|
+
for (var i = 0; i < string.length; i++) {
|
8
|
+
var character = string.charCodeAt(i);
|
9
|
+
hash = ((hash << 5) - hash) + character;
|
10
|
+
hash = hash & hash; // Convert to 32bit integer
|
11
|
+
}
|
12
|
+
return hash;
|
13
|
+
};
|
14
|
+
|
15
|
+
var unescapeHtml = function(string) {
|
16
|
+
var MAP = {
|
17
|
+
'&': '&',
|
18
|
+
'<': '<',
|
19
|
+
'>': '>',
|
20
|
+
'"': '"',
|
21
|
+
''': "'",
|
22
|
+
''': "'"
|
23
|
+
};
|
24
|
+
|
25
|
+
return string.replace(/&#?\w+;/g, function(c) {
|
26
|
+
return MAP[c];
|
27
|
+
});
|
28
|
+
};
|
29
|
+
|
30
|
+
options.el = document.createElement("div");
|
31
|
+
options.el.id = "cedar-js-" + hashCode(options.hash.id);
|
32
|
+
|
33
|
+
new Cedar.ContentEntry({ cedarId: options.hash.id }).retrieve().then(function(contentEntry){
|
34
|
+
|
35
|
+
var domEl = document.getElementById(options.el.id);
|
36
|
+
if (domEl === null) {
|
37
|
+
domEl = options.el;
|
38
|
+
}
|
39
|
+
|
40
|
+
if (typeof options.fn === "undefined") {
|
41
|
+
domEl.innerHTML = contentEntry.getContent();
|
42
|
+
} else if (typeof options.fn === "function") {
|
43
|
+
domEl.innerHTML = unescapeHtml(options.fn(contentEntry.toJSON()));
|
44
|
+
}
|
45
|
+
});
|
46
|
+
|
47
|
+
return new Handlebars.SafeString(options.el.outerHTML);
|
48
|
+
});
|
@@ -34,7 +34,10 @@ Cedar.Init = function() {
|
|
34
34
|
$(document).ready(function() {
|
35
35
|
var $body = $('body');
|
36
36
|
var globalActions = '<div class="cedar-cms-global-actions">' +
|
37
|
-
|
37
|
+
'<a href="#" class="cedar-cms-global-action" onclick="window.location.reload();">' +
|
38
|
+
'<span class="cedar-cms-icon cedar-cms-icon-edit"></span> ' +
|
39
|
+
'<span class="cedar-cms-global-action-label">Refresh</span>' +
|
40
|
+
'</a><br>' +
|
38
41
|
'<a class="cedar-cms-global-action" href="' + Cedar.auth.getLogOffURL() + '">' +
|
39
42
|
'<span class="cedar-cms-icon cedar-cms-icon-edit"></span> ' +
|
40
43
|
'<span class="cedar-cms-global-action-label">Log Off Cedar</span>' +
|
@@ -107,35 +110,90 @@ Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
|
|
107
110
|
* Cedar.Store
|
108
111
|
*
|
109
112
|
* responsible for retrieving Cedar elements from server or local cache.
|
113
|
+
*
|
114
|
+
* different cedar types may use different api paths, therefore the paths
|
115
|
+
* are passed into some functions
|
110
116
|
*/
|
111
117
|
Cedar.Store = function() {
|
112
|
-
this.
|
118
|
+
this.loaded = false;
|
119
|
+
try {
|
120
|
+
return 'localStorage' in window && window['localStorage'] !== null;
|
121
|
+
} catch (e) {
|
122
|
+
return false;
|
123
|
+
}
|
113
124
|
}
|
114
125
|
|
115
126
|
Cedar.Store.prototype.put = function ( key, item ) {
|
116
|
-
|
127
|
+
localStorage[key] = JSON.stringify(item);
|
117
128
|
}
|
118
129
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
130
|
+
/**
|
131
|
+
* get a single item based on id (key)
|
132
|
+
* if the item isn't in the local store, then get it from the server
|
133
|
+
*
|
134
|
+
* @param Cedar 'object'
|
135
|
+
* @param string 'key'
|
136
|
+
*/
|
137
|
+
Cedar.Store.prototype.get = function ( object, key ) {
|
138
|
+
if ( object.apiGet() === null ) {
|
139
|
+
throw 'Cedar Error: must provide api "get" path';
|
140
|
+
}
|
123
141
|
|
124
|
-
if (typeof
|
125
|
-
|
142
|
+
if (typeof localStorage[key] !== "undefined") {
|
143
|
+
console.log('retrieved from cache');
|
144
|
+
return $.Deferred().resolve(localStorage[key]);
|
145
|
+
} else {
|
146
|
+
console.log('retrieved from server');
|
147
|
+
return $.getJSON(Cedar.config.api + object.apiGet() + key, function(json) {
|
126
148
|
this.put(key, json);
|
127
|
-
console.log('retrieved from server');
|
128
149
|
}.bind(this));
|
129
150
|
}
|
130
|
-
|
131
|
-
|
132
|
-
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* query the api and fill the local store with the results
|
155
|
+
*
|
156
|
+
* @param string 'path'
|
157
|
+
* @param string 'param'
|
158
|
+
* @param string 'value'
|
159
|
+
*
|
160
|
+
*/
|
161
|
+
Cedar.Store.prototype.query = function ( path, param, value ) {
|
162
|
+
|
163
|
+
jQuery.getJSON(Cedar.config.api + path + '?' + param + '=' + value ).done( function(json) {
|
164
|
+
$.each(json, function (key, val){
|
165
|
+
Cedar.store.put(key, val);
|
166
|
+
});
|
167
|
+
}.bind(this));
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* get all objects and store locally
|
173
|
+
* TODO: (currently hardcoded to content entries - should be avail to any type in future)
|
174
|
+
*/
|
175
|
+
Cedar.Store.prototype.getAll = function () {
|
176
|
+
|
177
|
+
if (this.loaded) {
|
178
|
+
return $.Deferred().resolve({});
|
179
|
+
} else {
|
180
|
+
return $.getJSON(Cedar.config.api + "/queries/contententries/" ).done( function(json) {
|
181
|
+
$.each(json, function (key, val) {
|
182
|
+
this.put(val.id, val);
|
183
|
+
this.loaded = true;
|
184
|
+
}.bind(this));
|
185
|
+
}.bind(this));
|
133
186
|
}
|
134
|
-
|
187
|
+
|
135
188
|
}
|
136
189
|
|
190
|
+
/**
|
191
|
+
* remove a single locally store item by key
|
192
|
+
*
|
193
|
+
* @param ID key
|
194
|
+
*/
|
137
195
|
Cedar.Store.prototype.clear = function(key) {
|
138
|
-
|
196
|
+
localStorage.removeItem(key);
|
139
197
|
}
|
140
198
|
|
141
199
|
|
@@ -164,11 +222,32 @@ Cedar.ContentEntry = function(options) {
|
|
164
222
|
this.cedarId = this.options.cedarId;
|
165
223
|
this.el = this.options.el;
|
166
224
|
this.$el = $(this.el);
|
167
|
-
this.apiGet = '/objects/contententries/';
|
168
225
|
}
|
169
226
|
|
227
|
+
Cedar.ContentEntry.query = function(thing) {
|
228
|
+
Cedar.store.query( "/queries/contententries/", "guidfilter", thing );
|
229
|
+
}
|
230
|
+
|
231
|
+
Cedar.ContentEntry.prototype.apiGet = function() {
|
232
|
+
return "/objects/contententries/";
|
233
|
+
};
|
234
|
+
|
235
|
+
Cedar.ContentEntry.prototype.apiQuery = function() {
|
236
|
+
return "/queries/contententries/";
|
237
|
+
};
|
238
|
+
|
239
|
+
Cedar.ContentEntry.prototype.apiFilter = function() {
|
240
|
+
return "guidfilter";
|
241
|
+
};
|
242
|
+
|
243
|
+
Cedar.ContentEntry.prototype.apiList = function() {
|
244
|
+
return "guidlist";
|
245
|
+
};
|
246
|
+
|
247
|
+
|
170
248
|
// parse the json for the relevant content
|
171
249
|
Cedar.ContentEntry.prototype.setContent = function(json) {
|
250
|
+
if (typeof json === "undefined") return;
|
172
251
|
if (json.code == "UNKNOWN_ID"){
|
173
252
|
this.content = ' '; // if an element is new, fill with blank space to allow edit box to display
|
174
253
|
}
|
@@ -209,12 +288,20 @@ Cedar.ContentEntry.prototype.fill = function(element) {
|
|
209
288
|
|
210
289
|
// check store for content
|
211
290
|
Cedar.ContentEntry.prototype.retrieve = function() {
|
212
|
-
return Cedar.store.
|
291
|
+
return Cedar.store.get(this, this.cedarId).then(function(response) {
|
292
|
+
if (typeof response === "string") {
|
293
|
+
response = JSON.parse(response);
|
294
|
+
}
|
213
295
|
this.setContent(response);
|
214
296
|
return this;
|
215
297
|
}.bind(this));
|
216
298
|
}
|
217
299
|
|
300
|
+
// query filtered on object name matches
|
301
|
+
Cedar.ContentEntry.prototype.query = function(filter) {
|
302
|
+
return Cedar.store.query(filter, this);
|
303
|
+
}
|
304
|
+
|
218
305
|
// fill the asssociated element with the retrieved content
|
219
306
|
Cedar.ContentEntry.prototype.render = function() {
|
220
307
|
this.retrieve().done(function() {
|
@@ -241,3 +328,5 @@ Cedar.ContentEntry.prototype.getEditOpen = function(id) {
|
|
241
328
|
Cedar.ContentEntry.prototype.getEditClose = function(){
|
242
329
|
return '</span>';
|
243
330
|
}
|
331
|
+
|
332
|
+
Cedar.Init();
|
data/lib/cedar/version.rb
CHANGED
Binary file
|
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.2.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-
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- Rakefile
|
52
52
|
- cedar.gemspec
|
53
53
|
- lib/assets/images/cedar-display-tools-sprite.png
|
54
|
+
- lib/assets/javascripts/cedar.handlebars.js
|
54
55
|
- lib/assets/javascripts/cedar.js
|
55
56
|
- lib/assets/javascripts/cedar.marionette.js
|
56
57
|
- lib/assets/javascripts/cedarInit.js.erb
|
@@ -65,6 +66,7 @@ files:
|
|
65
66
|
- pkg/cedar-0.0.8.pre.gem
|
66
67
|
- pkg/cedar-0.0.9.pre.gem
|
67
68
|
- pkg/cedar-0.1.0.pre.gem
|
69
|
+
- pkg/cedar-0.1.1.pre.gem
|
68
70
|
homepage: http://plyinteractive.com
|
69
71
|
licenses:
|
70
72
|
- MIT
|