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

broccoli-html2js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-html2js - npm Package Compare versions

Comparing version 0.0.2 to 0.0.4

lib/html2js.js

91

index.js
'use strict';
var EXTENSIONS = ['html'];
var Writer = require('broccoli-writer'),
_HTML2JS = require('./lib/html2js');
var Writer = require('broccoli-writer'),
HTMLmin = require('html-minifier'),
fs = require('fs'),
helpers = require('broccoli-kitchen-sink-helpers'),
mkdirp = require('mkdirp'),
path = require('path');
var Utils = {
/**
* moduleTemplate
*
* @param {String} name
* @param {Array} dependencies
*
* @return {String}
*/
moduleTemplate: function (name, dependencies) {
return 'angular.module("' + name + '",'
+ '[' + (dependencies || []).map(function (e) { return '\'' + e + '\'' }).join(',') + ']'
+ ');';
},
/**
* template
*
* @param {String} name
* @param {String} content
*
* @return {String}
*/
template: function (name, content) {
return 'angular.module("' + name + '", []).run(["$templateCache", function ($templateCache) {'
+ '$templateCache.put("' + name + '", ' + content + ');'
+ '}]);';
},
/**
* minify
*
* @param {String} html
* @param {Object} content
*
* @return {String}
*/
minify: function (html, options) {
var content = HTMLmin.minify(html, options.htmlmin || {})
.replace(/'/g, '\\\'')
.replace(/"/g, '\\"');
return '\'' + content + '\'';
}
};
/**

@@ -75,4 +22,8 @@ * HTML2JS

this.options = options || {};
this.inputFiles = this.options.inputFiles || {};
this.outputFile = this.options.outputFile || {};
this.inputFiles = this.options.inputFiles || [];
this.outputFile = this.options.outputFile || '';
this.singleModule = this.options.singleModule || false;
this.module = this.options.module || '';
_HTML2JS.validate(this.options);
}

@@ -93,27 +44,3 @@

return readTree(this.inputTree).then(function (srcDir) {
helpers.assertAbsolutePaths([this.outputFile]);
var destPathDir = path.join(destDir, path.dirname(this.outputFile)),
destPathFile = path.join(destDir, this.outputFile),
files = helpers.multiGlob(this.inputFiles, {cwd: srcDir});
files = (files || []).filter(function (file) {
return typeof (file) === 'string' && ~EXTENSIONS.indexOf(file.split('.').pop());
}.bind(this));
mkdirp.sync(destPathDir);
if (this.options.module) {
fs.appendFileSync(destPathFile, Utils.moduleTemplate(this.options.module, files));
}
files.forEach(function (filePath) {
var _filePath = (typeof this.options.replace === 'function')
? this.options.replace.call(null, filePath)
: filePath,
content = Utils.minify(fs.readFileSync(srcDir + '/' + filePath, {encoding: 'utf8'}), this.options);
fs.appendFileSync(destPathFile, Utils.template(_filePath, content));
}.bind(this));
_HTML2JS.generate(this, srcDir, destDir);
}.bind(this));

@@ -120,0 +47,0 @@ };

{
"name": "broccoli-html2js",
"description": "",
"version": "0.0.2",
"author": "Alexander Tarasyuk <alexander.v.tarasyuk@gmail.com>",
"description": "Converts AngularJS templates to JavaScript",
"version": "0.0.4",
"author": {
"name": "Alexander Tarasyuk",
"email": "alexander.v.tarasyuk@gmail.com"
},
"main": "index.js",

@@ -16,3 +19,4 @@ "license": "MIT",

"broccoli-writer": "^0.1.1",
"broccoli-kitchen-sink-helpers": "^0.2.0"
"broccoli-kitchen-sink-helpers": "^0.2.0",
"jade": "^1.3.1"
},

@@ -23,3 +27,7 @@ "keywords": [

"angularjs"
]
}
],
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/a-tarasyuk/broccoli-html2js/issues"
}
}

@@ -5,22 +5,64 @@ # broccoli-html2js

#### Installation
```js
### Installation
```shell
nmp install broccoli-html2js
```
#### Example
### Options
#### inputFiles
Type: `Array`
Default: `[]`
Source files (supports `html`, `jade`)
#### outputFile
Type: `String`
Default: `''`
Output file (supports `js`, `coffee`)
#### replace
Type: `Function`
Default: `undefined`
Function that will apply for each filepath
```js
replace: function (filepath) {
return filepath.replace(/\.jade/g, '.html');
}
```
#### module
Type: `String`
Default: `''`
Parent module name
#### singleModule
Type: `Boolean`
Default: `false`
Wraps all templates in a single module.
#### htmlmin
Type: `Object`
Default: `{}`
See more options on https://github.com/kangax/html-minifier
### Example
```js
templates = html2js(tree, {
module: 'Bookmarks.views', // optional
replace: function (path) { // optional
return path;
},
htmlmin: {}, // optional (see more options on https://github.com/kangax/html-minifier)
inputFiles: ['*.html'], // required
outputFile: '/templates.js' // required
inputFiles: ['*.html', '*.jade'],
outputFile: '/templates.js' // or templates.coffee
});
```
#### Options
...
### Release History
0.0.4 - Updated Readme
#### Todo
...
0.0.3 - Add support for CoffeeScript, Jade, option `singleModule` (for placing all templates in a single module).
0.0.2 - Small changes
0.0.1 - Init project
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