This commit is contained in:
Tj Holowaychuk 2011-03-02 18:37:29 -08:00
parent 2f7b78c03a
commit 42f3ad436d
4 changed files with 39 additions and 31 deletions

View File

@ -2003,18 +2003,22 @@ This is also useful for libraries that may not match extensions correctly\. For
.IP "" 0
.
.P
For engines that do not comply with the Express specification, we can also wrap their api this way\.
For engines that do not comply with the Express specification, we can also wrap their api this way\. Below we map \fI\.md\fR to render markdown files, rendering the html once since it will not change on subsequent calls, and support local substitution in the form of "{name}"\.
.
.IP "" 4
.
.nf
app\.register(\'\.foo\', {
render: function(str, options) {
// perhaps their api is
// return foo\.toHTML(str, options);
}
});
app\.register(\'\.md\', {
compile: function(str, options){
var html = md\.toHTML(str);
return function(locals){
return html\.replace(/\e{([^}]+)\e}/g, function(_, name){
return locals[name];
});
};
}
});
.
.fi
.

View File

@ -1504,14 +1504,21 @@ of layout.hamljs, we can register the engine as ".haml":</p>
</code></pre>
<p>For engines that do not comply with the Express
specification, we can also wrap their api this way.</p>
specification, we can also wrap their api this way. Below
we map <em>.md</em> to render markdown files, rendering the html once
since it will not change on subsequent calls, and support local substitution
in the form of "{name}".</p>
<pre><code> app.register('.foo', {
render: function(str, options) {
// perhaps their api is
// return foo.toHTML(str, options);
}
});
<pre><code> app.register('.md', {
compile: function(str, options){
var html = md.toHTML(str);
return function(locals){
return html.replace(/\{([^}]+)\}/g, function(_, name){
return locals[name];
});
};
}
});
</code></pre>
<h3 id="app-listen-port-host-">app.listen([port[, host]])</h3>

View File

@ -1126,14 +1126,21 @@ of layout.hamljs, we can register the engine as ".haml":
app.register('.haml', require('haml-js'));
For engines that do not comply with the Express
specification, we can also wrap their api this way.
specification, we can also wrap their api this way. Below
we map _.md_ to render markdown files, rendering the html once
since it will not change on subsequent calls, and support local substitution
in the form of "{name}".
app.register('.foo', {
render: function(str, options) {
// perhaps their api is
// return foo.toHTML(str, options);
}
});
app.register('.md', {
compile: function(str, options){
var html = md.toHTML(str);
return function(locals){
return html.replace(/\{([^}]+)\}/g, function(_, name){
return locals[name];
});
};
}
});
### app.listen([port[, host]])

View File

@ -176,16 +176,6 @@ View.prototype.__defineGetter__('prefixPath', function(){
*
* app.register('.haml', require('haml-js'));
*
* For engines that do not comply with the Express
* specification, we can also wrap their api this way.
*
* app.register('.foo', {
* render: function(str, options) {
* // perhaps their api is
* // return foo.toHTML(str, options);
* }
* });
*
* @param {String} ext
* @param {Object} obj
* @api public