docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 2f7b78c · Browse files · 4 files·+39 added−31 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+39 added−31 removed
- other:+39 added−31 removed
Provenance
- Commit
42f3ad4- Tree
ef34808- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
2f7b78c
4 files changed+39 added−31 removed
modified:docs/guide.1+11 added-7 removed
2001 unmodified lines2002 .2003 .IP "" 02004 .2005 .P2006-For engines that do not comply with the Express specification, we can also wrap their api this way\.2006+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}"\.2007 .2008 .IP "" 42009 .2010 .nf2011 2012- app\.register(\'\.foo\', {2013- render: function(str, options) {2014- // perhaps their api is2015- // return foo\.toHTML(str, options);2016- }2017- });2012+ app\.register(\'\.md\', {2013+ compile: function(str, options){2014+ var html = md\.toHTML(str);2015+ return function(locals){2016+ return html\.replace(/\e{([^}]+)\e}/g, function(_, name){2017+ return locals[name];2018+ });2019+ };2020+ }2021+ });2022 .2023 .fi2024 .2025 .IP "" 049 unmodified linesmodified:docs/guide.html+14 added-7 removed
1502 unmodified lines1503 <pre><code> app.register('.haml', require('haml-js'));1504 </code></pre>1505 1506 <p>For engines that do not comply with the Express1507-specification, we can also wrap their api this way.</p>1507+specification, we can also wrap their api this way. Below1508+we map <em>.md</em> to render markdown files, rendering the html once1509+since it will not change on subsequent calls, and support local substitution1510+in the form of "{name}".</p>1511 1509-<pre><code> app.register('.foo', {1510- render: function(str, options) {1511- // perhaps their api is1512- // return foo.toHTML(str, options);1513- }1514- });1512+<pre><code> app.register('.md', {1513+ compile: function(str, options){1514+ var html = md.toHTML(str);1515+ return function(locals){1516+ return html.replace(/\{([^}]+)\}/g, function(_, name){1517+ return locals[name];1518+ });1519+ };1520+ }1521+ });1522 </code></pre>1523 1524 <h3 id="app-listen-port-host-">app.listen([port[, host]])</h3>1525 30 unmodified linesmodified:docs/guide.md+14 added-7 removed
1124 unmodified lines1125 1126 app.register('.haml', require('haml-js'));1127 1128 For engines that do not comply with the Express1129-specification, we can also wrap their api this way.1129+specification, we can also wrap their api this way. Below1130+we map _.md_ to render markdown files, rendering the html once1131+since it will not change on subsequent calls, and support local substitution1132+in the form of "{name}".1133 1131- app.register('.foo', {1132- render: function(str, options) {1133- // perhaps their api is1134- // return foo.toHTML(str, options);1135- }1136- });1134+ app.register('.md', {1135+ compile: function(str, options){1136+ var html = md.toHTML(str);1137+ return function(locals){1138+ return html.replace(/\{([^}]+)\}/g, function(_, name){1139+ return locals[name];1140+ });1141+ };1142+ }1143+ });1144 1145 ### app.listen([port[, host]])1146 1147 Bind the app server to the given _port_, which defaults to 3000. When _host_ is omitted all20 unmodified linesmodified:lib/view/view.js-10 removed
174 unmodified linesExpand all1751761771781791801811821831841851861871881791801811825 unmodified lines174 unmodified linesExpand all * 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. * * app.register('.foo', { * render: function(str, options) { * // perhaps their api is * // return foo.toHTML(str, options); * } * }); * * @param {String} ext * @param {Object} obj * @api public */5 unmodified lines