angular-tpl2js
Advanced tools
Comparing version 0.0.4 to 0.0.5
69
index.js
@@ -18,9 +18,23 @@ var async = require('async'); | ||
function merge(obj1, obj2) { | ||
var obj3 = {}; | ||
for (var attrname in obj1) { | ||
obj3[attrname] = obj1[attrname]; | ||
} | ||
for (var attrname in obj2) { | ||
obj3[attrname] = obj2[attrname]; | ||
} | ||
return obj3; | ||
} | ||
function embedIncludes(template, source) { | ||
var $ = cheerio.load(template, {decodeEntities: false}); | ||
var ele = $('[ng-include]').first(); | ||
var src = path.dirname(source) + '/' + ($(ele).attr('ng-include') || $(ele).attr('src')).replace(/"/g, '').replace(/'/g, '').trim(); | ||
var include = fs.readFileSync(src, 'utf8'); | ||
$(ele).append(include); | ||
$('[ng-include]').each(function (i, ele) { | ||
var src = path.dirname(source) + '/' + ($(ele).attr('ng-include') || $(ele).attr('src')).replace(/"/g, '').replace(/'/g, '').trim(); | ||
var include = fs.readFileSync(src, 'utf8'); | ||
$(ele).append(include); | ||
}); | ||
return $.html(); | ||
@@ -34,3 +48,10 @@ } | ||
set: function (config) { | ||
var HTMLMinifier = { | ||
collapseWhitespace: true, | ||
removeComments: true | ||
} | ||
_config = config || {}; | ||
_config.HTMLMinifier = merge(HTMLMinifier, (config.HTMLMinifier || {})); | ||
} | ||
@@ -74,16 +95,20 @@ } | ||
results.forEach(function (element, index, arr) { | ||
if (err) | ||
reject('template not found: ' + err.path); | ||
else { | ||
results.forEach(function (element, index, arr) { | ||
var t, $ = cheerio.load(element, {decodeEntities: false}); | ||
var t, $ = cheerio.load(element, {decodeEntities: false}); | ||
if ($($.html()).find('[ng-include]').length > 0 && _config.includes) { | ||
t = embedIncludes($.html(), source.templates[index]) | ||
} | ||
if ($($.html()).find('[ng-include]').length > 0 && _config.includes) { | ||
t = embedIncludes($.html(), source.templates[index]) | ||
} | ||
var template = minify((t || $.html()), {collapseWhitespace: true, removeComments: true}) // minify the markup | ||
source.templates[index] = template | ||
var template = minify((t || $.html()), _config.HTMLMinifier) // minify the markup | ||
source.templates[index] = template | ||
resolve(source); | ||
}); | ||
resolve(source); | ||
}); | ||
resolve(source); | ||
} | ||
}); | ||
@@ -104,3 +129,3 @@ }); | ||
if (match) | ||
arr[index] = arr[index].replace(/(?!,)templateUrl(.*),$/gm, 'template: \'' + transformed.templates.shift().replace(/'/g, "\\'") + '\',') | ||
arr[index] = arr[index].replace(/(?!,)templateUrl(.*)(?!,)$/gm, 'template: \'' + transformed.templates.shift().replace(/'/g, "\\'") + '\',') | ||
}); | ||
@@ -116,9 +141,7 @@ | ||
// TODO - solve pathing weirdness | ||
// TODO - refine poor regex check | ||
// TODO - relay options to html-minifier | ||
// TODO - identify failure points and return error through callbacks | ||
// TODO - refine templating for ng-include support | ||
// TODO - pathing madness | ||
// TODO - refine templateUrl regex check | ||
// TODO - identify failure points and return errors | ||
// TODO - recurse deeply nested ng-include templates | ||
// TODO - README | ||
// TODO - cli | ||
@@ -152,4 +175,6 @@ function TemplateManager() { | ||
engine.templates.set(transformed).then(function (output) { | ||
done(output); // -- out | ||
done(null, output); // -- out | ||
}); | ||
}, function (error) { | ||
done(error); | ||
}); | ||
@@ -156,0 +181,0 @@ }); |
{ | ||
"name": "angular-tpl2js", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Convert Angular templates to inline JavaScript", | ||
@@ -5,0 +5,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8171
139