UNPKG

page.js-express-mapper.js

Version:

Plugin for page.js which directly imitates the Express API.

57 lines (50 loc) 1.58 kB
<!DOCTYPE html> <html> <head> <title>Simple sample app to test page.js-express-mapper.js</title> <meta charset='UTF-8'> </head> <body> <ul> <li><a href='/testlink1'>/testlink1</a></li> <li><a href='/testlink2'>/testlink2</a></li> <li><a href='/testlink3'>/testlink3</a></li> </ul> <p><em>Note: this can only be run from a web server. If you have Python installed, you can start a quick one by running "<code>python -m SimpleHTTPServer</code>" and then going to <a href='http://localhost:8000/sampleApp.html'>http://localhost:8000/sampleApp.html</a>.</em></p> <!-- make sure to run: bower install page.js --> <script src='bower_components/page.js/page.js'></script> <!-- load express-mapper plugin --> <script src='page.js-express-mapper.js'></script> <!-- sample app code --> <script> // activate express-mapper plugin pageExpressMapper({ renderMethod: function(template, model) { console.log('template supplied was: ' + template); console.log('and the model:'); console.log(model); }, expressAppName: 'app' }); // define routes app.route('/testlink1').get(function(req, res) { res.render('someTemplate', {some: 'model'}); }); app.route('/testlink2').get(function(req, res) { res.render('someOtherTemplate', {someOther: 'model'}); }); app.route('/testlink3').get(function(req, res) { res.render('templateThree', {template: 'three'}); }); // activate router page(); </script> </body> </html>