update history.md for acceptParams change (#6177)
[express.git] / examples / view-constructor / github-view.js
blob43d29336cacddc9c6a89ad8542dce91dda95557e
1 'use strict'
3 /**
4 * Module dependencies.
5 */
7 var https = require('https');
8 var path = require('path');
9 var extname = path.extname;
11 /**
12 * Expose `GithubView`.
15 module.exports = GithubView;
17 /**
18 * Custom view that fetches and renders
19 * remove github templates. You could
20 * render templates from a database etc.
23 function GithubView(name, options){
24 this.name = name;
25 options = options || {};
26 this.engine = options.engines[extname(name)];
27 // "root" is the app.set('views') setting, however
28 // in your own implementation you could ignore this
29 this.path = '/' + options.root + '/master/' + name;
32 /**
33 * Render the view.
36 GithubView.prototype.render = function(options, fn){
37 var self = this;
38 var opts = {
39 host: 'raw.githubusercontent.com',
40 port: 443,
41 path: this.path,
42 method: 'GET'
45 https.request(opts, function(res) {
46 var buf = '';
47 res.setEncoding('utf8');
48 res.on('data', function(str){ buf += str });
49 res.on('end', function(){
50 self.engine(buf, options, fn);
51 });
52 }).end();