Browse Source

Provide global template helpers for userId, userName, userRoles.

Frederic G. MARAND 8 years ago
parent
commit
f8d8895fb8
4 changed files with 21 additions and 7 deletions
  1. 15 0
      client/helpers.js
  2. 0 0
      client/sso.js
  3. 5 6
      lib/startup.js
  4. 1 1
      package.js

+ 15 - 0
client/helpers.js

@@ -0,0 +1,15 @@
+Meteor.startup(function () {
+  // Helper names have to be well-formed JS identifiers, so they cannot use a
+  // "namespace.symbol" format... but a "namespace$symbol" is usable.
+  Template.registerHelper('drupal_sso$userId', function () {
+    return 42;
+  });
+
+  Template.registerHelper('drupal_sso$userName', function () {
+    return "yopa";
+  });
+
+  Template.registerHelper('drupal_sso$userRoles', function () {
+    return ['foo', 'bar'];
+  });
+});

+ 0 - 0
client/sso.js


+ 5 - 6
lib/startup.js

@@ -1,7 +1,7 @@
 /**
  * The SSO constructor.
  *
- * Notice that the returned sso instance has asynchronous behavior: its state
+ * Notice that the returned SSO instance has asynchronous behavior: its state
  * component will only be initialized once the server callback has returned,
  * which will almost always be some milliseconds after the instance itself is
  * returned: check sso.state.online to ensure the connection attempts is done:
@@ -9,14 +9,13 @@
  * -> false -> failed, values are defaults,
  * -> true -> succeeded,valuers are those provided by the server.
  *
- * @param {string} document_cookies
  * @returns {DrupalSSO}
  * @constructor
  */
-DrupalSSO = function (document_cookies) {
+DrupalSSO = function () {
   // Called without `new`: call with it.
   if (!(this instanceof DrupalSSO)) {
-    return new DrupalSSO(document_cookies);
+    return new DrupalSSO();
   }
 
   // Work around "this" interpretation in local scope methods.
@@ -66,7 +65,7 @@ DrupalSSO = function (document_cookies) {
     cookieBlob = '; ' + cookieBlob;
 
     var cookieName = that.state.cookieName;
-    var cookieValue = undefined;
+    var cookieValue;
     var cookies = cookieBlob.split('; ' + cookieName + "=");
 
     if (cookies.length == 2) {
@@ -74,7 +73,7 @@ DrupalSSO = function (document_cookies) {
     }
 
     return cookieValue;
-  }
+  };
 
   // Constructor body.
   _.extend(that.settings.client, Meteor.settings.public);

+ 1 - 1
package.js

@@ -10,7 +10,7 @@ Package.onUse(function(api) {
   api.versionsFrom('1.1.0.3');
 
   api.addFiles('lib/startup.js');
-  api.addFiles('client/sso.js', 'client');
+  api.addFiles('client/helpers.js', 'client');
   api.addFiles('server/sso.js', 'server');
   api.addFiles('sso.js');