Commits

Bob Bergman committed e0fae58

Update ringo kit to use RenderContext

Change-Id: I10bc5530ac9940ebc77b9911049f09a09c335ad6

  • Participants
  • Parent commits c4e884c

Comments (0)

Files changed (2)

ringojs-kit/src/main/resources/modules/atlassian/context.js

-var requestContext = appContext.getBean("requestContext");
-
-module.exports = {
-  clientKey: function () {
-    return requestContext.getClientKey();
-  },
-  userId: function () {
-    return requestContext.getUserId();
-  },
-  hostBaseUrl: function () {
-    return requestContext.getHostBaseUrl();
+var context = appContext.getBean("renderContext");
+
+// @todo if this is reparsed on every request, we may want to logically make
+// module.exports = snapshot(), since the values shouldn't change in the scope of a single
+// request (at least, not once we've reached the ringo layer in the execution stack)
+
+var properties = [];
+
+Object.keys(context).forEach(function (k) {
+  if (k.indexOf("get") === 0) {
+    var p = k.charAt(3).toLowerCase() + k.slice(4);
+    properties.push(p);
+    exports[p] = function () { return context[k](); };
   }
+});
+
+exports.snapshot = function () {
+  var json = {};
+  properties.forEach(function (p) {
+    json[p] = exports[p]();
+  });
+  return json;
 };

ringojs-kit/src/main/resources/modules/atlassian/response.js

     // response.render(view, locals)
     // response.render(view, locals, headers, statusCode)
     render: function (view, locals, headers, statusCode) {
-      var hostBaseUrl = context.hostBaseUrl();
-      // @todo make use of RenderContext service
-      var allLocals = {
-        hostBaseUrl: hostBaseUrl,
-        hostStylesheetUrl: hostBaseUrl + "/remoteapps/all.css",
-        hostScriptUrl: hostBaseUrl + "/remoteapps/all.js",
-        clientKey: context.clientKey(),
-        userId: context.userId()
-        // @todo also add the following, using new modules as needed:
-        //    - hostContextPath: URI.create(hostBaseUrl).getPath()
-        //    - i18n: i18nResolver
-        //    - locale: locale
-      };
+      var allLocals = context.snapshot();
       Object.keys(locals).forEach(function (k) {
         allLocals[k] = locals[k];
       });