Skip to content

Commit

Permalink
Merge pull request #374 from jreinert/feature/url
Browse files Browse the repository at this point in the history
add url function which returns the absolute url for a path
  • Loading branch information
arunoda committed Nov 11, 2015
2 parents 2ef57b0 + f1b1f4a commit f0573f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Router.prototype.url = function() {
var path = this.path.apply(this, arguments);
return Meteor.absoluteUrl(path.replace(/^\//, ''));
};
3 changes: 3 additions & 0 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Package.onTest(function(api) {
api.addFiles('test/server/plugins/fast_render.js', 'server');

api.addFiles('test/common/router.path.spec.js', ['client', 'server']);
api.addFiles('test/common/router.url.spec.js', ['client', 'server']);
api.addFiles('test/common/router.addons.spec.js', ['client', 'server']);
api.addFiles('test/common/route.spec.js', ['client', 'server']);
api.addFiles('test/common/group.spec.js', ['client', 'server']);
Expand Down Expand Up @@ -76,4 +77,6 @@ function configure(api) {
api.addFiles('server/_init.js', 'server');

api.addFiles('server/plugins/fast_render.js', 'server');

api.addFiles('lib/router.js', ['client', 'server']);
}
11 changes: 11 additions & 0 deletions test/common/router.url.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Tinytest.add('Common - Router - url - generic', function (test) {
var pathDef = "/blog/:blogId/some/:name";
var fields = {
blogId: "1001",
name: "superb"
};
var expectedUrl = Meteor.absoluteUrl('blog/1001/some/superb');

var path = FlowRouter.url(pathDef, fields);
test.equal(path, expectedUrl);
});

0 comments on commit f0573f2

Please sign in to comment.