cedar 0.1.5.pre → 0.1.6.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: 94d2c597a7f479090911653296c9d179b97b7d04
4
- data.tar.gz: a9f0edf34cf4e4b371c94918e4798aa7c99a6a89
3
+ metadata.gz: 864ddc8254855ea4cd9be8c882e123fc3008f751
4
+ data.tar.gz: bae1dc187c21c92183fe0a20c9f70f04e5c6bc56
5
5
  SHA512:
6
- metadata.gz: 36937266911e61807abc29ebb2db7c33d83bfec1143fd2984f1a0d927442cb49468b7e45b15483feb1319b7ee8dd14f286d31b4cf14e4938e22595b9e9fe84e1
7
- data.tar.gz: e0ba878e2c81318fa8600760ed82a2cf8862657c1e7ef0021908a20a14f352ad63b44bf6fb00f5a6cefcdff54cfca17d35f14a0b43561bdeeb499c500017cff3
6
+ metadata.gz: 981cc68bfbfee8548d4011d486260c0d13d7a25b65a1b3939e30bff87e033b7f988776d1154542549f1c0154d7eed9b84ecf2ca8cb10098233fa6d40b51b2b43
7
+ data.tar.gz: aff94b364525d5ffa1fc97b99a38f32467baa0529067ce92a36ff4821a991660fe8b11de172f868d203c1d051cf507fe78cc58aadf874d9a5831a5d3827e5a60
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cedar (0.1.5.pre)
4
+ cedar (0.1.6.pre)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -27,8 +27,20 @@ Handlebars.registerHelper('cedar', function(options) {
27
27
  });
28
28
  };
29
29
 
30
- options.el = document.createElement("div");
31
- options.el.setAttribute("style", "display: inline");
30
+ var blockHelperStyle = function() {
31
+ if (typeof options.fn === "function") {
32
+ return true;
33
+ } else {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ var tagName = options.hash.tagName || "span";
39
+ if (blockHelperStyle()) {
40
+ tagName = options.hash.tagName || "div";
41
+ }
42
+
43
+ options.el = document.createElement(tagName);
32
44
  options.el.id = "cedar-js-" + hashCode(options.hash.id);
33
45
 
34
46
  new Cedar.ContentEntry({ cedarId: options.hash.id }).retrieve().then(function(contentEntry){
@@ -38,9 +50,7 @@ Handlebars.registerHelper('cedar', function(options) {
38
50
  domEl = options.el;
39
51
  }
40
52
 
41
- if (typeof options.fn === "undefined") { // If using inline-style helper
42
- domEl.innerHTML = contentEntry.getContent();
43
- } else if (typeof options.fn === "function") { // If using block-style helper
53
+ if (blockHelperStyle()) {
44
54
  var output = '';
45
55
  if (Cedar.auth.isEditMode()) {
46
56
  output += contentEntry.getEditOpen();
@@ -50,6 +60,8 @@ Handlebars.registerHelper('cedar', function(options) {
50
60
  output += contentEntry.getEditClose();
51
61
  }
52
62
  domEl.innerHTML = output;
63
+ } else {
64
+ domEl.innerHTML = contentEntry.getContent();
53
65
  }
54
66
  });
55
67
 
@@ -6,8 +6,9 @@ var Cedar = {
6
6
  store: null,
7
7
  auth: null,
8
8
  config: {
9
- api: 'http://jed.cdr.core.plyinc.dev/api',
10
- server: 'http://jed.cdr.core.plyinc.dev'
9
+ api: '',
10
+ server: '',
11
+ debug: false
11
12
  }
12
13
  };
13
14
 
@@ -17,11 +18,22 @@ var Cedar = {
17
18
  *
18
19
  * take care of global initializations
19
20
  */
20
- Cedar.Init = function() {
21
+ Cedar.Init = function(options) {
21
22
  if ( Cedar.initialized ) {
22
23
  return;
23
24
  }
24
25
 
26
+ if ( typeof options.server === 'undefined' ) {
27
+ throw 'Cedar Error: must provide "server" value on Init()';
28
+ }
29
+
30
+ Cedar.config.server = 'http://' + options.server;
31
+ Cedar.config.api = 'http://' + options.server + '/api';
32
+
33
+ if ( typeof options.debug !== 'undefined' && options.debug ) {
34
+ Cedar.config.debug = true;
35
+ }
36
+
25
37
  if ( Cedar.store === null ) {
26
38
  Cedar.store = new Cedar.Store();
27
39
  }
@@ -50,6 +62,11 @@ Cedar.Init = function() {
50
62
  Cedar.initialized = true;
51
63
  }
52
64
 
65
+ Cedar.debug = function(msg) {
66
+ if (Cedar.config.debug) {
67
+ console.log(msg);
68
+ }
69
+ }
53
70
 
54
71
  /**
55
72
  * Cedar.Auth
@@ -116,7 +133,7 @@ Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
116
133
  */
117
134
  Cedar.Store = function() {
118
135
  this.loaded = false;
119
- console.log("loaded: " + this.loaded);
136
+ Cedar.debug("loaded: " + this.loaded);
120
137
  try {
121
138
  return 'localStorage' in window && window['localStorage'] !== null;
122
139
  } catch (e) {
@@ -139,12 +156,12 @@ Cedar.Store.prototype.get = function ( object, key ) {
139
156
  throw 'Cedar Error: must provide api "get" path';
140
157
  }
141
158
  if (typeof localStorage[key] !== "undefined") {
142
- console.log('getting from cache');
159
+ Cedar.debug('getting from cache');
143
160
  return $.Deferred().resolve(localStorage[key]);
144
161
  } else {
145
- console.log('getting from server...');
162
+ Cedar.debug('getting from server...');
146
163
  return $.getJSON(Cedar.config.api + object.apiGet() + key, function(json) {
147
- console.log('got from server');
164
+ Cedar.debug('got from server');
148
165
  Cedar.store.put(key, json);
149
166
  });
150
167
  }
@@ -173,23 +190,23 @@ Cedar.Store.prototype.query = function ( path, param, value ) {
173
190
  * TODO: (currently hardcoded to content entries - should be avail to any type in future)
174
191
  */
175
192
  Cedar.Store.prototype.getAll = function () {
176
- console.log("loaded: " + Cedar.store.loaded);
193
+ Cedar.debug("loaded: " + Cedar.store.loaded);
177
194
  return $.when(Cedar.store.checkData()).then( function() {
178
195
 
179
- console.log("loaded: " + Cedar.store.loaded);
196
+ Cedar.debug("loaded: " + Cedar.store.loaded);
180
197
  if (Cedar.store.loaded) {
181
198
 
182
- console.log("already loaded all items");
199
+ Cedar.debug("already loaded all items");
183
200
  return $.Deferred().resolve({});
184
201
 
185
202
  } else {
186
203
 
187
- console.log("loading all items from server...");
204
+ Cedar.debug("loading all items from server...");
188
205
  return $.getJSON(Cedar.config.api + "/queries/contententries/" ).done( function(json) {
189
- console.log("Got new stuff from the server");
206
+ Cedar.debug("Got new stuff from the server");
190
207
  $.each(json, function (key, val) {
191
208
  Cedar.store.put(val.id, val);
192
- console.log("storing: " + val.id + " / " + val);
209
+ Cedar.debug("storing: " + val.id + " / " + val);
193
210
  });
194
211
  Cedar.store.loaded = true;
195
212
  });
@@ -209,7 +226,7 @@ Cedar.Store.prototype.clear = function(key) {
209
226
  }
210
227
 
211
228
  Cedar.Store.prototype.setVersion = function(id) {
212
- console.log("updating to version #" + id);
229
+ Cedar.debug("updating to version #" + id);
213
230
  localStorage["___CEDAR__DATA__FINGERPRINT___"] = id;
214
231
  }
215
232
  Cedar.Store.prototype.getVersion = function() {
@@ -219,11 +236,11 @@ Cedar.Store.prototype.getVersion = function() {
219
236
  * Query the server for the latest version number (ie data freshness)
220
237
  */
221
238
  Cedar.Store.prototype.checkData = function() {
222
- console.log("checking version #" + Cedar.store.getVersion());
239
+ Cedar.debug("checking version #" + Cedar.store.getVersion());
223
240
  return $.getJSON(Cedar.config.api + '/queries/status').done( function(json) {
224
241
 
225
242
  if ( Cedar.store.getVersion() != json.settings.version ) {
226
- console.log("setting version");
243
+ Cedar.debug("setting version");
227
244
  Cedar.store.loaded = false;
228
245
  Cedar.store.setVersion(json.settings.version);
229
246
  }
@@ -247,8 +264,6 @@ Cedar.Store.prototype.checkData = function() {
247
264
  * }
248
265
  */
249
266
  Cedar.ContentEntry = function(options) {
250
- Cedar.Init();
251
-
252
267
  var defaults = {
253
268
  el: 'div'
254
269
  };
@@ -292,7 +307,7 @@ Cedar.ContentEntry.prototype.setContent = function(json) {
292
307
  }
293
308
  else {
294
309
  this.content = '';
295
- console.log('Cedar Error: Unable to parse json');
310
+ Cedar.debug('Cedar Error: Unable to parse json');
296
311
  }
297
312
  }
298
313
 
@@ -364,5 +379,3 @@ Cedar.ContentEntry.prototype.getEditOpen = function() {
364
379
  Cedar.ContentEntry.prototype.getEditClose = function(){
365
380
  return '</span>';
366
381
  }
367
-
368
- Cedar.Init();
data/lib/cedar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cedar
2
- VERSION = "0.1.5.pre"
2
+ VERSION = "0.1.6.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.5.pre
4
+ version: 0.1.6.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-02 00:00:00.000000000 Z
11
+ date: 2015-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler