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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3e41500eb184aac2c9bc274cc802fffa66aee72
4
- data.tar.gz: e58e773a697d69fe5601792b818fc84cad7ef7f6
3
+ metadata.gz: 3988489729a5845dbe10d9de748a5dda45fecc1b
4
+ data.tar.gz: eb6c4a3546167231d00c5897af33684041594ca8
5
5
  SHA512:
6
- metadata.gz: 2c81982f965d4ffce99a1c2f4d6ba85724688ef98c703c96a017fe4375e99c286d6efe2ce09c7c428f716d4f7cca5e6d6fa0dd29762ed4763e900507b68b8a44
7
- data.tar.gz: 811ade0d0b27c6f2f7afb06aa7dd4584a92a9117c8b912fde7d8bdda66e5d925fa845df33375ba2beee03b7d9d6c1ae036e75c9743c12883f69a3c54e5c82ec0
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
+ '&amp;': '&',
18
+ '&lt;': '<',
19
+ '&gt;': '>',
20
+ '&quot;': '"',
21
+ '&#39;': "'",
22
+ '&#x27;': "'"
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
- // '<a href="#" onclick="window.location.reload(true);return false;">[refresh]</a>' +
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._cache = {};
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
- this._cache[key] = item;
127
+ localStorage[key] = JSON.stringify(item);
117
128
  }
118
129
 
119
- // different cedar types may use different api paths
120
- Cedar.Store.prototype.find = function ( key, getPath ) {
121
- if ( getPath === null )
122
- console.log('Cedar Error: must provide api "get" path');
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 this._cache[key] === 'undefined'){
125
- return $.getJSON(Cedar.config.api + getPath + key, function(json) {
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
- else {
131
- console.log('retrieved from cache');
132
- return $.Deferred().resolve(this._cache[key]);
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
- return false;
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
- delete this._cache[key];
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 = '&nbsp;'; // 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.find(this.cedarId, this.apiGet ).then(function(response) {
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();
@@ -1,3 +1,3 @@
1
1
  module Cedar
2
- VERSION = "0.1.1.pre"
2
+ VERSION = "0.1.2.pre"
3
3
  end
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.1.pre
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-02-14 00:00:00.000000000 Z
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