Skip to content
Myr

github-view.js

This file

Path

examples/view-constructor/github-view.js

52 lines · 1.0 KiB · JavaScript

Last changed by

examples: fix github view exampleDouglas Christopher Wilsonbefore adoptionb97f6eb

History of this file

Take it

The walk stopped after 200 commits: lines older than 1f938c5 point at it.

tests: improve examples/auth testsDouglas Christopher Wilsonbefore adoption1f938c5

lines 1–37why, one step back
1
2/**3 * Module dependencies.4 */56var http = require('http')7 , path = require('path')8 , extname = path.extname910/**11 * Expose `GithubView`.12 */1314module.exports = GithubView;1516/**17 * Custom view that fetches and renders18 * remove github templates. You could19 * render templates from a database etc.20 */2122function GithubView(name, options){23 this.name = name;24 options = options || {};25 this.engine = options.engines[extname(name)];26 // "root" is the app.set('views') setting, however27 // in your own implementation you could ignore this28 this.path = '/' + options.root + '/master/' + name;29}3031/**32 * Render the view.33 */3435GithubView.prototype.render = function(options, fn){36 var self = this;37 var opts = {

examples: fix github view exampleDouglas Christopher Wilsonbefore adoptionb97f6eb

lines 38–39why, one step back
38 host: 'raw.githubusercontent.com',
39 port: 443,

tests: improve examples/auth testsDouglas Christopher Wilsonbefore adoption1f938c5

lines 40–43why, one step back
40 path: this.path,
41 method: 'GET'42 };43

examples: fix github view exampleDouglas Christopher Wilsonbefore adoptionb97f6eb

line 44why, one step back
44 https.request(opts, function(res) {

tests: improve examples/auth testsDouglas Christopher Wilsonbefore adoption1f938c5

lines 45–52why, one step back
45 var buf = '';
46 res.setEncoding('utf8');47 res.on('data', function(str){ buf += str });48 res.on('end', function(){49 self.engine(buf, options, fn);50 });51 }).end();52};