mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-13 20:17:07 +00:00
Updated environments and removed environment collections. Also creates separate files for different forms of spriting.
Reviewed by me.
This commit is contained in:
1 parent
b5ad030e40
commit
d9c47ec763
4 files changed
+98
-126
No files matched your search
@@ -60,7 +60,7 @@ BlendTask.prototype.defineSourceTasks = function()
|
||||
|
||||
BlendTask.prototype.defineThemeDescriptorTasks = function()
|
||||
{
|
||||
this.flattenedEnvironments().forEach(function(anEnvironment)
|
||||
this.environments().forEach(function(anEnvironment)
|
||||
{
|
||||
var folder = anEnvironment.name() + ".environment",
|
||||
themeDescriptors = this.themeDescriptors(),
|
||||
|
||||
@@ -42,7 +42,7 @@ ApplicationTask.prototype.indexFilePath = function()
|
||||
ApplicationTask.prototype.defineFrameworksTask = function()
|
||||
{
|
||||
// FIXME: platform requires...
|
||||
if (this.flattenedEnvironments().indexOf(require("objective-j/jake/environment").Browsers) === -1)
|
||||
if (this.environments().indexOf(require("objective-j/jake/environment").Browser) === -1)
|
||||
return;
|
||||
|
||||
var frameworks = FILE.join(this.buildProductPath(), "Frameworks"),
|
||||
|
||||
@@ -92,8 +92,6 @@ BundleTask.prototype.setEnvironments = function(environments)
|
||||
|
||||
else
|
||||
this._environments = [environments];
|
||||
|
||||
this._flattenedEnvironments = environment.Environment.flattenedEnvironments(this._environments);
|
||||
}
|
||||
|
||||
BundleTask.prototype.environments = function()
|
||||
@@ -101,11 +99,6 @@ BundleTask.prototype.environments = function()
|
||||
return this._environments;
|
||||
}
|
||||
|
||||
BundleTask.prototype.flattenedEnvironments = function()
|
||||
{
|
||||
return this._flattenedEnvironments;
|
||||
}
|
||||
|
||||
BundleTask.prototype.setAuthor = function(anAuthor)
|
||||
{
|
||||
this._author = anAuthor;
|
||||
@@ -162,14 +155,13 @@ BundleTask.prototype.setSources = function(sources, environments)
|
||||
this._sources = sources;
|
||||
else
|
||||
{
|
||||
if (Array.isArray(environments))
|
||||
environments = environment.Environment.flattenedEnvironments(environments);
|
||||
else
|
||||
environments = environments.flattenedEnvironments();
|
||||
|
||||
if (!this._sources)
|
||||
this._sources = { };
|
||||
|
||||
// If a single envirnment was passed in...
|
||||
if (!Array.isArray(environments))
|
||||
environments = [environments];
|
||||
|
||||
environments.forEach(function(anEnvironment)
|
||||
{
|
||||
this._sources[anEnvironment] = sources;
|
||||
@@ -319,6 +311,16 @@ BundleTask.prototype.buildProductStaticPathForEnvironment = function(anEnvironme
|
||||
return FILE.join(this.buildProductPath(), anEnvironment.name() + ".environment", this.productName() + ".sj");
|
||||
}
|
||||
|
||||
BundleTask.prototype.buildProductMHTMLPathForEnvironment = function(anEnvironment)
|
||||
{
|
||||
return FILE.join(this.buildProductPath(), anEnvironment.name() + ".environment", "MHTML.txt");
|
||||
}
|
||||
|
||||
BundleTask.prototype.buildProductDataURLPathForEnvironment = function(anEnvironment)
|
||||
{
|
||||
return FILE.join(this.buildProductPath(), anEnvironment.name() + ".environment", "dataURL.txt");
|
||||
}
|
||||
|
||||
BundleTask.prototype.defineTasks = function()
|
||||
{
|
||||
this.defineResourceTasks();
|
||||
@@ -326,6 +328,7 @@ BundleTask.prototype.defineTasks = function()
|
||||
this.defineInfoPlistTask();
|
||||
this.defineLicenseTask();
|
||||
this.defineStaticTask();
|
||||
this.defineSpritedImagesTask();
|
||||
|
||||
CLEAN.include(this.buildIntermediatesProductPath());
|
||||
CLOBBER.include(this.buildProductPath());
|
||||
@@ -351,7 +354,7 @@ BundleTask.prototype.infoPlist = function()
|
||||
infoPlist.setValueForKey("CPBundleIdentifier", this.identifier());
|
||||
infoPlist.setValueForKey("CPBundleVersion", this.version());
|
||||
infoPlist.setValueForKey("CPBundlePackageType", this.packageType());
|
||||
infoPlist.setValueForKey("CPBundleEnvironments", this.flattenedEnvironments().map(function(anEnvironment)
|
||||
infoPlist.setValueForKey("CPBundleEnvironments", this.environments().map(function(anEnvironment)
|
||||
{
|
||||
return anEnvironment.name();
|
||||
}));
|
||||
@@ -382,7 +385,7 @@ BundleTask.prototype.defineInfoPlistTask = function()
|
||||
|
||||
// FIXME: ? We do this because adding a .j file should cause Info.plist to be updated.
|
||||
// Any better way to handle this? Perhaps this should happen unconditionally.
|
||||
this.flattenedEnvironments().forEach(function(/*Environment*/ anEnvironment)
|
||||
this.environments().forEach(function(/*Environment*/ anEnvironment)
|
||||
{
|
||||
if (!anEnvironment.spritesImages())
|
||||
return;
|
||||
@@ -432,7 +435,7 @@ BundleTask.prototype.defineResourceTask = function(aResourcePath, aDestinationPa
|
||||
// Don't sprite images larger than 32KB, IE 8 doesn't like it.
|
||||
if (this.spritesResources() && isImage(aResourcePath) && FILE.size(aResourcePath) < 32768)
|
||||
{
|
||||
this.flattenedEnvironments().forEach(function(/*Environment*/ anEnvironment)
|
||||
this.environments().forEach(function(/*Environment*/ anEnvironment)
|
||||
{
|
||||
if (!anEnvironment.spritesImages())
|
||||
return;
|
||||
@@ -445,8 +448,7 @@ BundleTask.prototype.defineResourceTask = function(aResourcePath, aDestinationPa
|
||||
FILE.write(spritedDestinationPath, base64.encode(FILE.read(aResourcePath, { mode : 'b'})), { charset:"UTF-8" });
|
||||
});
|
||||
|
||||
// Add this as a dependency unconditionally because we need to set up the URL map either way.
|
||||
filedir (this.buildProductStaticPathForEnvironment(anEnvironment), [spritedDestinationPath]);
|
||||
task (anEnvironment.name() + "-sprites", [spritedDestinationPath]);
|
||||
}, this);
|
||||
}
|
||||
|
||||
@@ -556,9 +558,73 @@ BundleTask.prototype.defineResourceTasks = function()
|
||||
}, this);
|
||||
}
|
||||
|
||||
BundleTask.prototype.defineSpritedImagesTask = function()
|
||||
{
|
||||
this.environments().forEach(function(/*Environment*/ anEnvironment)
|
||||
{
|
||||
if (!anEnvironment.spritesImages())
|
||||
return;
|
||||
|
||||
var folder = anEnvironment.name() + ".environment",
|
||||
resourcesPath = FILE.join(this.buildIntermediatesProductPath(), folder, "Resources", ""),
|
||||
dataURLPath = this.buildProductDataURLPathForEnvironment(anEnvironment),
|
||||
MHTMLPath = this.buildProductMHTMLPathForEnvironment(anEnvironment),
|
||||
productName = this.productName();
|
||||
|
||||
task(anEnvironment.name() + "-sprites", function(aTask)
|
||||
{
|
||||
TERM.stream.print("Creating sprited images file... \0green(" + dataURLPath +"\0)");
|
||||
|
||||
var dataURLStream = FILE.open(dataURLPath, "w+", { charset:"UTF-8" }),
|
||||
MHTMLStream = FILE.open(MHTMLPath, "w+", { charset:"UTF-8" }),
|
||||
MHTMLContents = "/*\r\nContent-Type: multipart/related; boundary=\"_ANY_STRING_WILL_DO_AS_A_SEPARATOR\"\r\n\r\n";
|
||||
|
||||
dataURLStream.write("@STATIC;1.0;");
|
||||
MHTMLStream.write("@STATIC;1.0;");
|
||||
|
||||
aTask.prerequisites().forEach(function(aFilename)
|
||||
{
|
||||
if (!FILE.isFile(aFilename) || aFilename.indexOf(resourcesPath) !== 0 || !isImage(aFilename))
|
||||
return;
|
||||
|
||||
var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename);
|
||||
|
||||
dataURLStream.write("u;" + resourcePath.length + ";");
|
||||
MHTMLStream.write("u;" + resourcePath.length + ";");
|
||||
|
||||
// As data URL...
|
||||
var contents = "data:" + mimeType(aFilename) +
|
||||
";base64," + FILE.read(aFilename, { charset:"UTF-8" });
|
||||
|
||||
dataURLStream.write(contents.length + ";" + contents);
|
||||
|
||||
// As MHTML...
|
||||
contents = "mhtml:" + FILE.join(folder, productName + ".sj!") + resourcePath;
|
||||
|
||||
MHTMLContents += "--_ANY_STRING_WILL_DO_AS_A_SEPARATOR\r\n";
|
||||
MHTMLContents += "Content-Location:" + resourcePath + "\r\nContent-Transfer-Encoding:base64\r\n\r\n";
|
||||
MHTMLContents += FILE.read(aFilename, { charset:"UTF-8" });
|
||||
MHTMLContents += "\r\n";
|
||||
|
||||
MHTMLStream.write(contents.length + ";" + contents);
|
||||
});
|
||||
|
||||
dataURLStream.write("e;");
|
||||
dataURLStream.close();
|
||||
|
||||
MHTMLStream.write("e;");
|
||||
MHTMLStream.write(MHTMLContents + "*/");
|
||||
MHTMLStream.close();
|
||||
});
|
||||
|
||||
this.enhance([anEnvironment.name() + "-sprites"]);
|
||||
|
||||
}, this);
|
||||
}
|
||||
|
||||
BundleTask.prototype.defineStaticTask = function()
|
||||
{
|
||||
this.flattenedEnvironments().forEach(function(/*Environment*/ anEnvironment)
|
||||
this.environments().forEach(function(/*Environment*/ anEnvironment)
|
||||
{
|
||||
var folder = anEnvironment.name() + ".environment",
|
||||
sourcesPath = FILE.join(this.buildIntermediatesProductPath(), folder, "Sources", ""),
|
||||
@@ -597,49 +663,19 @@ BundleTask.prototype.defineStaticTask = function()
|
||||
fileStream.write("t;" + fileContents.length + ";" + fileContents);
|
||||
}
|
||||
|
||||
else if (aFilename.indexOf(resourcesPath) === 0)
|
||||
else if (aFilename.indexOf(resourcesPath) === 0 && !isImage(aFilename))
|
||||
{
|
||||
var contents = "",
|
||||
resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename);
|
||||
var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename);
|
||||
|
||||
if (isImage(aFilename))
|
||||
{
|
||||
fileStream.write("u;");
|
||||
fileStream.write("p;");
|
||||
|
||||
if (anEnvironment.spritesImagesAsDataURLs())
|
||||
contents = "data:" + mimeType(aFilename) + ";base64," + FILE.read(aFilename, { charset:"UTF-8" });
|
||||
|
||||
else if (anEnvironment.spritesImagesAsMHTML())
|
||||
{
|
||||
contents = "mhtml:" + FILE.join(folder, productName + ".sj!") + resourcePath;
|
||||
|
||||
if (!MHTMLContents.length)
|
||||
MHTMLContents = "/*\r\nContent-Type: multipart/related; boundary=\"_ANY_STRING_WILL_DO_AS_A_SEPARATOR\"\r\n\r\n";
|
||||
|
||||
MHTMLContents += "--_ANY_STRING_WILL_DO_AS_A_SEPARATOR\r\n";
|
||||
MHTMLContents += "Content-Location:" + resourcePath + "\r\nContent-Transfer-Encoding:base64\r\n\r\n";
|
||||
MHTMLContents += FILE.read(aFilename, { charset:"UTF-8" });
|
||||
MHTMLContents += "\r\n";
|
||||
}
|
||||
|
||||
contents = contents.length + ";" + contents;
|
||||
}
|
||||
else
|
||||
{
|
||||
fileStream.write("p;");
|
||||
|
||||
contents = FILE.read(aFilename, { charset:"UTF-8" });
|
||||
}
|
||||
contents = FILE.read(aFilename, { charset:"UTF-8" });
|
||||
|
||||
fileStream.write(resourcePath.length + ";" + resourcePath + contents);
|
||||
}
|
||||
}, this);
|
||||
|
||||
fileStream.write("e;");
|
||||
|
||||
if (MHTMLContents.length > 0)
|
||||
fileStream.write(MHTMLContents + "*/");
|
||||
|
||||
fileStream.close();
|
||||
});
|
||||
|
||||
@@ -663,10 +699,9 @@ BundleTask.prototype.defineSourceTasks = function()
|
||||
else if (compilerFlags.join)
|
||||
compilerFlags = compilerFlags.join(" ");
|
||||
|
||||
var environments = this.flattenedEnvironments(),
|
||||
flattensSources = this.flattensSources();
|
||||
var flattensSources = this.flattensSources();
|
||||
|
||||
environments.forEach(function(/*Environment*/ anEnvironment)
|
||||
this.environments().forEach(function(/*Environment*/ anEnvironment)
|
||||
{
|
||||
var environmentSources = sources,
|
||||
folder = anEnvironment.name() + ".environment",
|
||||
|
||||
@@ -5,9 +5,8 @@ function Environment(/*String*/ aName)
|
||||
{
|
||||
this._name = aName;
|
||||
this._compilerFlags = [];
|
||||
this._spritesImagesAsMHTML = false;
|
||||
this._spritesImagesAsDataURLs = false;
|
||||
|
||||
this._spritesImages = false;
|
||||
|
||||
environments[aName] = this;
|
||||
}
|
||||
|
||||
@@ -16,18 +15,6 @@ Environment.environmentWithName = function(/*String*/ aName)
|
||||
return environments[aName];
|
||||
}
|
||||
|
||||
Environment.flattenedEnvironments = function(/*Array*/ environments)
|
||||
{
|
||||
var flattenedEnvironments = [];
|
||||
|
||||
environments.forEach(function(/*Environment*/ anEnvironment)
|
||||
{
|
||||
Array.prototype.push.apply(flattenedEnvironments, anEnvironment.flattenedEnvironments());
|
||||
});
|
||||
|
||||
return flattenedEnvironments;
|
||||
}
|
||||
|
||||
Environment.prototype.name = function()
|
||||
{
|
||||
return this._name;
|
||||
@@ -38,11 +25,6 @@ Environment.prototype.toString = function()
|
||||
return this._name;
|
||||
}
|
||||
|
||||
Environment.prototype.flattenedEnvironments = function()
|
||||
{
|
||||
return [this];
|
||||
}
|
||||
|
||||
Environment.prototype.compilerFlags = function()
|
||||
{
|
||||
return this._compilerFlags;
|
||||
@@ -53,29 +35,14 @@ Environment.prototype.setCompilerFlags = function(flags)
|
||||
this._compilerFlags = flags;
|
||||
}
|
||||
|
||||
Environment.prototype.setSpritesImagesAsMHTML = function(/*Boolean*/ shouldSpriteImagesAsMHTML)
|
||||
Environment.prototype.setSpritesImages = function(/*Boolean*/ shouldSpriteImages)
|
||||
{
|
||||
this._spritesImagesAsMHTML = !!shouldSpriteImagesAsMHTML;
|
||||
}
|
||||
|
||||
Environment.prototype.spritesImagesAsMHTML = function()
|
||||
{
|
||||
return this._spritesImagesAsMHTML;
|
||||
}
|
||||
|
||||
Environment.prototype.setSpritesImagesAsDataURLs = function(/*Boolean*/ shouldSpriteImagesAsDataURLs)
|
||||
{
|
||||
this._spritesImagesAsDataURLs = !!shouldSpriteImagesAsDataURLs;
|
||||
}
|
||||
|
||||
Environment.prototype.spritesImagesAsDataURLs = function()
|
||||
{
|
||||
return this._spritesImagesAsDataURLs;
|
||||
this._spritesImages = !!shouldSpriteImages;
|
||||
}
|
||||
|
||||
Environment.prototype.spritesImages = function()
|
||||
{
|
||||
return this.spritesImagesAsMHTML() || this.spritesImagesAsDataURLs();
|
||||
return this._spritesImages;
|
||||
}
|
||||
|
||||
exports.Environment = Environment;
|
||||
@@ -91,36 +58,6 @@ exports.CommonJS = CommonJS;
|
||||
var Browser = new Environment("Browser");
|
||||
|
||||
Browser.setCompilerFlags(["-DPLATFORM_BROWSER", "-DPLATFORM_DOM"]);
|
||||
//Browser.setSpritesImagesAsDataURLs(true);
|
||||
Browser.setSpritesImages(true);
|
||||
|
||||
exports.Browser = Browser;
|
||||
|
||||
function EnvironmentCollection(/*String*/ aName, /*Array*/ environments)
|
||||
{
|
||||
this._name = aName;
|
||||
this._environments = environments;
|
||||
|
||||
environments[aName] = this;
|
||||
}
|
||||
|
||||
EnvironmentCollection.prototype.name = function()
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
EnvironmentCollection.prototype.toString = function()
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
EnvironmentCollection.prototype.flattenedEnvironments = function()
|
||||
{
|
||||
var environments = [];
|
||||
|
||||
this._environments.forEach(function(anEnvironment)
|
||||
{
|
||||
Array.prototype.push.apply(environments, anEnvironment.flattenedEnvironments());
|
||||
});
|
||||
|
||||
return environments;
|
||||
}
|
||||
Reference in new issue
Block a user