Skip to content

Commit

Permalink
0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scniro committed Apr 27, 2016
1 parent e555884 commit fdaf9b5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
37 changes: 22 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,24 @@ function TemplateEngine() {
set: function (transformed) {
var deferred = new Promise(function (resolve, reject) {

var parts = transformed.contents.split(/(?=templateUrl)(?!,)/g);
try {
var parts = transformed.contents.split(/(?=templateUrl)(?!,)/g);

parts.forEach(function (element, index, arr) {
if (parts.length === 1)
throw 'unable to set template: no templateUrl clause';

var match = (element.match(/(?!,)templateUrl(.*)$/gm));
parts.forEach(function (element, index, arr) {

if (match)
arr[index] = arr[index].replace(/(?!,)templateUrl(.*)(?!,)$/gm, 'template: \'' + transformed.templates.shift().replace(/'/g, "\\'") + '\',')
});
var match = (element.match(/(?!,)templateUrl(.*)$/gm));

if (match)
arr[index] = arr[index].replace(/(?!,)templateUrl(.*)(?!,)$/gm, 'template: \'' + transformed.templates.shift().replace(/'/g, "\\'") + '\',')
});

resolve(parts.join(''));
resolve(parts.join(''));
} catch (err) {
reject(err)
}
});

return deferred;
Expand All @@ -160,13 +167,13 @@ function TemplateManager() {
engine.config.set(config);
}

var base, css;
var base, js;

function run(css) {
engine.templates.get(css).then(function (transformed) {
function run(js) {
engine.templates.get(js).then(function (transformed) {
engine.templates.set(transformed).then(function (output) {
done(null, output); // -- out
}, function(err){
}, function (err) {
done(err) // -- templates.set promise error
});
}, function (err) {
Expand All @@ -176,13 +183,13 @@ function TemplateManager() {

if (input instanceof Buffer) {
base = '/' + path.dirname(path.relative(__dirname, config.target));
css = engine.source.hash(input.toString(), base);
run(css);
js = engine.source.hash(input.toString(), base);
run(js);
} else {
engine.source.read(input).then(function (data) {
base = path.dirname(input);
css = engine.source.hash(data, base);
run(css);
js = engine.source.hash(data, base);
run(js);
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-tpl2js",
"version": "0.0.9",
"version": "0.0.10",
"description": "Convert Angular templates to inline JavaScript",
"files": [
"index.js"
Expand All @@ -22,9 +22,9 @@
"vinyl": "^1.1.1"
},
"dependencies": {
"async": "^1.5.2",
"async": "^2.0.0-rc.3",
"cheerio": "^0.20.0",
"html-minifier": "^1.2.0"
"html-minifier": "^2.1.0"
},
"scripts": {
"test": "gulp test"
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ describe('tpl2js: engine', function () {
done();
});
});

it('should gracefully abort on error encountered when setting a template - error exist', function (done) {

var js = new File({
path: '/nomatter',
contents: new Buffer('this doesn\'t seem right!')
});

tpl2js.inline(js.contents, {target: '/nomatter'}, function (err, actual) {
expect(err).to.exist && expect(err).to.equal('unable to set template: no templateUrl clause')
done();
});
});
});

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

0 comments on commit fdaf9b5

Please sign in to comment.