Giter VIP home page Giter VIP logo

node-jstc's People

Contributors

vphantom avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

node-jstc's Issues

Add more tests to suite

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.

Handle each file as a glob

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.

Document jstc.getObject()

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?

Add helper library to templates

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.

Sub-templates

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:

  • Gather sub-templates while removing them entirely from the source string;
  • Invoke the compiler for each gathered sub-template, in which case the argument becomes its;
  • Invoke the compiler on the main source string and inject the sub-template functions after vars and before statements.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.