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

examples: fix reference error in view-constructorOwen Lukebefore adoptioncf37240

History of this file

Take it

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

tests: add lone "*" route testsDouglas Christopher Wilsonbefore adoption1f71fae

lines 1–4why, one step back
1/**
2 * Module dependencies.3 */4

examples: fix reference error in view-constructorOwen Lukebefore adoptioncf37240

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

tests: add lone "*" route testsDouglas Christopher Wilsonbefore adoption1f71fae

lines 6–51why, one step back
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: 'raw.githubusercontent.com',38 port: 443,39 path: this.path,40 method: 'GET'41 };4243 https.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};