
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Split your templates into asynchronous blocks, then asynchronously render the template. This is a asynchronous, server-side extension of block.
This is similar to hyperstream except:
ablock
is template type agnostic. You can stream JSON if you really want.Creates a block instance from an input string.
Each block can only be a word and must be surrounded by {{}}
.
Example, {{header}}
is okay, but not {{body.header}}
.
Permanently replaces a block with a string or an asynchronous function.
block.local()
and block.locals()
are aliases of each other.
For example:
var template = new Block('<html>{{head}}{{body}}</html>')
// This would permanently replace {{head}} with the following string
template.local('head', '<title>My Site</title>')
// This would permanently replace {{body}} with an asynchronous template
template.local('body', function (done) {
res.render('homepage', done)
})
// This would set both locals at the same time:
template.local({
head: '<title>My Site</title>',
body: function (done) {
res.render('homepage', done)
}
})
This is useful when building templates from pieces.
This returns a readable stream.
locals
are optional, temporary locals for the template.
Unlike block.local()
, these locals are not permanent.
locals
must be an object.
callback
is an optional callback that returns the resulting template as a Buffer
instance. For example:
function (req, res, next) {
block.render(res.locals, function (err, buf) {
if (err)
return next(err)
if (!buf)
// One of the underlying streams was destroyed.
return next(new Error('Something wrong happened.'))
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.send(buf)
})
}
If you want the result in a single string, just call buf.toString('utf8')
.
However, this is pretty much unnecessary.
If no callback
is set, you are expected to block.render().pipe()
into a writable stream. For example:
function (req, res) {
res.setHeader('Content-Type', 'text/html; charset=utf-8')
block.render(res.locals).pipe(res)
}
If you want to use conditional GETs (ie send 304 status codes when possible), you should use a callback. Otherwise, you should stream it.
Each block can be:
The MIT License (MIT)
Copyright (c) 2013 Jonathan Ong me@jongleberry.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.
FAQs
Asynchronous block-based templating
We found that ablock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.