cloudcms-server 4.0.0-beta.2 → 4.0.0-beta.21

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.
Files changed (78) hide show
  1. package/README.md +0 -5
  2. package/cloudcms-server.iml +1 -0
  3. package/index.js +58 -32
  4. package/middleware/authentication/authentication.js +40 -12
  5. package/middleware/authentication/providers/saml.js +8 -4
  6. package/middleware/awareness/awareness.js +8 -7
  7. package/middleware/awareness/plugins/api_event.js +105 -0
  8. package/middleware/awareness/plugins/editorial.js +54 -3
  9. package/middleware/awareness/plugins/resources.js +13 -5
  10. package/middleware/config/adapter.js +0 -44
  11. package/middleware/deployment/deployment.js +22 -24
  12. package/middleware/driver/driver.js +24 -1
  13. package/middleware/driver-config/driver-config.js +0 -6
  14. package/middleware/modules/modules.js +11 -5
  15. package/middleware/perf/perf.js +3 -2
  16. package/middleware/registration/registration.js +0 -5
  17. package/middleware/stores/engines/empty.js +0 -4
  18. package/middleware/stores/engines/fs-caching-adapter.js +0 -5
  19. package/middleware/stores/engines/fs.js +0 -9
  20. package/middleware/stores/engines/s3.js +0 -5
  21. package/middleware/stores/engines/s3fs.js +0 -5
  22. package/middleware/stores/multistore.js +0 -29
  23. package/middleware/stores/store.js +0 -10
  24. package/middleware/stores/stores.js +2 -2
  25. package/middleware/virtual-config/virtual-config.js +253 -206
  26. package/middleware/virtual-files/virtual-files.js +0 -3
  27. package/middleware/welcome/welcome.js +0 -3
  28. package/notifications/notifications.js +72 -10
  29. package/notifications/providers/kafka.js +182 -0
  30. package/notifications/providers/stomp.js +4 -0
  31. package/package.json +40 -56
  32. package/server/index.js +216 -123
  33. package/server/standalone.js +1 -6
  34. package/util/auth.js +10 -4
  35. package/util/cloudcms.js +77 -35
  36. package/util/loaders.js +113 -0
  37. package/util/proxy-factory.js +143 -168
  38. package/util/request.js +6 -2
  39. package/util/workqueue.js +111 -0
  40. package/.last_command +0 -7
  41. package/duster/helpers/core/cloudcms/associations.js +0 -34
  42. package/duster/helpers/core/cloudcms/beta/markdown.js +0 -46
  43. package/duster/helpers/core/cloudcms/beta/nodeAttachmentText.js +0 -46
  44. package/duster/helpers/core/cloudcms/beta/params.js +0 -33
  45. package/duster/helpers/core/cloudcms/beta/processTemplate.js +0 -82
  46. package/duster/helpers/core/cloudcms/content.js +0 -34
  47. package/duster/helpers/core/cloudcms/expand.js +0 -38
  48. package/duster/helpers/core/cloudcms/form.js +0 -34
  49. package/duster/helpers/core/cloudcms/query.js +0 -34
  50. package/duster/helpers/core/cloudcms/queryOne.js +0 -34
  51. package/duster/helpers/core/cloudcms/relatives.js +0 -34
  52. package/duster/helpers/core/cloudcms/search.js +0 -34
  53. package/duster/helpers/core/cloudcms/searchOne.js +0 -34
  54. package/duster/helpers/core/cloudcms/wcm/dependency.js +0 -83
  55. package/duster/helpers/core/cloudcms/wcm/fragment.js +0 -34
  56. package/duster/helpers/core/dev/debug.js +0 -42
  57. package/duster/helpers/core/dom/block.js +0 -49
  58. package/duster/helpers/core/dom/include.js +0 -38
  59. package/duster/helpers/core/dom/layout.js +0 -49
  60. package/duster/helpers/core/dom/link.js +0 -81
  61. package/duster/helpers/core/dom/resource.js +0 -77
  62. package/duster/helpers/core/engine.js +0 -1580
  63. package/duster/helpers/core/ice/value.js +0 -65
  64. package/duster/helpers/core/index.js +0 -49
  65. package/duster/helpers/core/operators/if.js +0 -64
  66. package/duster/helpers/core/operators/iter.js +0 -45
  67. package/duster/helpers/core/operators/iterate.js +0 -129
  68. package/duster/helpers/sample/nyt.js +0 -114
  69. package/duster/index.js +0 -319
  70. package/duster/support.js +0 -436
  71. package/duster/tracker.js +0 -262
  72. package/middleware/authentication/providers/cas.js +0 -73
  73. package/middleware/authentication/providers/facebook.js +0 -120
  74. package/middleware/authentication/providers/github.js +0 -88
  75. package/middleware/authentication/providers/linkedin.js +0 -112
  76. package/middleware/authentication/providers/twitter.js +0 -120
  77. package/middleware/server-tags/server-tags.js +0 -113
  78. package/middleware/wcm/wcm.js +0 -1437
@@ -1,15 +1,13 @@
1
- var http = require("http");
2
- var https = require("https");
1
+ // var http = require("http");
2
+ // var https = require("https");
3
3
  var path = require("path");
4
4
 
5
5
  var auth = require("./auth");
6
- var util = require("./util");
6
+ // var util = require("./util");
7
7
 
8
8
  var oauth2 = require("./oauth2")();
9
9
 
10
- var urlTool = require("url");
11
-
12
- var LRUCache = require("lru-cache");
10
+ var LRU = require("lru-cache");
13
11
 
14
12
  var exports = module.exports;
15
13
 
@@ -19,9 +17,9 @@ var _LOCK = function(lockIdentifiers, workFunction)
19
17
  process.locks.lock(name, workFunction);
20
18
  };
21
19
 
22
- var NAMED_PROXY_HANDLERS_CACHE = new LRUCache({
20
+ var NAMED_PROXY_HANDLERS_CACHE = new LRU({
23
21
  max: 200,
24
- maxAge: 1000 * 60 * 60 // 60 minutes
22
+ ttl: 1000 * 60 * 60 // 60 minutes
25
23
  });
26
24
 
27
25
  var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pathPrefix, callback)
@@ -35,36 +33,40 @@ var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pa
35
33
  {
36
34
  return callback(null, _cachedHandler);
37
35
  }
38
-
39
- // take out a thread lock
40
- _LOCK(["acquireProxyHandler", name], function(err, releaseLockFn) {
41
-
42
- if (err)
43
- {
44
- console.log("Failed to acquire proxy handler: " + name + ", err: ", err);
45
-
46
- // failed to acquire lock
47
- return callback(err);
48
- }
49
-
50
- // second check to make sure another thread didn't create the handler in the meantime
51
- _cachedHandler = NAMED_PROXY_HANDLERS_CACHE[name];
52
- if (_cachedHandler)
53
- {
54
- releaseLockFn();
55
- return callback(null, _cachedHandler);
56
- }
57
-
58
- // create the proxy handler and cache it into LRU cache
59
- //console.log("Acquiring proxy handler: " + name + ", for target: " + proxyTarget + " and prefix: " + pathPrefix);
60
- _cachedHandler = createProxyHandler(proxyTarget, pathPrefix);
61
-
62
- // store back into LRU cache
63
- NAMED_PROXY_HANDLERS_CACHE[name] = _cachedHandler;
64
36
 
65
- releaseLockFn();
66
- callback(null, _cachedHandler);
67
- });
37
+ // // take out a thread lock
38
+ // _LOCK(["acquireProxyHandler", name], function(err, releaseLockFn) {
39
+ //
40
+ // if (err)
41
+ // {
42
+ // console.log("Failed to acquire proxy handler: " + name + ", err: ", err);
43
+ //
44
+ // // failed to acquire lock
45
+ // return callback(err);
46
+ // }
47
+ //
48
+ // // second check to make sure another thread didn't create the handler in the meantime
49
+ // _cachedHandler = NAMED_PROXY_HANDLERS_CACHE[name];
50
+ // if (_cachedHandler)
51
+ // {
52
+ // releaseLockFn();
53
+ // return callback(null, _cachedHandler);
54
+ // }
55
+ //
56
+ // // create the proxy handler and cache it into LRU cache
57
+ // //console.log("Acquiring proxy handler: " + name + ", for target: " + proxyTarget + " and prefix: " + pathPrefix);
58
+ // _cachedHandler = createProxyHandler(proxyTarget, pathPrefix);
59
+ //
60
+ // // store back into LRU cache
61
+ // NAMED_PROXY_HANDLERS_CACHE[name] = _cachedHandler;
62
+ //
63
+ // releaseLockFn();
64
+ // callback(null, _cachedHandler);
65
+ // });
66
+
67
+ _cachedHandler = NAMED_PROXY_HANDLERS_CACHE[name] = createProxyHandler(proxyTarget, pathPrefix);
68
+
69
+ callback(null, _cachedHandler);
68
70
  };
69
71
 
70
72
 
@@ -72,70 +74,106 @@ var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pa
72
74
 
73
75
  var createProxyHandler = function(proxyTarget, pathPrefix)
74
76
  {
75
- const proxy = require("http2-proxy");
76
- const finalhandler = require('finalhandler')
77
-
78
- const defaultWebHandler = function(err, req, res) {
79
- if (err)
77
+ const { proxy, close } = require('fast-proxy')({
78
+ base: proxyTarget,
79
+ cacheURLs: 0,
80
+ //http2: true,
81
+ //undici: true
82
+ });
83
+
84
+ var proxyOptions = {};
85
+ proxyOptions.onResponse = function(req, res, stream) {
86
+
87
+ if (req.gitana_user)
80
88
  {
81
- console.log("A web proxy error was caught, path: " + req.path + ", err: ", err);
82
- try { res.status(500); } catch (e) { }
83
- try { res.end('Something went wrong while proxying the request.'); } catch (e) { }
84
- }
85
-
86
- finalhandler(req, res)(err);
87
- };
88
-
89
- // const defaultWsHandler = function(err, req, socket, head) {
90
- // if (err) {
91
- // console.error('proxy error (ws)', err);
92
- // socket.destroy();
93
- // }
94
- // };
95
-
96
- //console.log("Proxy Target: " + proxyTarget);
97
-
98
- var hostname = urlTool.parse(proxyTarget).hostname;
99
- var port = urlTool.parse(proxyTarget).port;
100
- var protocol = urlTool.parse(proxyTarget).protocol;
101
-
102
- // web
103
- var webConfig = {};
104
- webConfig.hostname = hostname;
105
- webConfig.port = port;
106
- webConfig.protocol = protocol;
107
- //webConfig.path = null;
108
- webConfig.timeout = 120000;
109
- webConfig.proxyTimeout = 120000;
110
- webConfig.proxyName = "Cloud CMS UI Proxy";
111
- webConfig.onReq = function(req, options) {
112
-
113
- if (!options.headers) {
114
- options.headers = {};
115
- }
116
- var headers = options.headers;
89
+ var chunks = [];
90
+
91
+ // triggers on data receive
92
+ stream.on('data', function(chunk) {
93
+ console.log("DATA!");
94
+ // add received chunk to chunks array
95
+ chunks.push(chunk);
96
+ });
97
+
98
+ stream.on("end", function () {
99
+
100
+ if (stream.statusCode === 401)
101
+ {
102
+ var text = "" + Buffer.concat(chunks);
103
+ if (text && (text.indexOf("invalid_token") > -1) || (text.indexOf("invalid_grant") > -1))
104
+ {
105
+ var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
106
+
107
+ _LOCK([identifier], function(err, releaseLockFn) {
108
+
109
+ if (err)
110
+ {
111
+ // failed to acquire lock
112
+ console.log("FAILED TO ACQUIRE LOCK", err);
113
+ req.log("FAILED TO ACQUIRE LOCK", err);
114
+ try { releaseLockFn(); } catch (e) { }
115
+ return;
116
+ }
117
+
118
+ var cleanup = function (full)
119
+ {
120
+ delete Gitana.APPS[req.identity_properties.token];
121
+ delete Gitana.PLATFORM_CACHE[req.identity_properties.token];
122
+
123
+ if (full) {
124
+ auth.removeUserCacheEntry(identifier);
125
+ }
126
+ };
127
+
128
+ // null out the access token
129
+ // this will force the refresh token to be used to get a new one on the next request
130
+ req.gitana_user.getDriver().http.refresh(function (err) {
131
+
132
+ if (err) {
133
+ cleanup(true);
134
+ req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
135
+ return releaseLockFn();
136
+ }
117
137
 
118
- if (options.path && options.path.startsWith("/proxy")) {
119
- options.path = options.path.substring(6);
138
+ req.gitana_user.getDriver().reloadAuthInfo(function () {
139
+ cleanup(true);
140
+ req.log("Refreshed token for gitana user: " + req.identity_properties.token);
141
+ releaseLockFn();
142
+ });
143
+ });
144
+ });
145
+ }
146
+
147
+ }
148
+ });
120
149
  }
121
-
122
- if (pathPrefix) {
123
- options.path = path.join(pathPrefix, options.path);
150
+
151
+ //res.setHeader('x-powered-by', 'cloudcms');
152
+ if (stream.statusCode && stream.headers) {
153
+ res.writeHead(stream.statusCode, stream.headers)
124
154
  }
125
-
155
+
156
+ stream.pipe(res)
157
+ };
158
+ proxyOptions.rewriteRequestHeaders = function(req, headers)
159
+ {
126
160
  // used to auto-assign the client header for /oauth/token requests
127
161
  oauth2.autoProxy(req);
128
-
162
+ if (req.headers && req.headers.authorization)
163
+ {
164
+ headers["authorization"] = req.headers.authorization;
165
+ }
166
+
129
167
  // copy domain host into "x-cloudcms-domainhost"
130
168
  if (req.domainHost) {
131
169
  headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
132
170
  }
133
-
171
+
134
172
  // copy virtual host into "x-cloudcms-virtualhost"
135
173
  if (req.virtualHost) {
136
174
  headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
137
175
  }
138
-
176
+
139
177
  // copy deployment descriptor info
140
178
  if (req.descriptor)
141
179
  {
@@ -145,27 +183,27 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
145
183
  {
146
184
  headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
147
185
  }
148
-
186
+
149
187
  if (req.descriptor.tenant.title)
150
188
  {
151
189
  headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
152
190
  }
153
191
  }
154
-
192
+
155
193
  if (req.descriptor.application)
156
194
  {
157
195
  if (req.descriptor.application.id)
158
196
  {
159
197
  headers["x-cloudcms-application-id"] = req.descriptor.application.id;
160
198
  }
161
-
199
+
162
200
  if (req.descriptor.application.title)
163
201
  {
164
202
  headers["x-cloudcms-application-title"] = req.descriptor.application.title;
165
203
  }
166
204
  }
167
205
  }
168
-
206
+
169
207
  // set optional "x-cloudcms-origin" header
170
208
  var cloudcmsOrigin = null;
171
209
  if (req.virtualHost)
@@ -176,13 +214,13 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
176
214
  {
177
215
  headers["x-cloudcms-origin"] = cloudcmsOrigin;
178
216
  }
179
-
217
+
180
218
  // set x-cloudcms-server-version header
181
219
  headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
182
-
220
+
183
221
  // keep alive
184
222
  //req.headers["connection"] = "keep-alive";
185
-
223
+
186
224
  // if the incoming request didn't have an "Authorization" header
187
225
  // and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
188
226
  if (!req.headers["authorization"])
@@ -196,85 +234,22 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
196
234
  headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
197
235
  }
198
236
  }
199
- };
200
- webConfig.onRes = function(req, res, proxyRes) {
201
-
202
- if (req.gitana_user)
203
- {
204
- var chunks = [];
205
-
206
- // triggers on data receive
207
- proxyRes.on('data', function(chunk) {
208
- // add received chunk to chunks array
209
- chunks.push(chunk);
210
- });
211
-
212
- proxyRes.on("end", function () {
213
-
214
- if (proxyRes.statusCode === 401)
215
- {
216
- var text = "" + Buffer.concat(chunks);
217
- if (text && (text.indexOf("invalid_token") > -1) || (text.indexOf("invalid_grant") > -1))
218
- {
219
- var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
220
237
 
221
- _LOCK([identifier], function(err, releaseLockFn) {
222
-
223
- if (err)
224
- {
225
- // failed to acquire lock
226
- console.log("FAILED TO ACQUIRE LOCK", err);
227
- req.log("FAILED TO ACQUIRE LOCK", err);
228
- try { releaseLockFn(); } catch (e) { }
229
- return;
230
- }
231
-
232
- var cleanup = function (full)
233
- {
234
- delete Gitana.APPS[req.identity_properties.token];
235
- delete Gitana.PLATFORM_CACHE[req.identity_properties.token];
236
-
237
- if (full) {
238
- auth.removeUserCacheEntry(identifier);
239
- }
240
- };
241
-
242
- // null out the access token
243
- // this will force the refresh token to be used to get a new one on the next request
244
- req.gitana_user.getDriver().http.refresh(function (err) {
245
-
246
- if (err) {
247
- cleanup(true);
248
- req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
249
- return releaseLockFn();
250
- }
238
+ return headers;
239
+ };
240
+ // rewrite response headers
241
+ proxyOptions.rewriteHeaders = function(headers)
242
+ {
243
+ return headers;
244
+ };
245
+ // request invoke settings
246
+ //proxyOptions.request = {};
251
247
 
252
- req.gitana_user.getDriver().reloadAuthInfo(function () {
253
- cleanup(true);
254
- req.log("Refreshed token for gitana user: " + req.identity_properties.token);
255
- releaseLockFn();
256
- });
257
- });
258
- });
259
- }
248
+ //////////////////////////////////////////////////////////////////////////
260
249
 
261
- }
262
- });
263
- }
264
-
265
- //res.setHeader('x-powered-by', 'cloudcms');
266
- res.writeHead(proxyRes.statusCode, proxyRes.headers)
267
- proxyRes.pipe(res)
268
- };
269
-
270
250
  var proxyRequestHandler = function(req, res) {
271
- proxy.web(req, res, webConfig, function(err, req, res) {
272
- defaultWebHandler(err, req, res);
273
- });
251
+ proxy(req, res, pathPrefix, proxyOptions);
274
252
  };
275
-
276
- // cookie domain rewrite?
277
- // not needed - this is handled intrinsically by http2-proxy
278
253
 
279
254
  return proxyRequestHandler;
280
255
  };
package/util/request.js CHANGED
@@ -103,7 +103,6 @@ module.exports = function(config, callback)
103
103
  requestConfig.responseType = config.responseType;
104
104
  }
105
105
 
106
-
107
106
  /*
108
107
  if (requestConfig.url.toLowerCase().indexOf("https:") > -1)
109
108
  {
@@ -114,10 +113,15 @@ module.exports = function(config, callback)
114
113
  requestConfig.httpAgent = http.globalAgent;
115
114
  }
116
115
  */
116
+
117
+ if (config.timeout) {
118
+ requestConfig.timeout = config.timeout;
119
+ }
117
120
 
118
121
  return axios.request(requestConfig).then(function(response) {
119
122
  callback(null, response, response.data);
120
- }, function(error) {
123
+ }).catch(function(error) {
121
124
  callback(error);
122
125
  });
126
+
123
127
  };
@@ -0,0 +1,111 @@
1
+ var util = require("./util");
2
+
3
+ module.exports = function(name, maxSize, debug)
4
+ {
5
+ if (!maxSize) {
6
+ maxSize = 3;
7
+ }
8
+
9
+ var pendingWorkQueue = [];
10
+ var activeCount = 0;
11
+
12
+ var debugLog = function(text)
13
+ {
14
+ if (debug)
15
+ {
16
+ console.log("[WORKQUEUE: " + name + "] " + text);
17
+ }
18
+ }
19
+
20
+ var dispatcherFn = function () {
21
+
22
+ // add as many pending work items as we can, loop until full or no more pending
23
+ var process = true;
24
+ do
25
+ {
26
+ // if nothing to work on, bail
27
+ if (pendingWorkQueue.length === 0)
28
+ {
29
+ process = false;
30
+ }
31
+ else
32
+ {
33
+ // var ids = [];
34
+ // for (var z = 0; z < pendingWorkQueue.length; z++)
35
+ // {
36
+ // ids.push(pendingWorkQueue[z].id);
37
+ // }
38
+ //
39
+ // debugLog("Dispatcher top, queue: " + ids.join(","));
40
+
41
+ //debugLog("dispatcher, pending: " + pendingWorkQueue.length + ", actives: " + activeCount + "]");
42
+
43
+ // if we're full, bail
44
+ if (activeCount >= maxSize)
45
+ {
46
+ process = false;
47
+ }
48
+
49
+ if (process)
50
+ {
51
+ // increment active count
52
+ activeCount++;
53
+
54
+ // define execution function and splice/bind to 0th element from pending list
55
+ var executionFn = function(work) {
56
+ return function() {
57
+ var workFn = work.workFn;
58
+ var callbackFn = work.callbackFn;
59
+
60
+ debugLog("Start: " + work.id + ", queue: " + pendingWorkQueue.length + ", actives: " + activeCount);
61
+
62
+ workFn(function(err, obj1, obj2) {
63
+
64
+ // fire optional callback
65
+ if (callbackFn) {
66
+ window.setTimeout(function() {
67
+ callbackFn(err, obj1, obj2);
68
+ });
69
+ }
70
+
71
+ // decrement active count
72
+ activeCount--;
73
+
74
+ debugLog("Complete: " + work.id + ", queue: " + pendingWorkQueue.length + ", actives: " + activeCount);
75
+ });
76
+
77
+ };
78
+ }(pendingWorkQueue.splice(0, 1)[0]);
79
+
80
+ // execute on timeout
81
+ window.setTimeout(executionFn);
82
+ }
83
+ }
84
+
85
+ } while (process);
86
+
87
+ // run again on a brief timeout
88
+ window.setTimeout(dispatcherFn, 50);
89
+ };
90
+
91
+ // launch dispatcher
92
+ window.setTimeout(dispatcherFn);
93
+
94
+ // hand back a function to register work onto the queue
95
+ return function(workFn, callbackFn) {
96
+
97
+ var work = {
98
+ "id": util.guid(),
99
+ "workFn": workFn
100
+ };
101
+
102
+ if (callbackFn) {
103
+ work.callbackFn = callbackFn;
104
+ }
105
+
106
+ pendingWorkQueue.push(work);
107
+
108
+ //debugLog("Added to pending queue, id: " + work.id + ", pending: " + pendingWorkQueue.length);
109
+ };
110
+
111
+ };
package/.last_command DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "command": {
3
- "group": "server",
4
- "name": "start"
5
- },
6
- "arguments": {}
7
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * @associations
3
- *
4
- * @param app
5
- * @param dust
6
- * @param callback
7
- */
8
- module.exports = function(app, dust, callback)
9
- {
10
- var engine = require("../engine")(app, dust);
11
-
12
- /**
13
- * ASSOCIATIONS
14
- *
15
- * Finds associations around a node.
16
- *
17
- * Syntax:
18
- *
19
- * {@associations node="<nodeId>" type="<association_type>" limit="" skip="" as=""}
20
- * {+templateIdentifier/}
21
- * {/associations}
22
- *
23
- * @param chunk
24
- * @param context
25
- * @param bodies
26
- * @param params
27
- */
28
- dust.helpers.associations = function(chunk, context, bodies, params)
29
- {
30
- return engine.handleAssociations(chunk, context, bodies, params);
31
- };
32
-
33
- callback();
34
- };
@@ -1,46 +0,0 @@
1
- var marked = require("marked");
2
- marked.setOptions({
3
- renderer: new marked.Renderer(),
4
- gfm: true,
5
- tables: true,
6
- breaks: false,
7
- pedantic: false,
8
- sanitize: true,
9
- smartLists: true,
10
- smartypants: false
11
- });
12
-
13
- /**
14
- * @markdown
15
- *
16
- * @param app
17
- * @param dust
18
- * @param callback
19
- */
20
- module.exports = function(app, dust, callback)
21
- {
22
- /**
23
- * Renders markdown into the Dust template.
24
- *
25
- * @param chunk
26
- * @param context
27
- * @param bodies
28
- * @param params
29
- * @returns {*}
30
- */
31
- dust.helpers.markdown = function(chunk, context, bodies, params) {
32
-
33
- params = params || {};
34
-
35
- var text = context.resolve(params.text);
36
- if (!text) {
37
- return chunk;
38
- }
39
-
40
- text = marked(text);
41
-
42
- return chunk.write(text);
43
- };
44
-
45
- callback();
46
- };
@@ -1,46 +0,0 @@
1
- /**
2
- * @nodeAttachmentText
3
- *
4
- * @param app
5
- * @param dust
6
- * @param callback
7
- */
8
- module.exports = function(app, dust, callback)
9
- {
10
- var engine = require("../../engine")(app, dust);
11
-
12
- var map = engine.map;
13
- var end = engine.end;
14
-
15
- dust.helpers.nodeAttachmentText = dust.helpers.nodeAttachmentValue = function(chunk, context, bodies, params)
16
- {
17
- params = params || {};
18
-
19
- var nodeId = context.resolve(params.node);
20
- var attachmentId = context.resolve(params.attachment);
21
- if (!attachmentId)
22
- {
23
- attachmentId = "default";
24
- }
25
-
26
- return map(chunk, function(chunk) {
27
-
28
- var req = context.get("req");
29
- req.branch(function(err, branch) {
30
-
31
- if (err) {
32
- return end(chunk, context);
33
- }
34
-
35
- branch.readNode(nodeId).attachment(attachmentId).download(function(text) {
36
-
37
- chunk.write(text);
38
-
39
- end(chunk, context);
40
- });
41
- });
42
- });
43
- };
44
-
45
- callback();
46
- };