mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
chore(markdown) rm iife
This commit is contained in:
parent
96dd511773
commit
16aa1ebf2c
2 changed files with 63 additions and 64 deletions
|
|
@ -1,71 +1,69 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var DIR = './',
|
||||
DIR_LIB = '../',
|
||||
DIR_ROOT = __dirname + '/' + DIR_LIB + '../',
|
||||
|
||||
var DIR = './',
|
||||
DIR_LIB = '../',
|
||||
DIR_ROOT = __dirname + '/' + DIR_LIB + '../',
|
||||
|
||||
fs = require('fs'),
|
||||
|
||||
root = require(DIR + 'root'),
|
||||
pipe = require('pipe-io'),
|
||||
ponse = require('ponse'),
|
||||
markdown = require('markdown-it')();
|
||||
fs = require('fs'),
|
||||
|
||||
function check(name, request, callback) {
|
||||
if (typeof name !== 'string')
|
||||
throw Error('name should be string!');
|
||||
|
||||
else if (!request)
|
||||
throw Error('request could not be empty!');
|
||||
|
||||
else if (typeof callback !== 'function')
|
||||
throw Error('callback should be function!');
|
||||
}
|
||||
root = require(DIR + 'root'),
|
||||
pipe = require('pipe-io'),
|
||||
ponse = require('ponse'),
|
||||
markdown = require('markdown-it')();
|
||||
|
||||
function check(name, request, callback) {
|
||||
if (typeof name !== 'string')
|
||||
throw Error('name should be string!');
|
||||
|
||||
module.exports = function(name, request, callback) {
|
||||
var query,
|
||||
method = request.method;
|
||||
|
||||
check(name, request, callback);
|
||||
|
||||
switch(method) {
|
||||
case 'GET':
|
||||
name = name.replace('/markdown', '');
|
||||
query = ponse.getQuery(request);
|
||||
|
||||
if (query === 'relative')
|
||||
name = DIR_ROOT + name;
|
||||
else if (!request)
|
||||
throw Error('request could not be empty!');
|
||||
|
||||
else if (typeof callback !== 'function')
|
||||
throw Error('callback should be function!');
|
||||
}
|
||||
|
||||
module.exports = function(name, request, callback) {
|
||||
var query,
|
||||
method = request.method;
|
||||
|
||||
check(name, request, callback);
|
||||
|
||||
switch(method) {
|
||||
case 'GET':
|
||||
name = name.replace('/markdown', '');
|
||||
query = ponse.getQuery(request);
|
||||
|
||||
if (query === 'relative')
|
||||
name = DIR_ROOT + name;
|
||||
else
|
||||
name = root(name);
|
||||
|
||||
fs.readFile(name, 'utf8', function(error, data) {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
name = root(name);
|
||||
|
||||
fs.readFile(name, 'utf8', function(error, data) {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
parse(data, callback);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
pipe.getBody(request, function(error, data) {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
parse(data, callback);
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
function parse(data, callback) {
|
||||
var md;
|
||||
parse(data, callback);
|
||||
});
|
||||
break;
|
||||
|
||||
process.nextTick(function() {
|
||||
md = markdown.render(data);
|
||||
|
||||
callback(null, md);
|
||||
});
|
||||
case 'PUT':
|
||||
pipe.getBody(request, function(error, data) {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
parse(data, callback);
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
function parse(data, callback) {
|
||||
var md;
|
||||
|
||||
})();
|
||||
process.nextTick(function() {
|
||||
md = markdown.render(data);
|
||||
|
||||
callback(null, md);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@
|
|||
"package-json": "^2.3.0",
|
||||
"pipe-io": "^1.2.0",
|
||||
"ponse": "^1.4.0",
|
||||
"pullout": "^1.0.1",
|
||||
"readjson": "^1.1.0",
|
||||
"remedy": "^1.5.0",
|
||||
"rendy": "^1.1.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue