vphantom / node-jstc Goto Github PK
View Code? Open in Web Editor NEWLightweight, non-sandboxing JSP-ish template compiler
License: MIT License
Lightweight, non-sandboxing JSP-ish template compiler
License: MIT License
While we have coverage, we aren't robustly testing the potential contents of templates and how mistakes are handled.
We should also make cli.js
exit non-zero when some templates failed at compile-time.
We need to read files asynchronously in order to play nice with server environments.
Our caller lists all files for us. Instead, and backwards-compatibly, we should treat each file as a glob to allow something like:
jstc 'templates/*.jst' 'plugins/*/templates/*.jst'
The difference for the command-line tool is negligible, but it will allow server use down the line.
A server would initialize with something like:
var render = {};
jstc.getObject(
['templates/*.jst','plugins/*/templates/*.jst'],
function(err, newRender) {
if (!err) {
render = newRender;
};
});
This allows long-running processes to recompile templates at any time, with the option to keep the in-memory version if something goes wrong.
Without promises/coroutines, this makes it difficult to block code that needs render
to be populated to function properly, in the initial compilation. I guess a server would outright fail to start on an initial compilation error, and complete its startup inside the callback?
It would be nice if, in addition to it
, templates had a shortcut to access a variety of utility functions, most provided by users and not by jstc itself, such as HTML encoding (which was handled as a special case in doT.js).
We should use this
as a reference to render._lib
which could contain misc constants and functions.
doT.js calls these "partials". This is a special syntax for creating several templates within a single file. To achieve this cleanly, we should introduce a pre-processor ahead of jstc.compile()
and implement a first pair of directives define
and end
:
<p>content...</p>
<%@define foo %>
<p>Sub-template! Name is: <%= its.name %></p>
<%@end %>
<p>And here, content refers to it locally:</p>
<%= foo({name: 'first'}) %>
<%= foo({name: 'second'}) %>
This should be structured so that foo() is private to the template (and sibling sub-templates).
The pre-processor, in this case, would:
its
;A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.