Commit a50be54f authored by Daniel Shumway's avatar Daniel Shumway

Merge branch 'develop' into 'master'

feat: resume, pdf generation

See merge request !39
parents 535067d3 337af461
Pipeline #31863251 canceled with stage
in 5 minutes and 55 seconds
......@@ -4,6 +4,8 @@ var path = require('path');
var highlightjs = require('highlight.js');
var puppeteer = require('puppeteer');
//Wrap around Asciidoctor to get proper curly quotes. There's got to be a better way to do this.
var Opal = (function () {
return global.Opal; //Already defined by AsciiDoctor
......@@ -155,6 +157,23 @@ var extensions = [
ctx.node.aside = true;
}
return ctx.next();
}
}, {
path : 'extensions/paragraph.template.js',
content : function (ctx) {
var roles = Array.from(ctx.node.roles);
if (roles.length) {
ctx.node.role = roles.join(' ');
}
return ctx.next();
}
}, {
path : 'extensions/section.template.js',
content : function (ctx) {
ctx.node.hlevel = ctx.node.level + 1;
return ctx.next();
}
}
......@@ -233,6 +252,48 @@ var output = Raise([extensions, './source'], {
});
});
}).then(async function () {
var http = require('http');
var Static = require('node-static');
var staticServer = new Static.Server('./public', {
cache : 0
});
var server = await new Promise(function (res, rej) {
var server = http.createServer(function (request, response) {
request.addListener('end', function () {
staticServer.serve(request, response, function (err, result) {
if (err) {
response.writeHead(err.status, err.headers);
response.end();
}
});
}).resume();
}).listen(8003, 'localhost', function () {
res(server);
});
});
//Generate pdfs for all of my resumes
var browser = await puppeteer.launch();
var page = await browser.newPage();
await page.goto('http://localhost:8003/resume/base/?noheader', { waitUntil: 'networkidle2' });
console.log('generating PDF');
await page.pdf({
scale : 0.8,
path: './public/resume/base/resume.pdf',
printBackground: true,
format: 'A4'
});
await browser.close();
server.close();
}).catch(function (err) {
console.log(err);
});
../rimraf/bin.js
\ No newline at end of file
sudo: false
language: node_js
node_js:
- "4"
- "5"
- "6"
- "7"
- "8"
- "9"
install:
- PATH="`npm bin`:`npm bin -g`:$PATH"
# Install dependencies and build
- npm install
script:
# Output useful info for debugging
- node --version
- npm --version
# Run tests
- npm test
4.2.0 / 2018-01-15
==================
* Add support for returning an `http.Agent` instance
* Optimize promisifying logic
* Set `timeout` to null for proper cleanup
* Remove Node.js <= 0.11.3 special-casing from test case
4.1.2 / 2017-11-20
==================
* test Node 9 on Travis
* ensure that `https.get()` uses the patched `https.request()`
4.1.1 / 2017-07-20
==================
* Correct `https.request()` with a String (#9)
4.1.0 / 2017-06-26
==================
* mix in Agent options into Request options
* throw when nothing is returned from agent-base callback
* do not modify the options object for https requests
4.0.1 / 2017-06-13
==================
* add `this` context tests and fixes
4.0.0 / 2017-06-06
==================
* drop support for Node.js < 4
* drop old versions of Node.js from Travis-CI
* specify Node.js >= 4.0.0 in `engines.node`
* remove more old code
* remove "extend" dependency
* remove "semver" dependency
* make the Promise logic a bit cleaner
* add async function pseudo-example to README
* use direct return in README example
3.0.0 / 2017-06-02
==================
* drop support for Node.js v0.8 and v0.10
* add support for async, Promises, and direct return
* add a couple `options` test cases
* implement a `"timeout"` option
* rename main file to `index.js`
* test Node 8 on Travis
2.1.1 / 2017-05-30
==================
* Revert [`fe2162e`](https://github.com/TooTallNate/node-agent-base/commit/fe2162e0ba18123f5b301cba4de1e9dd74e437cd) and [`270bdc9`](https://github.com/TooTallNate/node-agent-base/commit/270bdc92eb8e3bd0444d1e5266e8e9390aeb3095) (fixes #7)
2.1.0 / 2017-05-26
==================
* unref is not supported for node < 0.9.1 (@pi0)
* add tests to dangling socket (@pi0)
* check unref() is supported (@pi0)
* fix dangling sockets problem (@pi0)
* add basic "ws" module tests
* make `Agent` be subclassable
* turn `addRequest()` into a named function
* test: Node.js v4 likes to call `cork` on the stream (#3, @tomhughes)
* travis: test node v4, v5, v6 and v7
2.0.1 / 2015-09-10
==================
* package: update "semver" to v5.0.1 for WebPack (#1, @vhpoet)
2.0.0 / 2015-07-10
==================
* refactor to patch Node.js core for more consistent `opts` values
* ensure that HTTP(s) default port numbers are always given
* test: use ssl-cert-snakeoil SSL certs
* test: add tests for arbitrary options
* README: add API section
* README: make the Agent HTTP/HTTPS generic in the example
* README: use SVG for Travis-CI badge
1.0.2 / 2015-06-27
==================
* agent: set `req._hadError` to true after emitting "error"
* package: update "mocha" to v2
* test: add artificial HTTP GET request test
* test: add artificial data events test
* test: fix artifical GET response test on node > v0.11.3
* test: use a real timeout for the async error test
1.0.1 / 2013-09-09
==================
* Fix passing an "error" object to the callback function on the first tick
1.0.0 / 2013-09-09
==================
* New API: now you pass a callback function directly
0.0.1 / 2013-07-09
==================
* Initial release
agent-base
==========
### Turn a function into an [`http.Agent`][http.Agent] instance
[![Build Status](https://travis-ci.org/TooTallNate/node-agent-base.svg?branch=master)](https://travis-ci.org/TooTallNate/node-agent-base)
This module provides an `http.Agent` generator. That is, you pass it an async
callback function, and it returns a new `http.Agent` instance that will invoke the
given callback function when sending outbound HTTP requests.
#### Some subclasses:
Here's some more interesting uses of `agent-base`.
Send a pull request to list yours!
* [`http-proxy-agent`][http-proxy-agent]: An HTTP(s) proxy `http.Agent` implementation for HTTP endpoints
* [`https-proxy-agent`][https-proxy-agent]: An HTTP(s) proxy `http.Agent` implementation for HTTPS endpoints
* [`pac-proxy-agent`][pac-proxy-agent]: A PAC file proxy `http.Agent` implementation for HTTP and HTTPS
* [`socks-proxy-agent`][socks-proxy-agent]: A SOCKS (v4a) proxy `http.Agent` implementation for HTTP and HTTPS
Installation
------------
Install with `npm`:
``` bash
$ npm install agent-base
```
Example
-------
Here's a minimal example that creates a new `net.Socket` connection to the server
for every HTTP request (i.e. the equivalent of `agent: false` option):
```js
var net = require('net');
var tls = require('tls');
var url = require('url');
var http = require('http');
var agent = require('agent-base');
var endpoint = 'http://nodejs.org/api/';
var parsed = url.parse(endpoint);
// This is the important part!
parsed.agent = agent(function (req, opts) {
var socket;
// `secureEndpoint` is true when using the https module
if (opts.secureEndpoint) {
socket = tls.connect(opts);
} else {
socket = net.connect(opts);
}
return socket;
});
// Everything else works just like normal...
http.get(parsed, function (res) {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
```
Returning a Promise or using an `async` function is also supported:
```js
agent(async function (req, opts) {
await sleep(1000);
// etc…
});
```
Return another `http.Agent` instance to "pass through" the responsibility
for that HTTP request to that agent:
```js
agent(function (req, opts) {
return opts.secureEndpoint ? https.globalAgent : http.globalAgent;
});
```
API
---
## Agent(Function callback[, Object options]) → [http.Agent][]
Creates a base `http.Agent` that will execute the callback function `callback`
for every HTTP request that it is used as the `agent` for. The callback function
is responsible for creating a `stream.Duplex` instance of some kind that will be
used as the underlying socket in the HTTP request.
The `options` object accepts the following properties:
* `timeout` - Number - Timeout for the `callback()` function in milliseconds. Defaults to Infinity (optional).
The callback function should have the following signature:
### callback(http.ClientRequest req, Object options, Function cb) → undefined
The ClientRequest `req` can be accessed to read request headers and
and the path, etc. The `options` object contains the options passed
to the `http.request()`/`https.request()` function call, and is formatted
to be directly passed to `net.connect()`/`tls.connect()`, or however
else you want a Socket to be created. Pass the created socket to
the callback function `cb` once created, and the HTTP request will
continue to proceed.
If the `https` module is used to invoke the HTTP request, then the
`secureEndpoint` property on `options` _will be set to `true`_.
License
-------
(The MIT License)
Copyright (c) 2013 Nathan Rajlich &lt;nathan@tootallnate.net&gt;
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[http-proxy-agent]: https://github.com/TooTallNate/node-http-proxy-agent
[https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent
[pac-proxy-agent]: https://github.com/TooTallNate/node-pac-proxy-agent
[socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent
[http.Agent]: https://nodejs.org/api/http.html#http_class_http_agent
'use strict';
require('./patch-core');
const inherits = require('util').inherits;
const promisify = require('es6-promisify');
const EventEmitter = require('events').EventEmitter;
module.exports = Agent;
function isAgent(v) {
return v && typeof v.addRequest === 'function';
}
/**
* Base `http.Agent` implementation.
* No pooling/keep-alive is implemented by default.
*
* @param {Function} callback
* @api public
*/
function Agent(callback, _opts) {
if (!(this instanceof Agent)) {
return new Agent(callback, _opts);
}
EventEmitter.call(this);
// The callback gets promisified if it has 3 parameters
// (i.e. it has a callback function) lazily
this._promisifiedCallback = false;
let opts = _opts;
if ('function' === typeof callback) {
this.callback = callback;
} else if (callback) {
opts = callback;
}
// timeout for the socket to be returned from the callback
this.timeout = (opts && opts.timeout) || null;
this.options = opts;
}
inherits(Agent, EventEmitter);
/**
* Override this function in your subclass!
*/
Agent.prototype.callback = function callback(req, opts) {
throw new Error(
'"agent-base" has no default implementation, you must subclass and override `callback()`'
);
};
/**
* Called by node-core's "_http_client.js" module when creating
* a new HTTP request with this Agent instance.
*
* @api public
*/
Agent.prototype.addRequest = function addRequest(req, _opts) {
const ownOpts = Object.assign({}, _opts);
// Set default `host` for HTTP to localhost
if (null == ownOpts.host) {
ownOpts.host = 'localhost';
}
// Set default `port` for HTTP if none was explicitly specified
if (null == ownOpts.port) {
ownOpts.port = ownOpts.secureEndpoint ? 443 : 80;
}
const opts = Object.assign({}, this.options, ownOpts);
if (opts.host && opts.path) {
// If both a `host` and `path` are specified then it's most likely the
// result of a `url.parse()` call... we need to remove the `path` portion so
// that `net.connect()` doesn't attempt to open that as a unix socket file.
delete opts.path;
}
delete opts.agent;
delete opts.hostname;
delete opts._defaultAgent;
delete opts.defaultPort;
delete opts.createConnection;
// Hint to use "Connection: close"
// XXX: non-documented `http` module API :(
req._last = true;
req.shouldKeepAlive = false;