angular-tpl2js
Advanced tools
Comparing version 0.0.2 to 0.0.3
53
index.js
var async = require('async'); | ||
var engine = new TemplateEngine(); | ||
var fs = require('fs'); | ||
var minify = require('html-minifier').minify; | ||
var path = require('path'); | ||
var cheerio = require('cheerio'); | ||
var engine; | ||
@@ -10,2 +11,3 @@ function TemplateEngine() { | ||
var self = this; | ||
var _config = {}; | ||
@@ -17,2 +19,21 @@ function readAsync(file, callback) { | ||
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); | ||
return $.html(); | ||
} | ||
self.config = { | ||
get: function () { | ||
return _config; | ||
}, | ||
set: function (config) { | ||
_config = config || {}; | ||
} | ||
} | ||
self.source = { | ||
@@ -49,2 +70,3 @@ hash: function (raw, base) { | ||
get: function (source) { | ||
var deferred = new Promise(function (resolve, reject) { | ||
@@ -54,3 +76,12 @@ async.map(source.templates, readAsync, function (err, results) { | ||
results.forEach(function (element, index, arr) { | ||
source.templates[index] = minify(element, {collapseWhitespace: true, removeComments: true}) // minify the markup | ||
var t, $ = cheerio.load(element, {decodeEntities: false}); | ||
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 | ||
resolve(source); | ||
}); | ||
@@ -87,7 +118,7 @@ | ||
// TODO - refine poor regex check | ||
// TODO - identify passed options, likely relayed to html-minifier | ||
// TODO - relay options to html-minifier | ||
// TODO - identify failure points and return error through callbacks | ||
// TODO - recurse templating for ng-include support | ||
// TODO - travis ci | ||
// TODO - refine templating for ng-include support | ||
// TODO - README | ||
// TODO - cli | ||
@@ -98,7 +129,10 @@ function TemplateManager() { | ||
self.inline = function (input, options, done) { // -- in | ||
self.inline = function (input, config, done) { // -- in | ||
if (options.gulp) { | ||
engine = new TemplateEngine(); | ||
engine.config.set(config); | ||
var base = '/' + path.dirname(path.relative(__dirname, options.target)); | ||
// more robust gulp check mayhaps? | ||
if (input.contents) { | ||
var base = '/' + path.dirname(path.relative(__dirname, config.target)); | ||
var source = engine.source.hash(input, base); | ||
@@ -111,3 +145,2 @@ | ||
}); | ||
} else { | ||
@@ -130,2 +163,2 @@ engine.source.read(input).then(function (data) { | ||
module.exports = new TemplateManager(); | ||
module.exports.engine = engine; | ||
module.exports.engine = new TemplateEngine(); |
{ | ||
"name": "angular-tpl2js", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Convert Angular templates to inline JavaScript", | ||
@@ -16,2 +16,5 @@ "files": [ | ||
"chai": "^3.5.0", | ||
"gulp": "^3.9.1", | ||
"gulp-mocha": "^2.2.0", | ||
"gulp-util": "^3.0.7", | ||
"mocha": "^2.4.5" | ||
@@ -21,4 +24,8 @@ }, | ||
"async": "^1.5.2", | ||
"cheerio": "^0.20.0", | ||
"html-minifier": "^1.2.0" | ||
}, | ||
"scripts": { | ||
"test": "gulp test" | ||
} | ||
} |
# angular-tpl2js | ||
> awesomeness coming soon | ||
[![Build Status](https://img.shields.io/travis/scniro/angular-tpl2js.svg?style=flat-square)](https://travis-ci.org/scniro/angular-tpl2js) | ||
[![NPM Version](https://img.shields.io/npm/v/angular-tpl2js.svg?style=flat-square)](https://www.npmjs.com/package/angular-tpl2js) | ||
[![Dependency Status](https://img.shields.io/david/scniro/angular-tpl2js.svg?label=deps&style=flat-square)](https://david-dm.org/scniro/angular-tpl2js) | ||
[![devDependency Status](https://img.shields.io/david/dev/scniro/angular-tpl2js.svg?label=devDeps&style=flat-square)](https://david-dm.org/scniro/angular-tpl2js#info=devDependencies) |
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
7444
119
8
3
5
+ Addedcheerio@^0.20.0
+ Addedabab@1.0.4(transitive)
+ Addedacorn@2.7.0(transitive)
+ Addedacorn-globals@1.0.9(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedboolbase@1.0.0(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcheerio@0.20.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcss-select@1.2.0(transitive)
+ Addedcss-what@2.1.3(transitive)
+ Addedcssom@0.3.8(transitive)
+ Addedcssstyle@0.2.37(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddom-serializer@0.1.1(transitive)
+ Addeddomelementtype@1.3.1(transitive)
+ Addeddomhandler@2.3.0(transitive)
+ Addeddomutils@1.5.1(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedentities@1.0.01.1.2(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhtmlparser2@3.8.3(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjsdom@7.2.2(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addednth-check@1.0.2(transitive)
+ Addednwmatcher@1.4.4(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedparse5@1.5.1(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedsymbol-tree@3.2.4(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwebidl-conversions@2.0.1(transitive)
+ Addedwhatwg-url-compat@0.6.5(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedxml-name-validator@2.0.1(transitive)