Skip to content
OnkelHenky edited this page Feb 18, 2011 · 4 revisions

Task ContenType

This task is for check the file extension of the files of framework and attache the correct content-type to each file. The content.typ is used by the m-server process to deliver the file correctly.

Each File object contains function to check the file extension e.g.: '.js','.css','.json' or '.png'.

def foo
  puts 'bar'
end

Task_ContentType = exports.Task_ContentType = function() {

/* Properties */ this.name = 'content type'; this.contentTypes = { ".js" : "text/javascript; charset=utf-8", ".css" : "text/css; charset=utf-8", ".manifest": "text/cache-manifest", ".html" : "text/html", ".png" : "image/png", ".jpg" : "image/jpeg", ".gif" : "image/gif", ".svg" : "image/svg+xml", ".json" : "application/json" }; };

Task_ContentType.prototype.duty = function(framework,callback){ var self = this;

framework.files.forEach(function(cF){ cF.contentType = (self.contentTypes[cF.getFileExtension()]) ? self.contentTypes[cF.getFileExtension()] : 'text/plain';

switch (true) { case (cF.isImage()): cF.requestPath = 'theme/images/'+cF.getBaseName()+cF.getFileExtension(); break; case (cF.isStylesheet()): cF.requestPath = 'theme/'+cF.getBaseName()+cF.getFileExtension(); cF.contentType = "text/css; charset=utf-8"; break; case (cF.isHTML()): cF.requestPath = cF.getBaseName()+cF.getFileExtension(); break; default: cF.requestPath = cF.getBaseName()+cF.getFileExtension(); break; } });

callback(framework); };

Clone this wiki locally