Put MHTML contents into .sj.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I committed 2009-11-09 13:57:00 +01:00
1 parent 0c24a60bac
commit 11b881273e
3 files changed
+44 -85

No files matched your search

@@ -317,11 +317,6 @@ 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", this.productName() + ".mhtml");
}
BundleTask.prototype.defineTasks = function()
{
this.defineResourceTasks();
@@ -329,7 +324,6 @@ BundleTask.prototype.defineTasks = function()
this.defineInfoPlistTask();
this.defineLicenseTask();
this.defineStaticTask();
this.defineMHTMLTask();
CLEAN.include(this.buildIntermediatesProductPath());
CLOBBER.include(this.buildProductPath());
@@ -444,9 +438,6 @@ BundleTask.prototype.defineResourceTask = function(aResourcePath, aDestinationPa
FILE.write(spritedDestinationPath, base64.encode(FILE.read(aResourcePath, { mode : 'b'})), { charset:"UTF-8" });
});
if (anEnvironment.spritesImagesToMHTMLFile())
filedir (this.buildProductMHTMLPathForEnvironment(anEnvironment), [spritedDestinationPath]);
// Add this as a dependency unconditionally because we need to set up the URL map either way.
filedir (this.buildProductStaticPathForEnvironment(anEnvironment), [spritedDestinationPath]);
}, this);
@@ -569,7 +560,8 @@ BundleTask.prototype.defineStaticTask = function()
{
print("Creating static file... " + staticPath);
var fileStream = FILE.open(staticPath, "w+", { charset:"UTF-8" });
var fileStream = FILE.open(staticPath, "w+", { charset:"UTF-8" }),
MHTMLContents = "";
fileStream.write("@STATIC;1.0;");
@@ -601,16 +593,28 @@ BundleTask.prototype.defineStaticTask = function()
{
fileStream.write("u;");
if (anEnvironment.spritesImagesToStaticFile())
contents += "data:" + mimeType(aFilename) + ";base64," + FILE.read(aFilename, { charset:"UTF-8" });
else if (anEnvironment.spritesImagesToMHTMLFile())
contents = "mhtml:" + FILE.join(folder, productName + ".mhtml!") + resourcePath;
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" });
}
@@ -618,6 +622,11 @@ BundleTask.prototype.defineStaticTask = function()
}
}, this);
fileStream.write("e;", { charset:"UTF-8" });
if (MHTMLContents.length > 0)
fileStream.write(MHTMLContents + "*/", { charset:"UTF-8" });
fileStream.close();
});
@@ -625,59 +634,6 @@ BundleTask.prototype.defineStaticTask = function()
}, this);
}
BundleTask.prototype.defineMHTMLTask = function()
{
var environments = this.flattenedEnvironments();
if (!environments.some(function(anEnvironment)
{
return anEnvironment.spritesImagesToMHTMLFile();
}))
return;
environments.filter(function(/*Environment*/ anEnvironment)
{
return anEnvironment.spritesImagesToMHTMLFile();
}).forEach(function(/*Environment*/ anEnvironment)
{
var folder = anEnvironment.name() + ".environment",
resourcesPath = FILE.join(this.buildIntermediatesProductPath(), folder, "Resources", ""),
MHTMLPath = this.buildProductMHTMLPathForEnvironment(anEnvironment);
filedir (MHTMLPath, function(aTask)
{
print("Creating MHTML file... " + MHTMLPath);
var fileStream = FILE.open(MHTMLPath, "w+", { charset:"UTF-8" });
fileStream.write("/*\r\nContent-Type: multipart/related; boundary=\"_ANY_STRING_WILL_DO_AS_A_SEPARATOR\"\r\n\r\n");
aTask.prerequisites().forEach(function(aFilename)
{
// Our prerequisites will contain directories due to filedir.
if (!isImage(aFilename))
return;
var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename);
fileStream.write("--_ANY_STRING_WILL_DO_AS_A_SEPARATOR\r\n");
fileStream.write("Content-Location:" + resourcePath + "\r\nContent-Transfer-Encoding:base64\r\n\r\n");
var contents = FILE.read(aFilename, { charset:"UTF-8" });
fileStream.write(contents);
fileStream.write("\r\n");
}, this);
fileStream.write("*/");
fileStream.close();
});
this.enhance([MHTMLPath]);
}, this);
}
BundleTask.prototype.defineSourceTasks = function()
{
var sources = this.sources();
@@ -5,8 +5,8 @@ function Environment(/*String*/ aName)
{
this._name = aName;
this._compilerFlags = [];
this._spritesImagesToMHTMLFile = false;
this._spritesImagesToStaticFile = false;
this._spritesImagesAsMHTML = false;
this._spritesImagesAsDataURLs = false;
environments[aName] = this;
}
@@ -53,29 +53,29 @@ Environment.prototype.setCompilerFlags = function(flags)
this._compilerFlags = flags;
}
Environment.prototype.setSpritesImagesToMHTMLFile = function(/*Boolean*/ shouldSpriteImagesToMHTMLFile)
Environment.prototype.setSpritesImagesAsMHTML = function(/*Boolean*/ shouldSpriteImagesAsMHTML)
{
this._spritesImagesToMHTMLFile = !!shouldSpriteImagesToMHTMLFile;
this._spritesImagesAsMHTML = !!shouldSpriteImagesAsMHTML;
}
Environment.prototype.spritesImagesToMHTMLFile = function()
Environment.prototype.spritesImagesAsMHTML = function()
{
return this._spritesImagesToMHTMLFile;
return this._spritesImagesAsMHTML;
}
Environment.prototype.setSpritesImagesToStaticFile = function(/*Boolean*/ shouldSpriteImagesToStaticFile)
Environment.prototype.setSpritesImagesAsDataURLs = function(/*Boolean*/ shouldSpriteImagesAsDataURLs)
{
this._spritesImagesToStaticFile = !!shouldSpriteImagesToStaticFile;
this._setSpritesImagesAsDataURLs = !!shouldSpriteImagesAsDataURLs;
}
Environment.prototype.spritesImagesToStaticFile = function()
Environment.prototype.spritesImagesAsDataURLs = function()
{
return this._spritesImagesToStaticFile;
return this._spritesImagesAsDataURLs;
}
Environment.prototype.spritesImages = function()
{
return this.spritesImagesToMHTMLFile() || this.spritesImagesToStaticFile();
return this.spritesImagesAsMHTML() || this.spritesImagesAsDataURLs();
}
exports.Environment = Environment;
@@ -91,21 +91,21 @@ exports.CommonJS = CommonJS;
var W3C = new Environment("W3C");
W3C.setCompilerFlags(["-DPLATFORM_BROWSER", "-DPLATFORM_DOM"]);
W3C.setSpritesImagesToStaticFile(true);
W3C.setSpritesImagesAsDataURLs(true);
exports.W3C = W3C;
var IE7 = new Environment("IE7");
IE7.setCompilerFlags(["-DPLATFORM_BROWSER", "-DPLATFORM_DOM"]);
IE7.setSpritesImagesToMHTMLFile(true);
IE7.setSpritesImagesAsMHTML(true);
exports.IE7 = IE7;
var IE8 = new Environment("IE8");
IE8.setCompilerFlags(["-DPLATFORM_BROWSER", "-DPLATFORM_DOM"]);
IE8.setSpritesImagesToStaticFile(true);
IE8.setSpritesImagesAsDataURLs(true);
exports.IE8 = IE8;
+7 -4
View File
@@ -69,14 +69,17 @@ objj_markedStream.prototype.getMarker = function()
if (location >= string.length)
return NULL;
var next = string.indexOf(';', location);
if (next < 0)
return NULL;
var marker = string.substring(location, next);
if (marker === 'e')
return NULL;
this._location = next + 1;
return marker;