Skip to content

Instantly share code, notes, and snippets.

@mauritslamers
Created February 15, 2011 21:19
Show Gist options
  • Save mauritslamers/828264 to your computer and use it in GitHub Desktop.
Save mauritslamers/828264 to your computer and use it in GitHub Desktop.
App.prototype.save = function() {
var that = this,
stylesheets = [],
scripts = [],
fw,i,len,
stylesheet, script, html, savr;
var Saver = function(app, file) {
var that = this;
that.save = function() {
file.handler.handle(file, null, function(r) {
var path;
if (r.data.length > 0) {
path = l.path.join(app.savePath, file.savePath());
File.createDirectory(l.path.dirname(path));
l.fs.writeFile(path, r.data, function(err) {
if (err) throw err;
});
}
});
};
};
var finisher = function(){
stylesheet = new File({
path: that.name + '.css',
framework: that,
handler: sharedHandlers.build(['join']),
children: stylesheets
});
savr = new Saver(that, stylesheet);
savr.save();
script = new File({
path: that.name + '.js',
framework: that,
handler: sharedHandlers.build(['join']),
children: scripts
});
savr = new Saver(that, script);
savr.save();
html.content = this.rootContent(
'<link href="' + that.urlPrefix + stylesheet.url() + '" rel="stylesheet" type="text/css">',
'<script type="text/javascript" src="' + that.urlPrefix + script.url() + '"></script>'
);
savr = new Saver(that, html);
savr.save();
};
var parseFw = function(framework) {
var file, url;
for (url in that.server.files) {
//l.sys.puts('parsing url: ' + url);
file = that.server.files[url];
if (file.framework === framework) {
if (file.isStylesheet()) stylesheets.push(file);
if (file.isScript()) scripts.push(file);
if (file.isResource()) new Saver(that, file).save();
}
if (file.isHtml){
html = file;
}
}
};
that.urlPrefix = '../';
sharedHandlers.urlPrefix = that.urlPrefix;
for(i=0,len=that.frameworks.length;i<len;i+=1){
parseFw(that.frameworks[i]);
}
finisher(); //fails because html is undefined
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment