github-view.js
This file
Path
examples/view-constructor/github-view.js
51 lines · 1.0 KiB · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than b5f98ab point at it.
deps: serve-static@~1.10.0Douglas Christopher Wilsonbefore adoptionb5f98ab
lines 1–51why, one step back1/**2 * Module dependencies.3 */45var http = require('http');6var path = require('path');7var extname = path.extname;89/**10 * Expose `GithubView`.11 */1213module.exports = GithubView;1415/**16 * Custom view that fetches and renders17 * remove github templates. You could18 * render templates from a database etc.19 */2021function GithubView(name, options){22 this.name = name;23 options = options || {};24 this.engine = options.engines[extname(name)];25 // "root" is the app.set('views') setting, however26 // in your own implementation you could ignore this27 this.path = '/' + options.root + '/master/' + name;28}2930/**31 * Render the view.32 */3334GithubView.prototype.render = function(options, fn){35 var self = this;36 var opts = {37 host: 'raw.githubusercontent.com',38 port: 443,39 path: this.path,40 method: 'GET'41 };4243 https.request(opts, function(res) {44 var buf = '';45 res.setEncoding('utf8');46 res.on('data', function(str){ buf += str });47 res.on('end', function(){48 self.engine(buf, options, fn);49 });50 }).end();51};