Skip to content

Commit

Permalink
add htmlclean support
Browse files Browse the repository at this point in the history
  • Loading branch information
vwochnik committed Nov 16, 2017
1 parent 9bcd88b commit 7672952
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"README.md"
],
"dependencies": {
"htmlclean": "^3.0.3",
"lodash": "^4.9.0",
"lodash-es": "^4.9.0",
"rollup-pluginutils": "^1.3.1"
Expand Down
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { extname } from 'path';
import { createFilter } from 'rollup-pluginutils';

import template from 'lodash/template';
import htmlclean from 'htmlclean';


export default function( options = {} ) {
Expand All @@ -11,6 +12,10 @@ export default function( options = {} ) {

const templateOptions = options.templateOptions || { variable: 'data' };

const useHtmlclean = options.htmlclean || false;

const htmlcleanOptions = options.htmlcleanOptions || { };

return {
transform( code, id ) {
if ( !filter( id ) ) {
Expand All @@ -21,6 +26,10 @@ export default function( options = {} ) {
return null;
}

if ( useHtmlclean ) {
code = htmlclean(code, htmlcleanOptions);
}

const tpl = template( code, templateOptions );

let hasEscape = false;
Expand Down
3 changes: 3 additions & 0 deletions test/sample/c.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div >
<p> <%= data %></p >
</div>
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ describe( 'rollup-plugin-jst', () => {
plugins: [ jst() ]
}).then( executeBundle );
});

it( 'compiles a component - htmlclean', () => {
return rollup({
entry: 'sample/c.ejs',
plugins: [ jst({ htmlclean: true }) ]
}).then( executeBundle );
});
});

0 comments on commit 7672952

Please sign in to comment.