Skip to content

Commit

Permalink
applying lint updates
Browse files Browse the repository at this point in the history
  • Loading branch information
colbygk committed Oct 15, 2017
1 parent 6134d2f commit b0a5ac0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
14 changes: 7 additions & 7 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var bunyan = require('bunyan');

// Create bunyan logger and request (req) serializer
var log = module.exports = bunyan.createLogger({
name: 'mathslax',
serializers: {
req: bunyan.stdSerializers.req
}
name: 'mathslax',
serializers: {
req: bunyan.stdSerializers.req
}
});

/**
Expand All @@ -15,8 +15,8 @@ var log = module.exports = bunyan.createLogger({
* @callback {void}
*/
log.middleware = function (req, res, next) {
req.log = log;
if (req.method !== undefined) log.info({req: req});
next();
req.log = log;
if (req.method !== undefined) log.info({req: req});
next();
};

17 changes: 10 additions & 7 deletions lib/typeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ mathjax.start();

// Application logic for typesetting.
const extractRawMath = function(text, setType) {
var mathRegex = new RegExp('^\s*(' + setType + ')*\s*((\n|.)*)','g');
// eslint-disable-next-line no-useless-escape
var mathRegex = new RegExp('^\s*' + setType + '*\s*((\n|.)*)','g');
var results = [];
var match;

while (match = mathRegex.exec(text))
while ((match = mathRegex.exec(text)) !== null)
{
results.push({ // mathObject
matchedText: match[0],
Expand All @@ -29,7 +30,8 @@ const extractRawMath = function(text, setType) {
};

const renderMath = (mathObject, parseOptions) => {
var defaultOptions = {

const defaultOptions = {
math: mathObject.input,
format: 'TeX',
png: true,
Expand All @@ -40,8 +42,8 @@ const renderMath = (mathObject, parseOptions) => {
timeout: 30 * 1000,
};

var typesetOptions = _.extend(defaultOptions, parseOptions);
var deferred = q.defer();
const typesetOptions = _.extend(defaultOptions, parseOptions);
const deferred = q.defer();

const hash = crypto.createHash('sha256');
hash.update(mathObject.input);
Expand All @@ -61,7 +63,8 @@ const renderMath = (mathObject, parseOptions) => {
}

log.info('writing new PNG: %s', filename);
var pngData = new Buffer(result.png.slice(22), 'base64');
const pngData = new Buffer(result.png.slice(22), 'base64');

fs.writeFile(filepath, pngData, (error) => {
if (error) {
mathObject.error = error;
Expand All @@ -80,7 +83,7 @@ const renderMath = (mathObject, parseOptions) => {
}

return deferred.promise;
}
};

const typeset = function(text, setType) {

Expand Down
14 changes: 9 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

const express = require('express');
const bodyparser = require('body-parser');
const pug = require('pug');
const util = require('util');
// const util = require('util');
const entities = require('entities');

const log = require('./lib/log');
Expand Down Expand Up @@ -37,7 +38,7 @@ router.post('/typeset', function(req, res) {

var promiseSuccess = function(mathObjects) {
var locals = {'mathObjects': mathObjects,
'serverAddress': `http://${SERVER}:${PORT}/` };
'serverAddress': `http://${SERVER}:${PORT}/` };
var htmlResult = pug.renderFile('./views/slack-response.pug', locals);
res.json({'text' : htmlResult});
res.end();
Expand Down Expand Up @@ -73,15 +74,18 @@ router.post('/slashtypeset', function(req, res) {
}

var promiseSuccess = function(mathObjects) {
var locals = {'mathObjects': mathObjects,
'serverAddress': SERVER!='127.0.0.1' ? util.format('http://%s:%s/', SERVER, PORT) : 'http://'+req.headers.host+'/' };
//var locals = {'mathObjects': mathObjects,
// 'serverAddress': SERVER!='127.0.0.1' ?
// util.format('http://%s:%s/', SERVER, PORT) :
// 'http://'+req.headers.host+'/' };
res.json({
response_type: 'in_channel',
text: requestString,
attachments: [
{
fallback: requestString,
image_url: 'http://' + SERVER + ':' + PORT + '/' + mathObjects[0].output,
image_url: 'http://' + SERVER + ':' + PORT + '/'
+ mathObjects[0].output
},
],
});
Expand Down

0 comments on commit b0a5ac0

Please sign in to comment.