Permalink
Browse files

All view helpers are now added to Geddy global on init.

  • Loading branch information...
1 parent 75b076c commit a32d1b81a3b8c3bc2f9fda022cc0f1a3ec84b0d4 @larzconwell larzconwell committed Jun 24, 2012
Showing with 24 additions and 5 deletions.
  1. +24 −0 lib/app.js
  2. +0 −5 lib/template/index.js
View
@@ -259,6 +259,29 @@ var App = function () {
}
}
+ // Load helpers into Geddy global
+ // ==================
+ , _loadHelpers = function(next) {
+ this.helpers = {};
+ var self = this
+ , Helpers = require('./template/helpers')
+ , i, helper;
+
+ for(i in Helpers) {
+ helper = Helpers[i];
+
+ if(helper.name !== 'registerData') {
+ // Create alternative helper name with opposite case style
+ helper.altName = helper.altName || utils.string.snakeize(helper.name);
+
+ // Assign to geddy.helpers
+ self.viewHelpers[helper.altName] = helper.action;
+ self.viewHelpers[helper.name] = helper.action;
+ }
+ }
+ next();
+ }
+
// Run code in the app's config/init.js or .coffee variation
// ==================
, _runAppLocalInit = function (next) {
@@ -307,6 +330,7 @@ var App = function () {
, _loadLocales
, _loadMetrics
, _registerTemplatePaths
+ , _loadHelpers
, _runAppLocalInit
];
View
@@ -48,7 +48,6 @@ Templater.prototype.eventTypes = {
// Main render function that renders pages from a layout and template(s)
Templater.prototype.render = function(data, config) {
var templateFileName;
- geddy.helpers = geddy.helpers || {};
// Register all the helper functions to Templato
Helpers.registerData.action(data);
@@ -63,10 +62,6 @@ Templater.prototype.render = function(data, config) {
// Register helper functions for view rendering
Templato.registerHelper(helper.altName, helper.action);
Templato.registerHelper(helper.name, helper.action);
-
- // Assign to geddy.helpers
- geddy.helpers[helper.altName] = helper.action;
- geddy.helpers[helper.name] = helper.action;
}
}

0 comments on commit a32d1b8

Please sign in to comment.