Skip to content

Commit

Permalink
Add line-ending cli parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed May 8, 2015
1 parent ab3d7ad commit fca8ab2
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 316 deletions.
5 changes: 4 additions & 1 deletion bin/apidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var argv = nomnom

.option('markdown', { 'default': true, help: 'Turn off default markdown parser or set a file to a custom parser.' })

.option('line-ending', { help: 'Turn off autodetect line-ending. Allowed values: LF, CR, CRLF.' })

.parse()
;

Expand Down Expand Up @@ -95,7 +97,8 @@ var options = {
workers : transformToObject(argv['parse-workers']),
silent : argv['silent'],
simulate : argv['simulate'],
markdown : argv['markdown']
markdown : argv['markdown'],
lineEnding : argv['line-ending'],
};

if (apidoc.createDoc(options) === false) {
Expand Down
10 changes: 10 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ function createDoc(options) {
options.dest = path.join(options.dest, './');
options.template = path.join(options.template, './');

// Line-Ending.
if (options.lineEnding) {
if (options.lineEnding === 'CRLF')
options.lineEnding = '\r\n'; // win32
else if (options.lineEnding === 'CR')
options.lineEnding = '\r'; // darwin
else
options.lineEnding = '\n'; // linux
}

// Options.
app.options = options;

Expand Down
4 changes: 2 additions & 2 deletions test/apidoc_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ describe('apiDoc full example', function() {
// remove the base path
createdContent = createdContent.replace(filenameRegExp, '');

var fixtureLines = fixtureContent.split(/\r\n/);
var createdLines = createdContent.split(/\r\n/);
var fixtureLines = fixtureContent.split(/\n/);
var createdLines = createdContent.split(/\n/);

if (fixtureLines.length !== createdLines.length)
throw new Error('File ./tmp/' + name + ' not equals to ' + fixturePath + '/' + name);
Expand Down
2 changes: 1 addition & 1 deletion test/custom_markdown_parser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('apiDoc custom markdown parser', function() {
fixtureFiles.forEach(function(name) {
var createdContent = fs.readFileSync('./tmp/' + name, 'utf8');

var createdLines = createdContent.split(/\r\n/);
var createdLines = createdContent.split(/\n/);

for (var lineNumber = 0; lineNumber < createdLines.length; lineNumber += 1) {
if (createdLines[lineNumber].indexOf('Custom Markdown Parser: ') !== -1)
Expand Down
286 changes: 143 additions & 143 deletions test/multi_input_folder/fixtures/api_data.js
Original file line number Diff line number Diff line change
@@ -1,144 +1,144 @@
define({ "api": [
{
"type": "post",
"url": "/api/authenticate",
"title": "",
"version": "0.3.0",
"group": "Authentication",
"name": "Authenticate",
"parameter": {
"fields": {
"Credentials": [
{
"group": "Credentials",
"type": "<p>String</p> ",
"optional": false,
"field": "username",
"description": "<p>Username</p> "
},
{
"group": "Credentials",
"type": "<p>String</p> ",
"optional": false,
"field": "password",
"description": "<p>password</p> "
}
]
}
},
"filename": "src/test_api.js",
"groupTitle": "Authentication",
"error": {
"fields": {
"500 Internal Server Error": [
{
"group": "500 Internal Server Error",
"optional": false,
"field": "InternalServerError",
"description": "<p>The server encountered an internal error</p> "
}
]
},
"examples": [
{
"title": "500 Internal Server Error",
"content": "HTTP/1.1 500 Internal Server Error\n{\n \"uri\": \"<api-endpoint>\",\n \"method\": \"<method used>\",\n \"type\": \"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\",\n \"title\": \"Internal Server Error\",\n \"status\": 500,\n \"detail\": \"<Detail Message>\"\n}",
"type": "json"
}
]
}
},
{
"type": "get",
"url": "/api/subscriptioninfo",
"title": "",
"version": "0.3.0",
"description": "<p>Get the subscription information from an authenticated user.</p> ",
"group": "Authentication",
"name": "GetSubscriptionInfo",
"filename": "src/test_api.js",
"groupTitle": "Authentication",
"header": {
"fields": {
"Header": [
{
"group": "Header",
"type": "String",
"optional": false,
"field": "Authorization",
"description": "<p>Auth header with JWT Token</p> "
}
]
},
"examples": [
{
"title": "Authorization-Example:",
"content": "Authorization: Bearer <jwt-token>",
"type": "String"
}
]
},
"error": {
"fields": {
"500 Internal Server Error": [
{
"group": "500 Internal Server Error",
"optional": false,
"field": "InternalServerError",
"description": "<p>The server encountered an internal error</p> "
}
]
},
"examples": [
{
"title": "500 Internal Server Error",
"content": "HTTP/1.1 500 Internal Server Error\n{\n \"uri\": \"<api-endpoint>\",\n \"method\": \"<method used>\",\n \"type\": \"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\",\n \"title\": \"Internal Server Error\",\n \"status\": 500,\n \"detail\": \"<Detail Message>\"\n}",
"type": "json"
}
]
}
},
{
"type": "get",
"url": "/api/subscriptioninfo/:userid",
"title": "",
"version": "0.2.0",
"description": "<p>Get the subscription information for a user.</p> ",
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "<p>Number</p> ",
"optional": false,
"field": "userid",
"description": "<p>user id</p> "
}
]
}
},
"group": "Authentication",
"name": "GetSubscriptionInfo",
"filename": "folder2/History.js",
"groupTitle": "Authentication",
"error": {
"fields": {
"500 Internal Server Error": [
{
"group": "500 Internal Server Error",
"optional": false,
"field": "InternalServerError",
"description": "<p>The server encountered an internal error</p> "
}
]
},
"examples": [
{
"title": "500 Internal Server Error",
"content": "HTTP/1.1 500 Internal Server Error\n{\n \"uri\": \"<api-endpoint>\",\n \"method\": \"<method used>\",\n \"type\": \"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\",\n \"title\": \"Internal Server Error\",\n \"status\": 500,\n \"detail\": \"<Detail Message>\"\n}",
"type": "json"
}
]
}
}
define({ "api": [
{
"type": "post",
"url": "/api/authenticate",
"title": "",
"version": "0.3.0",
"group": "Authentication",
"name": "Authenticate",
"parameter": {
"fields": {
"Credentials": [
{
"group": "Credentials",
"type": "<p>String</p> ",
"optional": false,
"field": "username",
"description": "<p>Username</p> "
},
{
"group": "Credentials",
"type": "<p>String</p> ",
"optional": false,
"field": "password",
"description": "<p>password</p> "
}
]
}
},
"filename": "src/test_api.js",
"groupTitle": "Authentication",
"error": {
"fields": {
"500 Internal Server Error": [
{
"group": "500 Internal Server Error",
"optional": false,
"field": "InternalServerError",
"description": "<p>The server encountered an internal error</p> "
}
]
},
"examples": [
{
"title": "500 Internal Server Error",
"content": "HTTP/1.1 500 Internal Server Error\n{\n \"uri\": \"<api-endpoint>\",\n \"method\": \"<method used>\",\n \"type\": \"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\",\n \"title\": \"Internal Server Error\",\n \"status\": 500,\n \"detail\": \"<Detail Message>\"\n}",
"type": "json"
}
]
}
},
{
"type": "get",
"url": "/api/subscriptioninfo",
"title": "",
"version": "0.3.0",
"description": "<p>Get the subscription information from an authenticated user.</p> ",
"group": "Authentication",
"name": "GetSubscriptionInfo",
"filename": "src/test_api.js",
"groupTitle": "Authentication",
"header": {
"fields": {
"Header": [
{
"group": "Header",
"type": "String",
"optional": false,
"field": "Authorization",
"description": "<p>Auth header with JWT Token</p> "
}
]
},
"examples": [
{
"title": "Authorization-Example:",
"content": "Authorization: Bearer <jwt-token>",
"type": "String"
}
]
},
"error": {
"fields": {
"500 Internal Server Error": [
{
"group": "500 Internal Server Error",
"optional": false,
"field": "InternalServerError",
"description": "<p>The server encountered an internal error</p> "
}
]
},
"examples": [
{
"title": "500 Internal Server Error",
"content": "HTTP/1.1 500 Internal Server Error\n{\n \"uri\": \"<api-endpoint>\",\n \"method\": \"<method used>\",\n \"type\": \"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\",\n \"title\": \"Internal Server Error\",\n \"status\": 500,\n \"detail\": \"<Detail Message>\"\n}",
"type": "json"
}
]
}
},
{
"type": "get",
"url": "/api/subscriptioninfo/:userid",
"title": "",
"version": "0.2.0",
"description": "<p>Get the subscription information for a user.</p> ",
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "<p>Number</p> ",
"optional": false,
"field": "userid",
"description": "<p>user id</p> "
}
]
}
},
"group": "Authentication",
"name": "GetSubscriptionInfo",
"filename": "folder2/History.js",
"groupTitle": "Authentication",
"error": {
"fields": {
"500 Internal Server Error": [
{
"group": "500 Internal Server Error",
"optional": false,
"field": "InternalServerError",
"description": "<p>The server encountered an internal error</p> "
}
]
},
"examples": [
{
"title": "500 Internal Server Error",
"content": "HTTP/1.1 500 Internal Server Error\n{\n \"uri\": \"<api-endpoint>\",\n \"method\": \"<method used>\",\n \"type\": \"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\",\n \"title\": \"Internal Server Error\",\n \"status\": 500,\n \"detail\": \"<Detail Message>\"\n}",
"type": "json"
}
]
}
}
] });
Loading

0 comments on commit fca8ab2

Please sign in to comment.