Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pass app config correctly to helpers

  • Loading branch information...
commit de3fd662d9be6348ec2da65288ce73b23bbdc67a 1 parent b189c5e
@mde mde authored
View
3  lib/init/helpers.js
@@ -18,6 +18,9 @@ module.exports = new (function () {
app.viewHelpers = {};
+ // Pass geddy.config to helpers
+ helpers.setConfig(app.config);
+
// Create action helpers based on router
var i = router.routes.length;
while (--i >= 0) {
View
12 lib/template/helpers/index.js
@@ -20,8 +20,7 @@ var utils = require('utilities')
, helperUtils = require('./utils')
, flashUtils = require('./flash')
, Data
- // FIXME: pass this config in
- , geddyConfig = (typeof geddy != 'undefined' && geddy.config) || {}
+ , _config = {}
, _getAssetPath;
_getAssetPath = function (assetType, src) {
@@ -36,8 +35,8 @@ _getAssetPath = function (assetType, src) {
return src;
}
- host = geddyConfig.assetHost || ''
- basePath = geddyConfig.assetBasePath || '/';
+ host = _config.assetHost || ''
+ basePath = _config.assetBasePath || '/';
// Include poss. extra leading slash in path.join to ensure
// there's at least one
@@ -54,6 +53,7 @@ _getAssetPath = function (assetType, src) {
exports.registerData = {
name: 'registerData',
action: function (data) {
+ helperUtils.setConfig(_config);
Data = data;
helperUtils.registerData(data);
}
@@ -313,3 +313,7 @@ exports.t = {
return i18n.t.apply(i18n, arguments);
}
};
+
+exports.setConfig = function (c) {
+ _config = c;
+};
View
14 lib/template/helpers/utils.js
@@ -1,7 +1,7 @@
var utils = require('utilities')
- , geddyConfig = (typeof geddy != 'undefined' && geddy.config) || {}
// Include empty params so that conditionals will work without registerData being called
- , Data = {params: {}};
+ , Data = {params: {}}
+ , _config = {};
// Register Object for use with `exports.urls`, needs
// a `data.params` to be of any use
@@ -239,7 +239,7 @@ exports.urls = {
var protocol = options.protocol;
// Set default protocol if none is given
- if (geddyConfig.spdy || geddyConfig.ssl) {
+ if (_config.spdy || _config.ssl) {
protocol = protocol || 'https';
} else {
protocol = protocol || 'http';
@@ -275,8 +275,8 @@ exports.urls = {
var domain = options.domain
, hostname = '';
- if (geddyConfig.hostname) {
- domain = domain || geddyConfig.hostname;
+ if (_config.hostname) {
+ domain = domain || _config.hostname;
}
if (options.subdomain) {
@@ -463,3 +463,7 @@ exports.urls = {
}
}
};
+
+exports.setConfig = function (c) {
+ _config = c;
+};
Please sign in to comment.
Something went wrong with that request. Please try again.