cedar 0.1.4.pre → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5d280227fbd35a6d74fad592fc82ade118e7235
4
- data.tar.gz: 98f6b8c3544fc3f053f6f7c7bc6b20fe5e128faa
3
+ metadata.gz: 94d2c597a7f479090911653296c9d179b97b7d04
4
+ data.tar.gz: a9f0edf34cf4e4b371c94918e4798aa7c99a6a89
5
5
  SHA512:
6
- metadata.gz: 8598d491a8eea92e6395ad8626dac591f924ecfbd8f3566ebae1ad52c6ae82f6b4ac279d11188c33c8aad628c705e1c88148ceb75ffeb6ebfd8f02e6a63a00ba
7
- data.tar.gz: 818dfac12dd59da8b8ff884caac69ddd582219aa9fd789627e14a84392010d83caae7d7b5b6e56e11ed0d13e2d2d3d4c7d4e2ee75344ed165514128ac2df4b45
6
+ metadata.gz: 36937266911e61807abc29ebb2db7c33d83bfec1143fd2984f1a0d927442cb49468b7e45b15483feb1319b7ee8dd14f286d31b4cf14e4938e22595b9e9fe84e1
7
+ data.tar.gz: e0ba878e2c81318fa8600760ed82a2cf8862657c1e7ef0021908a20a14f352ad63b44bf6fb00f5a6cefcdff54cfca17d35f14a0b43561bdeeb499c500017cff3
@@ -0,0 +1 @@
1
+ pkg/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cedar (0.1.2.pre)
4
+ cedar (0.1.5.pre)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -18,7 +18,31 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install cedar
20
20
 
21
+ ## Usage
21
22
 
23
+ To retrieve all available content and save it to `localStorage`, use the following function (returns a promise)
24
+
25
+ ```javascript
26
+ Cedar.store.getAll();
27
+ ```
28
+
29
+ ### Handlebars
30
+
31
+ To add Cedar-managed content to your Handlebars templates, use the following helper:
32
+
33
+ ```handlebars
34
+ {{ cedar type="contentEntry" id="Today's Activities : Activities : Intro" }}
35
+ ```
36
+
37
+ Set the `id` to a unique string that is used to identify this piece of content. The `type` attribute is optional and defaults to `contentEntry`.
38
+
39
+ You can also use the block-helper style which allows you to define a template that the `JSON` content returned from Cedar will bind to.
40
+
41
+ ```handlebars
42
+ {{#cedar type="contentEntry" id="Today's Activities : Activities : Empty Message" }}
43
+ <div class="notice">{{content}}</div>
44
+ {{/cedar}}
45
+ ```
22
46
 
23
47
  ## Ply Dev Notes
24
48
 
@@ -28,6 +28,7 @@ Handlebars.registerHelper('cedar', function(options) {
28
28
  };
29
29
 
30
30
  options.el = document.createElement("div");
31
+ options.el.setAttribute("style", "display: inline");
31
32
  options.el.id = "cedar-js-" + hashCode(options.hash.id);
32
33
 
33
34
  new Cedar.ContentEntry({ cedarId: options.hash.id }).retrieve().then(function(contentEntry){
@@ -37,10 +38,18 @@ Handlebars.registerHelper('cedar', function(options) {
37
38
  domEl = options.el;
38
39
  }
39
40
 
40
- if (typeof options.fn === "undefined") {
41
+ if (typeof options.fn === "undefined") { // If using inline-style helper
41
42
  domEl.innerHTML = contentEntry.getContent();
42
- } else if (typeof options.fn === "function") {
43
- domEl.innerHTML = unescapeHtml(options.fn(contentEntry.toJSON()));
43
+ } else if (typeof options.fn === "function") { // If using block-style helper
44
+ var output = '';
45
+ if (Cedar.auth.isEditMode()) {
46
+ output += contentEntry.getEditOpen();
47
+ }
48
+ output += unescapeHtml(options.fn(contentEntry.toJSON()));
49
+ if (Cedar.auth.isEditMode()) {
50
+ output += contentEntry.getEditClose();
51
+ }
52
+ domEl.innerHTML = output;
44
53
  }
45
54
  });
46
55
 
@@ -116,6 +116,7 @@ Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
116
116
  */
117
117
  Cedar.Store = function() {
118
118
  this.loaded = false;
119
+ console.log("loaded: " + this.loaded);
119
120
  try {
120
121
  return 'localStorage' in window && window['localStorage'] !== null;
121
122
  } catch (e) {
@@ -126,7 +127,6 @@ Cedar.Store = function() {
126
127
  Cedar.Store.prototype.put = function ( key, item ) {
127
128
  localStorage[key] = JSON.stringify(item);
128
129
  }
129
-
130
130
  /**
131
131
  * get a single item based on id (key)
132
132
  * if the item isn't in the local store, then get it from the server
@@ -138,15 +138,15 @@ Cedar.Store.prototype.get = function ( object, key ) {
138
138
  if ( object.apiGet() === null ) {
139
139
  throw 'Cedar Error: must provide api "get" path';
140
140
  }
141
-
142
141
  if (typeof localStorage[key] !== "undefined") {
143
- console.log('retrieved from cache');
142
+ console.log('getting from cache');
144
143
  return $.Deferred().resolve(localStorage[key]);
145
144
  } else {
146
- console.log('retrieved from server');
145
+ console.log('getting from server...');
147
146
  return $.getJSON(Cedar.config.api + object.apiGet() + key, function(json) {
148
- this.put(key, json);
149
- }.bind(this));
147
+ console.log('got from server');
148
+ Cedar.store.put(key, json);
149
+ });
150
150
  }
151
151
  }
152
152
 
@@ -159,13 +159,13 @@ Cedar.Store.prototype.get = function ( object, key ) {
159
159
  *
160
160
  */
161
161
  Cedar.Store.prototype.query = function ( path, param, value ) {
162
-
163
- jQuery.getJSON(Cedar.config.api + path + '?' + param + '=' + value ).done( function(json) {
162
+ $.getJSON(Cedar.config.api + path + '?' + param + '=' + value ).done( function(json) {
164
163
  $.each(json, function (key, val){
165
- Cedar.store.put(key, val);
164
+ if ( typeof val.id !== 'undefined' && typeof val.settings.content !== 'undefined') {
165
+ Cedar.store.put(val.id, val);
166
+ }
166
167
  });
167
- }.bind(this));
168
-
168
+ });
169
169
  }
170
170
 
171
171
  /**
@@ -173,18 +173,30 @@ Cedar.Store.prototype.query = function ( path, param, value ) {
173
173
  * TODO: (currently hardcoded to content entries - should be avail to any type in future)
174
174
  */
175
175
  Cedar.Store.prototype.getAll = function () {
176
+ console.log("loaded: " + Cedar.store.loaded);
177
+ return $.when(Cedar.store.checkData()).then( function() {
176
178
 
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));
186
- }
179
+ console.log("loaded: " + Cedar.store.loaded);
180
+ if (Cedar.store.loaded) {
181
+
182
+ console.log("already loaded all items");
183
+ return $.Deferred().resolve({});
184
+
185
+ } else {
187
186
 
187
+ console.log("loading all items from server...");
188
+ return $.getJSON(Cedar.config.api + "/queries/contententries/" ).done( function(json) {
189
+ console.log("Got new stuff from the server");
190
+ $.each(json, function (key, val) {
191
+ Cedar.store.put(val.id, val);
192
+ console.log("storing: " + val.id + " / " + val);
193
+ });
194
+ Cedar.store.loaded = true;
195
+ });
196
+
197
+ }
198
+
199
+ });
188
200
  }
189
201
 
190
202
  /**
@@ -196,6 +208,30 @@ Cedar.Store.prototype.clear = function(key) {
196
208
  localStorage.removeItem(key);
197
209
  }
198
210
 
211
+ Cedar.Store.prototype.setVersion = function(id) {
212
+ console.log("updating to version #" + id);
213
+ localStorage["___CEDAR__DATA__FINGERPRINT___"] = id;
214
+ }
215
+ Cedar.Store.prototype.getVersion = function() {
216
+ return localStorage["___CEDAR__DATA__FINGERPRINT___"];
217
+ }
218
+ /**
219
+ * Query the server for the latest version number (ie data freshness)
220
+ */
221
+ Cedar.Store.prototype.checkData = function() {
222
+ console.log("checking version #" + Cedar.store.getVersion());
223
+ return $.getJSON(Cedar.config.api + '/queries/status').done( function(json) {
224
+
225
+ if ( Cedar.store.getVersion() != json.settings.version ) {
226
+ console.log("setting version");
227
+ Cedar.store.loaded = false;
228
+ Cedar.store.setVersion(json.settings.version);
229
+ }
230
+ else {
231
+ Cedar.store.loaded = true;
232
+ }
233
+ });
234
+ }
199
235
 
200
236
  /**
201
237
  * Cedar.ContentEntry
@@ -263,7 +299,7 @@ Cedar.ContentEntry.prototype.setContent = function(json) {
263
299
  // takes into account edit mode styling
264
300
  Cedar.ContentEntry.prototype.getContent = function(){
265
301
  if (Cedar.auth.isEditMode()) {
266
- return this.getEditOpen(this.cedarId) + this.content + this.getEditClose();
302
+ return this.getEditOpen() + this.content + this.getEditClose();
267
303
  }
268
304
  else {
269
305
  return this.content;
@@ -272,7 +308,7 @@ Cedar.ContentEntry.prototype.getContent = function(){
272
308
 
273
309
  Cedar.ContentEntry.prototype.toJSON = function(){
274
310
  return {
275
- content: this.getContent()
311
+ content: this.content
276
312
  }
277
313
  };
278
314
 
@@ -298,9 +334,9 @@ Cedar.ContentEntry.prototype.retrieve = function() {
298
334
  }
299
335
 
300
336
  // query filtered on object name matches
301
- Cedar.ContentEntry.prototype.query = function(filter) {
302
- return Cedar.store.query(filter, this);
303
- }
337
+ //Cedar.ContentEntry.prototype.query = function(filter) {
338
+ // return Cedar.store.query(filter, this);
339
+ //}
304
340
 
305
341
  // fill the asssociated element with the retrieved content
306
342
  Cedar.ContentEntry.prototype.render = function() {
@@ -310,7 +346,7 @@ Cedar.ContentEntry.prototype.render = function() {
310
346
  }
311
347
 
312
348
  // styling for edit box
313
- Cedar.ContentEntry.prototype.getEditOpen = function(id) {
349
+ Cedar.ContentEntry.prototype.getEditOpen = function() {
314
350
  var jsString = "if(event.stopPropagation){event.stopPropagation();}" +
315
351
  "event.cancelBubble=true;" +
316
352
  "window.location.href=this.attributes.href.value + \'&referer=' + encodeURIComponent(window.location.href) + '\';" +
@@ -319,7 +355,7 @@ Cedar.ContentEntry.prototype.getEditOpen = function(id) {
319
355
  var block = '<span class="cedar-cms-editable clearfix">';
320
356
  block += '<span class="cedar-cms-edit-tools">';
321
357
  block += '<a onclick="' + jsString + '" href="' + Cedar.config.server +
322
- '/cmsadmin/EditData?cdr=1&t=ContentEntry&o=' + encodeURIComponent(id) +
358
+ '/cmsadmin/EditData?cdr=1&t=ContentEntry&o=' + encodeURIComponent(this.cedarId) +
323
359
  '" class="cedar-cms-edit-icon cedar-js-edit" >';
324
360
  block += '<i class="cedar-cms-icon cedar-cms-icon-right cedar-cms-icon-edit"></i></a>';
325
361
  block += '</span>';
@@ -6,17 +6,26 @@
6
6
  .cedar-cms-editable {
7
7
  position: relative;
8
8
  display: inline-block !important;
9
- border: 1px dotted #F65126 !important;
10
- padding-right: 20px;
11
9
  min-height: 22px;
12
10
  vertical-align: middle;
11
+
12
+ &:before {
13
+ content: "";
14
+ position: absolute;
15
+ top: 0;
16
+ left: 0;
17
+ width: 100%;
18
+ height: 100%;
19
+ border: 1px dotted #F65126 !important;
20
+ box-sizing: border-box;
21
+ }
13
22
  }
14
23
 
15
24
  .cedar-cms-edit-tools {
16
25
  font-family: Arial, sans-serif;
17
26
  position: absolute;
18
27
  top: 0;
19
- right: 0;
28
+ right: -18px;
20
29
  display: block !important;
21
30
  font-size: 10px !important;
22
31
  line-height: 1.2 !important;
@@ -49,7 +58,7 @@
49
58
  height: 18px;
50
59
  background-color: transparent !important;
51
60
  padding: 0;
52
- margin: 1px;
61
+ margin: 0;
53
62
  }
54
63
 
55
64
  /* 4 classes to display icons */
@@ -1,3 +1,3 @@
1
1
  module Cedar
2
- VERSION = "0.1.4.pre"
2
+ VERSION = "0.1.5.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.1.4.pre
4
+ version: 0.1.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-03-26 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -45,6 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".gitignore"
48
49
  - Gemfile
49
50
  - Gemfile.lock
50
51
  - LICENSE.txt