Skip to content

Commit f50c08d

Browse files
author
Daniel Stockman
committed
Merge remote-tracking branch 'elarivie/master' into edge
* elarivie/master: Set maxbuffer length to Infinity to avoid stdout maxBuffer exceeded fix danielgtaylor#44 Removed hardcoded path to tmp, now uses os library to get it. Add support for embeded image with data uri Added missing description of response to the template Randomize temp file name to avoid race condition fix danielgtaylor#17 fix danielgtaylor#24 fix danielgtaylor#42
2 parents 13c5c0b + d87f628 commit f50c08d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/renderer.coffee

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{exec} = require 'child_process'
2+
os = require 'os'
23
path = require 'path'
34
_ = require 'underscore-plus'
45
fs = require 'fs-plus'
@@ -22,17 +23,28 @@ exports.toHTML = (text='', filePath, grammar, callback) ->
2223
render text, filePath, callback
2324

2425
render = (text, filePath, callback) ->
25-
tempFile = '/tmp/atom.apib'
26+
27+
# Use current time and random number to generate a temp file name
28+
# This way each rendering execution have their own unshared temp file
29+
# This avoids error when rendering multiple times in a short period of time.
30+
tempFile = path.join(os.tmpdir(), 'atom' + (new Date).getTime() + '_' + Math.floor(Math.random() * 9007199254740991) + '.apib')
2631
fs.writeFileSync tempFile, text
32+
2733
# Env hack... helps find aglio binary
28-
options =
29-
maxBuffer: 2 * 1024 * 1024 # Default: 200*1024
30-
env = Object.create(process.env)
34+
newEnv = Object.create(process.env)
3135
npm_bin = atom.project.getPaths().map (p) -> path.join(p, 'node_modules', '.bin')
32-
env.PATH = npm_bin.concat(env.PATH, '/usr/local/bin').join(path.delimiter)
36+
newEnv.PATH = npm_bin.concat(newEnv.PATH, '/usr/local/bin').join(path.delimiter)
37+
3338
template = "#{path.dirname __dirname}/templates/api-blueprint-preview.jade"
39+
3440
includePath = path.dirname filePath # for Aglio include directives
35-
exec "aglio -i #{tempFile} -t #{template} -n #{includePath} -o -", {env, options}, (err, stdout, stderr) =>
41+
42+
options = {
43+
maxBuffer: Infinity # Default: 200*1024, set to Infinity to avoid stdout maxBuffer exceeded
44+
env: newEnv # Use the new environment to help find aglio binary
45+
}
46+
47+
exec "aglio -i #{tempFile} -t #{template} -n #{includePath} -o -", options, (err, stdout, stderr) =>
3648
if err then return callback(err)
3749
console.log stderr
3850
fs.removeSync tempFile
@@ -45,6 +57,7 @@ resolveImagePaths = (html, filePath) ->
4557
img = o(imgElement)
4658
if src = img.attr('src')
4759
continue if src.match(/^(https?|atom):\/\//)
60+
continue if src.startsWith('data:image/')
4861
continue if src.startsWith(process.resourcesPath)
4962
continue if src.startsWith(resourcePath)
5063
continue if src.startsWith(packagePath)

templates/api-blueprint-preview.jade

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ mixin RequestResponse(title, request)
3434
if request.name
3535
|   
3636
code= request.name
37+
!= markdown(request.description)
3738
if content
3839
if Object.keys(request.headers).length
3940
h6 Headers

0 commit comments

Comments
 (0)