Skip to content
Myr

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 file

Take it

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

fix package.json to reflect supported node versionDouglas Christopher Wilsonbefore adoptionc054581

lines 1–51why, one step back
1/**
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: 'rawgithub.com',38 port: 80,39 path: this.path,40 method: 'GET'41 };4243 http.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};