From 1b84f81b1ef5bc64349046c0ab8458abe33caef0 Mon Sep 17 00:00:00 2001 From: riffle Date: Wed, 10 May 2017 18:01:34 -0700 Subject: [PATCH 1/3] Include more options to pass to EJS * Increment version number * Update README with new flag support --- .gitignore | 2 +- Readme.md | 102 +++++++++++++++++++++++++----------------------- bin/ejs-compile | 18 ++++++--- package.json | 42 ++++++++++---------- 4 files changed, 88 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index 08b2553..3c3629e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -node_modules +node_modules diff --git a/Readme.md b/Readme.md index 02a9538..ffb9cb5 100644 --- a/Readme.md +++ b/Readme.md @@ -1,49 +1,53 @@ -# ejs-compile - -Pre-compile [ejs](https://github.com/visionmedia/ejs) templates. - -## Installation - -```bash -$ npm install ejs-compile -``` - -## Usage - -``` -Usage: ejs-compile [file|dir] [options] - -Options: - - -h, --help output usage information - -V, --version output the version number - -w, --watch Watch file(s) for changes and re-compile - -o, --out [dir] Output to [dir] when passing files - --min Do some (unsafe) pre minification that minifiers usually can't do. - --debug -``` - -## License - -(The MIT License) - -Copyright (c) 2009-2010 Jonnathan Soares <jonnsl@hotmail.com> - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# ejs-compile + +Pre-compile [ejs](https://github.com/visionmedia/ejs) templates. + +## Installation + +```bash +$ npm install ejs-compile +``` + +## Usage + +``` +Usage: ejs-compile [file|dir] [options] + +Options: + + -h, --help output usage information + -V, --version output the version number + -w, --watch Watch file(s) for changes and re-compile + -o, --out [dir] Output to [dir] when passing files. + --strict When set, generated function is in strict mode + --cache Compiled functions are cached + --usewith Whether or not to use with() {} constructs. If false then the locals will be stored in the locals object. Set to false in strict mode. Default false. + --rmWhitespace Remove all safe-to-remove whitespace, including leading and trailing whitespace. It also enables a safer version of -%> line slurping for all scriptlet tags (it does not strip new lines of tags in the middle of a line) + --min Do some (unsafe) pre minification that minifiers usually can't do. + --debug +``` + +## License + +(The MIT License) + +Copyright (c) 2009-2010 Jonnathan Soares <jonnsl@hotmail.com> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/bin/ejs-compile b/bin/ejs-compile index a7ead33..f7721c2 100755 --- a/bin/ejs-compile +++ b/bin/ejs-compile @@ -19,7 +19,11 @@ program .option('-w, --watch', 'Watch file(s) for changes and re-compile') .option('-o, --out [dir]', 'Output to [dir] when passing files') .option('--min', 'Do some (unsafe) pre minification that minifiers usually can\'t do.') - .option('--debug', '') + .option('--debug', 'Output generated function body') + .option('--strict', 'When set to true, generated function is in strict mode') + .option('--cache', 'Compiled functions are cached, requires filename') + .option('--usewith', 'Whether or not to use with() {} constructs. If false then the locals will be stored in the locals object. Set to false in strict mode.') + .option('--rmWhitespace', 'Remove all safe-to-remove whitespace, including leading and trailing whitespace. It also enables a safer version of -%> line slurping for all scriptlet tags (it does not strip new lines of tags in the middle of a line)') .parse(process.argv); var run = program.watch ? watch : compile; @@ -81,12 +85,16 @@ function compile(file) { if (err) return abort(err); var contents = buf.toString('utf8'); - var fn = ejs.compile(contents, { - //resolveInclude: false, + var options = { client: true, + filename: path.join(process.cwd(), file), compileDebug: program.debug === true, - filename: path.join(process.cwd(), file) - }); + strict: program.strict === true, + cache: program.cache === true, + _with: program.usewith === true, + rmWhitespace: program.rmWhitespace === true, + } + var fn = ejs.compile(contents, options); var data = fn.toString().split('\n'); data.splice(0, 1, data[0].replace(/^function anonymous/, 'module.exports = function '+ escape(basename))); diff --git a/package.json b/package.json index 9af7f6d..470c6f1 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,21 @@ -{ - "name": "ejs-compile", - "description": "Pre-compile ejs templates.", - "version": "0.0.1", - "author": { - "name": "Jonnathan Soares", - "email": "jonnsl@hotmail.com" - }, - "dependencies": { - "commander": "*", - "read-dir-files": "*", - "ejs": "*" - }, - "repository": { - "type": "git", - "url": "https://github.com/jonnsl/ejs-compile" - }, - "bin": { - "ejs-compile": "./bin/ejs-compile" - } -} +{ + "name": "ejs-compile", + "description": "Pre-compile ejs templates.", + "version": "0.0.2", + "author": { + "name": "Jonnathan Soares", + "email": "jonnsl@hotmail.com" + }, + "dependencies": { + "commander": "*", + "read-dir-files": "*", + "ejs": "*" + }, + "repository": { + "type": "git", + "url": "https://github.com/jonnsl/ejs-compile" + }, + "bin": { + "ejs-compile": "./bin/ejs-compile" + } +} From 86eea45d0907b5ede349b911c8f57cfe6658bf83 Mon Sep 17 00:00:00 2001 From: riffle Date: Wed, 10 May 2017 18:21:17 -0700 Subject: [PATCH 2/3] Remove filters --- bin/ejs-compile | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/ejs-compile b/bin/ejs-compile index f7721c2..1c1a56b 100755 --- a/bin/ejs-compile +++ b/bin/ejs-compile @@ -98,7 +98,6 @@ function compile(file) { var data = fn.toString().split('\n'); data.splice(0, 1, data[0].replace(/^function anonymous/, 'module.exports = function '+ escape(basename))); - data.splice(2, 0, 'filters = filters || require(\'./filters.js\');'); if (program.out) { fs.writeFile( From 7d181673b8e6f8d4d6861529a09ac734282a5abc Mon Sep 17 00:00:00 2001 From: riffle Date: Wed, 10 May 2017 18:23:31 -0700 Subject: [PATCH 3/3] Increment version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 470c6f1..bdb4813 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ejs-compile", "description": "Pre-compile ejs templates.", - "version": "0.0.2", + "version": "0.0.3", "author": { "name": "Jonnathan Soares", "email": "jonnsl@hotmail.com"