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

Not known.

History of this file

Take it

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

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 1–52why, 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 = {38 host: 'rawgithub.com',39 port: 80,40 path: this.path,41 method: 'GET'42 };4344 http.request(opts, function(res) {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};