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

examples: use strict modeDouglas Christopher Wilsonbefore adoption20047bb

History of this file

Take it

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

examples: use strict modeDouglas Christopher Wilsonbefore adoption20047bb

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

tests: remove should usage from Router testsDouglas Christopher Wilsonbefore adoption8e4add7

lines 3–53why, one step back
3/**
4 * Module dependencies.5 */67var https = require('https');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 = {39 host: 'raw.githubusercontent.com',40 port: 443,41 path: this.path,42 method: 'GET'43 };4445 https.request(opts, function(res) {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};