Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intended fix for Issue #216 - Changed url creation to simply join strings #217

Merged
merged 7 commits into from
Mar 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ YUI.add('doc-builder', function (Y) {
if (t === 'attribute') {
t = 'attr';
}
href = path.join(base, 'classes', cls + '.html#' + t + '_' + method);
href = Y.webpath(base, 'classes', cls + '.html#' + t + '_' + method);
}
});
}
Expand All @@ -242,9 +242,9 @@ YUI.add('doc-builder', function (Y) {
link = false;
}
if (!href) {
href = path.join(base, 'classes', item + '.html');
href = Y.webpath(base, 'classes', item + '.html');
if (base.match(/^https?:\/\//)) {
href = base + path.join('classes', item + '.html');
href = base + Y.webpath('classes', item + '.html');
}
}
if (!link && self.options.linkNatives) {
Expand Down
17 changes: 17 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,21 @@ YUI.add('utils', function (Y) {

Y.Lang.fixType = fixType;

/**
* Produces a normalized web path by joining all the parts and normalizing the
* filesystem-like path into web compatible url.
* Supports relative and absolute paths.
* Courtesy of [Mojito's utils](https://github.com/yahoo/mojito/)
*
* @method webpath
* @param {Array|String*} url the list of parts to be joined and normalized
* @return {String} The joined and normalized url
**/
function webpath(url) {
var args = [].concat.apply([], arguments),
parts = path.join.apply(path, args).split(/[\\\/]/);
return parts.join('/');
}

Y.webpath = webpath;
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"scripts": {
"pretest": "jshint ./lib/*.js ./tests/*.js",
"test": "istanbul cover --print=both --yui ytestrunner -- --include ./tests/options.js --include ./tests/builder.js --include ./tests/parser.js --include ./tests/parser_coffee.js --include ./tests/files.js"
"test": "istanbul cover --print=both --yui ytestrunner -- --include ./tests/options.js --include ./tests/builder.js --include ./tests/parser.js --include ./tests/parser_coffee.js --include ./tests/files.js --include ./tests/utils.js"
},
"preferGlobal": "true",
"licenses":[
Expand Down
16 changes: 16 additions & 0 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,20 @@ suite.add(new YUITest.TestCase({
}
}));

suite.add(new YUITest.TestCase({
name: 'produce valid web urls',
'test: Adds paths onto end in sequence' : function() {
var url = Y.webpath('foo', 'bar', 'baz');
Assert.areEqual('foo/bar/baz', url, 'parts should be added in sequence');
},
'test: normalises windows paths into web happy urls' : function() {
var url = Y.webpath('foo\\bar', 'baz');
Assert.areEqual('foo/bar/baz', url, '\\ should be normalised to /');
},
'test: joins relative paths' : function() {
var url = Y.webpath('./foo/bar', './baz/');
Assert.areEqual('foo/bar/baz/', url, 'should join relative paths');
}
}));

YUITest.TestRunner.add(suite);