Skip to content

Commit

Permalink
Merge 1c0847b into d181229
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Mar 30, 2015
2 parents d181229 + 1c0847b commit e837e49
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
7 changes: 4 additions & 3 deletions lib/compiler.js
Expand Up @@ -66,6 +66,7 @@ function Compiler(directory, pipe, options) {
}

Compiler.prototype.__proto__ = require('eventemitter3').prototype;
Compiler.prototype.asyncemit = require('asyncemit');

/**
* Create the BigPipe base front-end framework that's required for the handling
Expand Down Expand Up @@ -362,10 +363,10 @@ Compiler.prototype.catalog = function catalog(pages, done) {
*/
function register(assemble, next) {
async.each(Object.keys(assemble), function prefix(hash, fn) {
compiler.namespace(assemble[hash], function namespaced(error, file) {
if (error) return fn(error);
compiler.asyncemit('assembly', assemble[hash], function (err) {
if (err) return fn(err);

compiler.register(file);
compiler.register(assemble[hash]);
fn();
});
}, next);
Expand Down
20 changes: 12 additions & 8 deletions lib/file.js
Expand Up @@ -44,7 +44,10 @@ function File(aliases, extname, dependency, code) {
//
// Process the content of the file if provided.
//
if (code) this.set(code);
if (code) {
this.hash = this.encrypt(code);
this.set(code);
}
}

fuse(File, require('eventemitter3'));
Expand All @@ -66,18 +69,19 @@ File.readable('location', {
* Update the content of the file, convert to Buffer if required and update length.
*
* @param {Buffer|String} content Content of the file.
* @param {Boolean} append Add async CSS selector or not
* @returns {File} fluent interface
* @api private
*/
File.readable('set', function set(content, append) {
this.hash = this.encrypt(content);
if (this.is('css') && append) content = this.append(content, this.hash);
File.readable('set', function set(content) {
this.code = content;

//
// Append async loading class to CSS and make sure that the code is a Buffer.
// Append async loading class to CSS
//
this.code = content;
if (this.is('css')) {
content = this.append(content, this.hash);
}

this.buffer = Buffer.isBuffer(content) ? content : new Buffer(content);
this.length = this.buffer.length;

Expand Down Expand Up @@ -107,7 +111,7 @@ File.readable('get', function get(readable) {
File.readable('append', function append(content, hash) {
return [
content,
'#pagelet_',
'#_',
hash || this.hash,
' { height: 42px }'
].join('');
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -15,6 +15,7 @@
"404-pagelet": "1.0.x",
"500-pagelet": "1.0.x",
"async": "0.9.x",
"asyncemit": "1.0.x",
"bigpipe.js": "0.9.x",
"bootstrap-pagelet": "1.0.x",
"browserify": "9.0.x",
Expand Down
8 changes: 2 additions & 6 deletions test/lib/file.test.js
Expand Up @@ -118,11 +118,7 @@ describe('File', function () {
});

it('returns content with selector attached', function () {
assume(file.append(code)).to.equal(code + '#pagelet_' + sha + ' { height: 42px }');
});

it('can be provided with alternative hash', function () {
assume(file.append(code, 'test')).to.equal(code + '#pagelet_test { height: 42px }');
assume(file.append(code)).to.equal(code + '#_' + sha + ' { height: 42px }');
});
});

Expand All @@ -135,4 +131,4 @@ describe('File', function () {
assume(file.location).to.equal('/' + sha + ext);
});
});
});
});

0 comments on commit e837e49

Please sign in to comment.