Skip to content

Commit

Permalink
Simplify the urlPrefix method to make it easier to understand
Browse files Browse the repository at this point in the history
  • Loading branch information
bmac committed Dec 30, 2015
1 parent 95c1340 commit b5028e6
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions addon/-private/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,41 +218,31 @@ export default Ember.Mixin.create({
@return {String} urlPrefix
*/
urlPrefix(path, parentURL) {
var host = get(this, 'host');
var host = get(this, 'host') || '';
var namespace = get(this, 'namespace');
var url = [];

if (path) {
// Protocol relative url
//jscs:disable disallowEmptyBlocks
if (/^\/\//.test(path)) {
// Do nothing, the full host is already included. This branch
// avoids the absolute path logic and the relative path logic.
if (/^\/\//.test(path) || /http(s)?:\/\//.test(path)) {
// Do nothing, the full host is already included.
return path;

// Absolute path
} else if (path.charAt(0) === '/') {
//jscs:enable disallowEmptyBlocks
if (host) {
path = path.slice(1);
url.push(host);
}
return `${host}${path}`;
// Relative path
} else if (!/^http(s)?:\/\//.test(path)) {
url.push(parentURL);
} else {
return `${parentURL}/${path}`;
}
} else {
if (host) { url.push(host); }
if (namespace) { url.push(namespace); }
}

if (path) {
url.push(path);
}

// No path provided
var url = [];
if (host) { url.push(host); }
if (namespace) { url.push(namespace); }
return url.join('/');
},


/**
Determines the pathname for a given type.
Expand Down

0 comments on commit b5028e6

Please sign in to comment.