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

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

History of this file

Take it

The walk stopped after 200 commits: lines older than 6aa4a45 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.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45

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

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

lines 7–8why, one step back
7var https = require('node:https');
8var path = require('node:path');

Merge tag '3.17.7'Douglas Christopher Wilsonbefore adoption6aa4a45

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