Skip to content

Commit

Permalink
coverage, climate
Browse files Browse the repository at this point in the history
  • Loading branch information
scniro committed Apr 11, 2016
1 parent 3894600 commit 1784f34
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
44 changes: 17 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ function TemplateEngine() {

function merge(obj1, obj2) {
var obj3 = {};
for (var attrname in obj1) {
obj3[attrname] = obj1[attrname];
for (var a1 in obj1) {
obj3[a1] = obj1[a1];
}
for (var attrname in obj2) {
obj3[attrname] = obj2[attrname];
for (var a2 in obj2) {
obj3[a2] = obj2[a2];
}
return obj3;
}
Expand Down Expand Up @@ -135,11 +135,6 @@ function TemplateEngine() {
}
}

// TODO - pathing madness
// TODO - refine templateUrl regex check
// TODO - identify failure points and return errors
// TODO - recurse deeply nested ng-include templates

function TemplateManager() {

var self = this;
Expand All @@ -149,38 +144,33 @@ function TemplateManager() {
engine = new TemplateEngine();

// shift optional config argument
if(arguments.length === 2 && Object.prototype.toString.call(arguments[1]) == '[object Function]') {
if (arguments.length === 2 && Object.prototype.toString.call(arguments[1]) === '[object Function]') {
done = config;
} else {
engine.config.set(config);
}

// more robust gulp check mayhaps?
if (typeof input === 'object') {

var base = '/' + path.dirname(path.relative(__dirname, config.target));
var source = engine.source.hash(input.toString(), base);
var base, css;

engine.templates.get(source).then(function (transformed) {
function run(css) {
engine.templates.get(css).then(function (transformed) {
engine.templates.set(transformed).then(function (output) {
done(null, output); // -- out
});
}, function (error) {
done(error);
});
}

if (input instanceof Buffer) {
base = '/' + path.dirname(path.relative(__dirname, config.target));
css = engine.source.hash(input.toString(), base);
run(css);
} else {
engine.source.read(input).then(function (data) {

var base = path.dirname(input);
var source = engine.source.hash(data, base);

engine.templates.get(source).then(function (transformed) {
engine.templates.set(transformed).then(function (output) {
done(null, output); // -- out
});
}, function (error) {
done(error);
});
base = path.dirname(input);
css = engine.source.hash(data, base);
run(css);
});
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var engine = require('..').engine;
var expect = chai.expect;
var path = require('path');
var tpl2js = require('..');
var File = require('vinyl');
var fs = require('fs');

chai.should();

Expand Down Expand Up @@ -254,6 +256,22 @@ describe('tpl2js: engine', function () {
done();
});
});

it('should execute logic regarded to buffer check', function () {

var i = 0;

var js = new File({
path: '/nomatter',
contents: new Buffer('angular.module(\'mod\').directive(\'dir\', function () { return { scope: {}, templateUrl: \'templates/ng.template.basic.html\', link: function (scope, elem, attrs) { } } });')
});

tpl2js.inline(js.contents, {target: '/nomatter'}, function (err, actual) {
i += 1;
expect(i).to.equal(1);
done();
});
});
});

describe('tpl2js', function () {
Expand Down

0 comments on commit 1784f34

Please sign in to comment.