
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
An asynchronous ERB-like templating system for node.js
node-asyncEJS implements a templating language for embedding JavaScript into other text documents such as HTML. It adds new features to the classic ERB syntax to enable asynchronous execution of the template.
You can always use the synchronous features. So use it whenever you need a templating solution.
The asynchronous features come in handy when you
<html>
<head>
<% ctx.hello = "World"; %>
<title><%= "Hello " + ctx.hello %></title>
</head>
<body>
<h1><%? setTimeout(function () { res.print("Async Header"); res.finish(); }, 2000) %></h1>
<p><%? setTimeout(function () { res.print("Body"); res.finish(); }, 1000) %></p>
</body>
</html>
var te = require("../lib/asyncEJS").Engine();
te.template("template.t.html", function () {
var templateResponse = template(paras);
templateResponse.addListener("body", function (chunk) {
sys.print(chunk);
});
templateResponse.addListener("complete", function () {
sys.puts("COMPLETE")
});
});
ctx
contains the parameter that was passed to the template function
res
represents the output of the template.
res.print("string")
prints more output into the template
res.finish()
tells the template that the current asynchronous blocks has finished execution
<% var javascript = "code" %>
executes arbitrary JavaScript
<%= "Hello " + ctx.hello %>
outputs the statement result into the template
<%? setTimeout(function () { res.print("Async Header"); res.finish(); }, 2000) %>
<%?
introduces a block that will be expected to execute asynchronously with respect
to the rest of the template. The rest of the template will continue executing but no
output will be returned until the res.finish()
method will be called.
<% res.partial("partial.js.html", { hello: "world" }); %>
`res.partial(filename, paras)
There is currently no escaping of output but this will change.
Construct a template engine with
var te = require("../lib/asyncEJS").Engine({
autoUpdate: false,
templateRoot: '/path/to/templates'
});
If autoUpdate
is true, asyncEJS will continously look for changes in templates and
automatically update them when they change on disk.
templateRoot
is a directory where templates will be served from. If omitted, templates
will be served from the current working directory.
After you instantiated a template engine use the template
method to create a template
function.
te.template("template.t.html", function (template) { ... });
Executing the template function with paras
will return a templateResponse. The paras
are
accessible as ctx
variable inside the template.
var templateResponse = template(paras);
The template response emits two events body
and complete
templateResponse.addListener("body", function (chunk) {
sys.print(chunk);
});
templateResponse.addListener("complete", function () {
sys.puts("COMPLETE")
});
body
is emitted whenever a part of the template has been completed.
complete
will fire once when the template has fully executed.
See examples/
and test/
FAQs
Unknown package
The npm package asyncEJS receives a total of 0 weekly downloads. As such, asyncEJS popularity was classified as not popular.
We found that asyncEJS demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.