jspreproc
Do you have this?
/** * The exposed tmpl function returns the template value from the cache, render with data. * @param * @param * @returns * @private */ { if !str return str // catch falsy values here //#if DEBUG if data && data_debug_ data_debug_ = 0 if !_cachestr _cachestr = // request debug output var rs = typeof riot === 'undefined' ? '(riot undefined)' : JSON console //#endif // At this point, the expressions must have been parsed, it only remains to construct // the function (if it is not in the cache) and call it to replace expressions with // their values. data (`this`) is a Tag instance, logErr is the error handler. return _cachestr || _cachestr = }// end of _tmpl
And want this?
{ if !str return str return _cachestr || _cachestr = }
Me too. This is why jspreproc, a tiny, C-Style source file preprocessor in JavaScript for JavaScript, with duplicate empty lines and comments remover.
Featuring many of the C preprocessor characteristics through JavaScript comments, jspreproc can be used in any source with a JavaScript-like syntax, even C#
files with some limitations.
Important:
From version 0.2.1-beta.1 the location of jspp.js is the bin folder.
This is work in progress, so please update jspreproc constantly, I hope the first stable version does not take too long.
Install
You can install jspreproc with npm globally to use as the CLI tool, or locally for your project.
jspreproc works in node.js 0.10.0 or above (tested in Windows 7/8, cmd and sh shells).
Command-line
npm -g install jspreproc
jspreproc name for command-line interface is jspp
jspp [options] file1 file2 ...
Multiple files are concatenated into one, as if it had passed a file with multiple #include
directives, one for each of the files listed.
If you don't list files, jspreproc reads from the standard input.
The result is written to the standard output, so it can be redirected.
Find more about the options in the documentation.
node.js
npm install jspreproc
var jspp = var stream =
Parameter files
can be an file name, an array of file names, or an instance of a readable stream. Options is an object with the same options from command-line.
jspp return value is a stream.PassThrough
instance.
You can read about this API in the documentation.
There is a package for bower, too.
Documentation
This is a short example of basic syntax in files prepared for jspreproc:
//#include globals.inc//#set DEBUG = 1 //#ifdef DEBUGconsole//#endif
Find more in the Syntax guide.
Read the CHANGELOG for recent additions and fixes.
You can see jspreproc operation in the tests.
Please note: the documentation is very much a work in progress. Contributions are welcome.
Third-party tools & libraries
The following third-party tools and libraries are used by this project:
For regular use (dependencies installed by npm)
Development and code quality (devDependencies)
- Jasmine by Pivotal Labs, my favorite testing framework, does not rely on other frameworks
- jasmine-spec-reporter by Bastien Caudan, pretty console spec reporter for jasmine
- istanbul by Krishnan Anantheswaran, for generating coverage information
I'd like to thank all.
Known Issues
process.stdout fails (so jspreproc too) on console emulators for Windows, e.g. ConEmu and others, use clean Windows prompt or MSYS with mintty.
TODO
Maybe some day...
-
100% coverage (done) - Configuration from the file system.
.jspreproc.json
? - jspreproc reconfiguration through comments
-
#emit
? for generating output of expression values - Better documentation
- Explanatory error messages