Skip to content

Instantly share code, notes, and snippets.

@mauritslamers
Created February 15, 2011 21:10
Show Gist options
  • Select an option

  • Save mauritslamers/828248 to your computer and use it in GitHub Desktop.

Select an option

Save mauritslamers/828248 to your computer and use it in GitHub Desktop.

Revisions

  1. mauritslamers created this gist Feb 15, 2011.
    80 changes: 80 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    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;
    finisher();
    }
    }
    };

    that.urlPrefix = '../';
    sharedHandlers.urlPrefix = that.urlPrefix;

    for(i=0,len=that.frameworks.length;i<len;i+=1){
    parseFw(that.frameworks[i]);
    }