mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-08 16:10:34 +00:00
Further cleaning and bringing CPURL up to speed with CFURL.
Reviewed by me.
This commit is contained in:
1 parent
aa3e3c7e71
commit
b2ffe7e509
7 files changed
+50
-41
No files matched your search
+9
-20
@@ -86,13 +86,13 @@ CPURLCustomIconKey = @"CPURLCustomIconKey";
|
||||
|
||||
- (CPString)path
|
||||
{
|
||||
return [self absoluteString].path();
|
||||
return [self absoluteURL].path();
|
||||
}
|
||||
|
||||
// if absolute, returns the same as path
|
||||
- (CPString)relativePath
|
||||
{
|
||||
return URI_RE.test(_relative) ? (parse(_relative).path || nil) : nil;
|
||||
return self.path();
|
||||
}
|
||||
|
||||
- (CPString)scheme
|
||||
@@ -102,43 +102,32 @@ CPURLCustomIconKey = @"CPURLCustomIconKey";
|
||||
|
||||
- (CPString)user
|
||||
{
|
||||
var str = [self absoluteString];
|
||||
return URI_RE.test(str) ? (parse(str).user || nil) : nil;
|
||||
return [self absoluteURL].user();
|
||||
}
|
||||
|
||||
- (CPString)password
|
||||
{
|
||||
var str = [self absoluteString];
|
||||
return URI_RE.test(str) ? (parse(str).password || nil) : nil;
|
||||
return [self absoluteURL].password();
|
||||
}
|
||||
|
||||
- (CPString)host
|
||||
{
|
||||
var str = [self absoluteString];
|
||||
return URI_RE.test(str) ? (parse(str).domain || nil) : nil;
|
||||
return [self absoluteURL].domain();
|
||||
}
|
||||
|
||||
- (Number)port
|
||||
{
|
||||
var str = [self absoluteString];
|
||||
if (URI_RE.test(str)) {
|
||||
var port = parse(str).port;
|
||||
if (port)
|
||||
return parseInt(port, 10);
|
||||
}
|
||||
return nil;
|
||||
return parseInt([self absoluteURL].port(), 10);
|
||||
}
|
||||
|
||||
- (CPString)parameterString
|
||||
{
|
||||
var str = [self absoluteString];
|
||||
return URI_RE.test(str) ? (parse(str).query || nil) : nil;
|
||||
return self.queryString();
|
||||
}
|
||||
|
||||
- (CPString)fragment
|
||||
{
|
||||
var str = [self absoluteString];
|
||||
return URI_RE.test(str) ? (parse(str).anchor || nil) : nil;
|
||||
return self.fragment();
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(id)anObject
|
||||
@@ -160,7 +149,7 @@ CPURLCustomIconKey = @"CPURLCustomIconKey";
|
||||
|
||||
- (CPURL)standardizedURL
|
||||
{
|
||||
return [CPURL URLWithString:format(parse(_relative)) relativeToURL:_base];
|
||||
return self.standardizedURL();
|
||||
}
|
||||
|
||||
- (BOOL)isFileURL
|
||||
|
||||
@@ -21,6 +21,11 @@
|
||||
*/
|
||||
|
||||
|
||||
function makeAbsoluteURL(/*CFURL|String*/ aURL)
|
||||
{
|
||||
return new CFURL(aURL, mainBundleURL);
|
||||
}
|
||||
|
||||
#ifdef COMMONJS
|
||||
var mainBundleURL = new CFURL("file:" + require("file").cwd());
|
||||
#elif defined(BROWSER)
|
||||
|
||||
@@ -35,7 +35,7 @@ var CFBundlesForURLStrings = { },
|
||||
|
||||
GLOBAL(CFBundle) = function(/*CFURL|String*/ aURL)
|
||||
{
|
||||
aURL = resolveURL(aURL).asDirectoryPathURL();
|
||||
aURL = makeAbsoluteURL(aURL).asDirectoryPathURL();
|
||||
|
||||
var URLString = aURL.absoluteString(),
|
||||
existingBundle = CFBundlesForURLStrings[URLString];
|
||||
@@ -64,9 +64,9 @@ CFBundle.environments = function()
|
||||
return ENVIRONMENTS;
|
||||
}
|
||||
|
||||
CFBundle.bundleContainingURL = function(/*CFURL*/ aURL)
|
||||
CFBundle.bundleContainingURL = function(/*CFURL|String*/ aURL)
|
||||
{
|
||||
aURL = new CFURL(".", resolveURL(aURL));
|
||||
aURL = new CFURL(".", makeAbsoluteURL(aURL));
|
||||
|
||||
while (aURL.path() !== "/")
|
||||
{
|
||||
|
||||
+22
-2
@@ -221,7 +221,7 @@ CFURL.prototype.toString = function()
|
||||
return this.absoluteString();
|
||||
}
|
||||
|
||||
function _resolveURL(aURL)
|
||||
function resolveURL(aURL)
|
||||
{
|
||||
aURL = aURL.standardizedURL();
|
||||
|
||||
@@ -356,7 +356,7 @@ function URLStringFromParts(/*Object*/ parts)
|
||||
CFURL.prototype.absoluteURL = function()
|
||||
{
|
||||
if (this._absoluteURL === undefined)
|
||||
this._absoluteURL = _resolveURL(this);
|
||||
this._absoluteURL = resolveURL(this);
|
||||
|
||||
return this._absoluteURL;
|
||||
}
|
||||
@@ -504,6 +504,26 @@ CFURL.prototype.scheme = function()
|
||||
return baseURL && baseURL.scheme() || "";
|
||||
}
|
||||
|
||||
CFURL.prototype.user = function()
|
||||
{
|
||||
return CFURLGetParts(this).user;
|
||||
}
|
||||
|
||||
CFURL.prototype.password = function()
|
||||
{
|
||||
return CFURLGetParts(this).password;
|
||||
}
|
||||
|
||||
CFURL.prototype.port = function()
|
||||
{
|
||||
return CFURLGetParts(this).port;
|
||||
}
|
||||
|
||||
CFURL.prototype.domain = function()
|
||||
{
|
||||
return CFURLGetParts(this).domain;
|
||||
}
|
||||
|
||||
CFURL.prototype.baseURL = function()
|
||||
{
|
||||
return this._baseURL;
|
||||
|
||||
@@ -26,14 +26,14 @@ var ExecutableUnloadedFileDependencies = 0,
|
||||
ExecutableLoadedFileDependencies = 2,
|
||||
AnonymousExecutableCount = 0;
|
||||
|
||||
function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL*/ aURL, /*Function*/ aFunction)
|
||||
function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String*/ aURL, /*Function*/ aFunction)
|
||||
{
|
||||
if (arguments.length === 0)
|
||||
return this;
|
||||
|
||||
this._code = aCode;
|
||||
this._function = aFunction || NULL;
|
||||
this._URL = resolveURL(aURL || new CFURL("(Anonymous" + (AnonymousExecutableCount++) + ")", mainBundleURL));
|
||||
this._URL = makeAbsoluteURL(aURL || new CFURL("(Anonymous" + (AnonymousExecutableCount++) + ")", mainBundleURL));
|
||||
|
||||
this._fileDependencies = fileDependencies;
|
||||
this._fileDependencyLoadStatus = ExecutableUnloadedFileDependencies;
|
||||
@@ -329,7 +329,7 @@ var cachedFileExecutersForURLStrings = { };
|
||||
|
||||
Executable.fileExecuterForURL = function(/*CFURL|String*/ aURL)
|
||||
{
|
||||
var referenceURL = resolveURL(aURL),
|
||||
var referenceURL = makeAbsoluteURL(aURL),
|
||||
referenceURLString = referenceURL.absoluteString(),
|
||||
cachedFileExecuter = cachedFileExecutersForURLStrings[referenceURLString];
|
||||
|
||||
@@ -356,9 +356,9 @@ Executable.fileExecuterForURL = function(/*CFURL|String*/ aURL)
|
||||
|
||||
var cachedImportersForURLStrings = { };
|
||||
|
||||
Executable.fileImporterForURL = function(/*CFURL*/ aURL)
|
||||
Executable.fileImporterForURL = function(/*CFURL|String*/ aURL)
|
||||
{
|
||||
var referenceURL = resolveURL(aURL),
|
||||
var referenceURL = makeAbsoluteURL(aURL),
|
||||
referenceURLString = referenceURL.absoluteString(),
|
||||
cachedImporter = cachedImportersForURLStrings[referenceURLString];
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
|
||||
var FileExecutablesForURLStrings = { };
|
||||
|
||||
function FileExecutable(/*CFURL*/ aURL, /*Executable*/ anExecutable)
|
||||
function FileExecutable(/*CFURL|String*/ aURL, /*Executable*/ anExecutable)
|
||||
{
|
||||
aURL = resolveURL(aURL);
|
||||
aURL = makeAbsoluteURL(aURL);
|
||||
|
||||
var URLString = aURL.absoluteString(),
|
||||
existingFileExecutable = FileExecutablesForURLStrings[URLString];
|
||||
|
||||
@@ -124,14 +124,9 @@ function rootResourceForAbsoluteURL(/*CFURL*/ anAbsoluteURL)
|
||||
return resource;
|
||||
}
|
||||
|
||||
function resolveURL(/*CFURL|String*/ aURL)
|
||||
StaticResource.resourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ resolveAsDirectoriesIfNecessary)
|
||||
{
|
||||
return new CFURL(aURL, mainBundleURL);
|
||||
}
|
||||
|
||||
StaticResource.resourceAtURL = function(/*CFURL*/ aURL, /*BOOL*/ resolveAsDirectoriesIfNecessary)
|
||||
{
|
||||
aURL = resolveURL(aURL).absoluteURL();
|
||||
aURL = makeAbsoluteURL(aURL).absoluteURL();
|
||||
|
||||
var resource = rootResourceForAbsoluteURL(aURL),
|
||||
components = aURL.pathComponents(),
|
||||
@@ -160,9 +155,9 @@ StaticResource.prototype.resourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*
|
||||
return StaticResource.resourceAtURL(new CFURL(aURL, this.URL()), resolveAsDirectoriesIfNecessary);
|
||||
}
|
||||
|
||||
StaticResource.resolveResourceAtURL = function(/*CFURL*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback)
|
||||
StaticResource.resolveResourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback)
|
||||
{
|
||||
aURL = resolveURL(aURL).absoluteURL();
|
||||
aURL = makeAbsoluteURL(aURL).absoluteURL();
|
||||
|
||||
resolveResourceComponents(rootResourceForAbsoluteURL(aURL), isDirectory, aURL.pathComponents(), 0, aCallback);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user