Skip to content
Myr

github-view.js

This file

Path

examples/view-constructor/github-view.js

53 lines · 1.0 KiB · JavaScript

Last changed by

Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b

History of this file

Take it

The walk stopped after 200 commits: lines older than 20635d0 point at it.

Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b

lines 1–2why, one step back
1'use strict'
2

Merge tag '3.16.9'Douglas Christopher Wilsonbefore adoption20635d0

lines 3–6why, one step back
3/**
4 * Module dependencies.5 */6

Merge tag '4.15.4'Douglas Christopher Wilsonbefore adoptionc319fe2

line 7why, one step back
7var https = require('https');

Merge tag '3.16.9'Douglas Christopher Wilsonbefore adoption20635d0

lines 8–38why, one step back
8var path = require('path');
9var extname = path.extname;1011/**12 * Expose `GithubView`.13 */1415module.exports = GithubView;1617/**18 * Custom view that fetches and renders19 * remove github templates. You could20 * render templates from a database etc.21 */2223function 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, however28 // in your own implementation you could ignore this29 this.path = '/' + options.root + '/master/' + name;30}3132/**33 * Render the view.34 */3536GithubView.prototype.render = function(options, fn){37 var self = this;38 var opts = {

Merge tag '3.17.1'Douglas Christopher Wilsonbefore adoption3dca534

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

Merge tag '3.16.9'Douglas Christopher Wilsonbefore adoption20635d0

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

Merge tag '3.17.1'Douglas Christopher Wilsonbefore adoption3dca534

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

Merge tag '3.16.9'Douglas Christopher Wilsonbefore adoption20635d0

lines 46–53why, one step back
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();53};