Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-tpl2js

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-tpl2js - npm Package Compare versions

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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc