github-view.js
This file
Path
examples/view-constructor/github-view.js
51 lines · 1.0 KiB · JavaScript
Last changed by
Merge tag '4.15.4'Douglas Christopher Wilsonbefore adoptionc319fe2
History of this fileTake it
The walk stopped after 200 commits: lines older than 21bb2ef point at it.
deps: finalhandler@0.1.0Douglas Christopher Wilsonbefore adoption21bb2ef
lines 1–4why, one step back1/**2 * Module dependencies.3 */4Merge tag '4.15.4'Douglas Christopher Wilsonbefore adoptionc319fe2
line 5why, one step back5var https = require('https');deps: finalhandler@0.1.0Douglas Christopher Wilsonbefore adoption21bb2ef
lines 6–36why, one step back6var 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 = {Merge tag '3.17.1'Douglas Christopher Wilsonbefore adoption3dca534
lines 37–38why, one step back37 host: 'raw.githubusercontent.com',38 port: 443,deps: finalhandler@0.1.0Douglas Christopher Wilsonbefore adoption21bb2ef
lines 39–42why, one step back39 path: this.path,40 method: 'GET'41 };42Merge tag '3.17.1'Douglas Christopher Wilsonbefore adoption3dca534
line 43why, one step back43 https.request(opts, function(res) {deps: finalhandler@0.1.0Douglas Christopher Wilsonbefore adoption21bb2ef
lines 44–51why, one step back44 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};