Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

If no controller is given with the `id` or `action` urlFor will attem…

…pt to get the current controller
  • Loading branch information...
commit 3489b5cdb2205bbdc9895f01e6a69564d24c8cab 1 parent 3b29a7e
@larzconwell larzconwell authored
Showing with 26 additions and 5 deletions.
  1. +7 −4 lib/template/helpers/index.js
  2. +19 −1 lib/template/helpers/utils.js
View
11 lib/template/helpers/index.js
@@ -22,7 +22,10 @@ var utils = require('../../utils')
// Copy a data object so it can be used in helpers
exports.registerData = {
name: 'registerData',
- action: function(data) { Data = data; }
+ action: function(data) {
+ Data = data;
+ helperUtils.registerData(data);
+ }
}
/*
@@ -178,10 +181,10 @@ exports.scriptLink = {
* Generates a style element pointing to `source` and includes all the given `htmlOptions`
*
* Examples:
- * styleLink('/js/script.js')
+ * styleLink('/css/styles.css')
* => '<link href="/css/style.css" />'
*
- * styleLink('/js/script.js', { type: 'text/javascript' })
+ * styleLink('/css/styles.css', { type: 'text/javascript' })
* => '<link href="/css/style.css" rel="stylesheet" />'
*/
exports.styleLink = {
@@ -275,7 +278,7 @@ exports.imageLink = {
}
/*
- * truncate(string<String>, options<Object>, callback[Function])
+ * truncate(string<String>, options<Integer/Object>, callback[Function])
*
* Truncates a given `string` after a specified `length` if `string` is longer than
* `length`. The last characters will be replaced with an `omission` for a total length not
View
20 lib/template/helpers/utils.js
@@ -1,4 +1,7 @@
var utils = require('../../utils')
+ , Data;
+
+exports.registerData = function(data) { Data = data; };
/*
* Helper utilities for dealing with HTML tags, and other attributes
@@ -229,6 +232,13 @@ exports.urls = {
}
}
if(options.id) {
+ // If no controller is given attempt to get the current one
+ if(!options.controller && Data.params.controller) {
+ var controller = Data.params.controller[0].toLowerCase() +
+ Data.params.controller.slice(1, Data.params.controller.length);
+
+ path += '/' + controller;
+ }
path += '/' + options.id;
if(!options.action) options.action = 'show';
@@ -240,9 +250,17 @@ exports.urls = {
if(options.action) {
path += '/';
+ // If no controller is given attempt to get the current one
+ if(!options.controller && Data.params.controller) {
+ var controller = Data.params.controller[0].toLowerCase() +
+ Data.params.controller.slice(1, Data.params.controller.length);
+
+ path += controller + '/';
+ }
+
if(options.action === 'show') {
if(options.trailingSlash) path += '/';
- return path
+ return path;
} else {
path += options.action;
if(options.trailingSlash) path += '/';
Please sign in to comment.
Something went wrong with that request. Please try again.