broccoli-html2js
Advanced tools
Comparing version 0.0.2 to 0.0.4
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 |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
10150
7
246
1
68
5
1
+ Addedjade@^1.3.1
+ Addedacorn@1.2.22.7.0(transitive)
+ Addedacorn-globals@1.0.9(transitive)
+ Addedasap@1.0.0(transitive)
+ Addedcharacter-parser@1.2.1(transitive)
+ Addedclean-css@3.4.28(transitive)
+ Addedcommander@2.6.02.8.1(transitive)
+ Addedconstantinople@3.0.2(transitive)
+ Addedcss@1.0.8(transitive)
+ Addedcss-parse@1.0.4(transitive)
+ Addedcss-stringify@1.0.5(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedis-promise@1.0.12.2.2(transitive)
+ Addedjade@1.11.0(transitive)
+ Addedjstransformer@0.0.2(transitive)
+ Addedoptimist@0.3.7(transitive)
+ Addedpromise@2.0.06.1.0(transitive)
+ Addedsource-map@0.1.430.4.4(transitive)
+ Addedtransformers@2.1.0(transitive)
+ Addeduglify-js@2.2.5(transitive)
+ Addedvoid-elements@2.0.1(transitive)
+ Addedwith@4.0.3(transitive)
+ Addedwordwrap@0.0.3(transitive)