Skip to content

Commit fca8ab2

Browse files
committed
Add line-ending cli parameter.
1 parent ab3d7ad commit fca8ab2

9 files changed

+329
-316
lines changed

bin/apidoc

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ var argv = nomnom
5252

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

55+
.option('line-ending', { help: 'Turn off autodetect line-ending. Allowed values: LF, CR, CRLF.' })
56+
5557
.parse()
5658
;
5759

@@ -95,7 +97,8 @@ var options = {
9597
workers : transformToObject(argv['parse-workers']),
9698
silent : argv['silent'],
9799
simulate : argv['simulate'],
98-
markdown : argv['markdown']
100+
markdown : argv['markdown'],
101+
lineEnding : argv['line-ending'],
99102
};
100103

101104
if (apidoc.createDoc(options) === false) {

lib/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ function createDoc(options) {
5151
options.dest = path.join(options.dest, './');
5252
options.template = path.join(options.template, './');
5353

54+
// Line-Ending.
55+
if (options.lineEnding) {
56+
if (options.lineEnding === 'CRLF')
57+
options.lineEnding = '\r\n'; // win32
58+
else if (options.lineEnding === 'CR')
59+
options.lineEnding = '\r'; // darwin
60+
else
61+
options.lineEnding = '\n'; // linux
62+
}
63+
5464
// Options.
5565
app.options = options;
5666

test/apidoc_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ describe('apiDoc full example', function() {
8989
// remove the base path
9090
createdContent = createdContent.replace(filenameRegExp, '');
9191

92-
var fixtureLines = fixtureContent.split(/\r\n/);
93-
var createdLines = createdContent.split(/\r\n/);
92+
var fixtureLines = fixtureContent.split(/\n/);
93+
var createdLines = createdContent.split(/\n/);
9494

9595
if (fixtureLines.length !== createdLines.length)
9696
throw new Error('File ./tmp/' + name + ' not equals to ' + fixturePath + '/' + name);

test/custom_markdown_parser_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('apiDoc custom markdown parser', function() {
8080
fixtureFiles.forEach(function(name) {
8181
var createdContent = fs.readFileSync('./tmp/' + name, 'utf8');
8282

83-
var createdLines = createdContent.split(/\r\n/);
83+
var createdLines = createdContent.split(/\n/);
8484

8585
for (var lineNumber = 0; lineNumber < createdLines.length; lineNumber += 1) {
8686
if (createdLines[lineNumber].indexOf('Custom Markdown Parser: ') !== -1)
+143-143
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,144 @@
1-
define({ "api": [
2-
{
3-
"type": "post",
4-
"url": "/api/authenticate",
5-
"title": "",
6-
"version": "0.3.0",
7-
"group": "Authentication",
8-
"name": "Authenticate",
9-
"parameter": {
10-
"fields": {
11-
"Credentials": [
12-
{
13-
"group": "Credentials",
14-
"type": "<p>String</p> ",
15-
"optional": false,
16-
"field": "username",
17-
"description": "<p>Username</p> "
18-
},
19-
{
20-
"group": "Credentials",
21-
"type": "<p>String</p> ",
22-
"optional": false,
23-
"field": "password",
24-
"description": "<p>password</p> "
25-
}
26-
]
27-
}
28-
},
29-
"filename": "src/test_api.js",
30-
"groupTitle": "Authentication",
31-
"error": {
32-
"fields": {
33-
"500 Internal Server Error": [
34-
{
35-
"group": "500 Internal Server Error",
36-
"optional": false,
37-
"field": "InternalServerError",
38-
"description": "<p>The server encountered an internal error</p> "
39-
}
40-
]
41-
},
42-
"examples": [
43-
{
44-
"title": "500 Internal Server Error",
45-
"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}",
46-
"type": "json"
47-
}
48-
]
49-
}
50-
},
51-
{
52-
"type": "get",
53-
"url": "/api/subscriptioninfo",
54-
"title": "",
55-
"version": "0.3.0",
56-
"description": "<p>Get the subscription information from an authenticated user.</p> ",
57-
"group": "Authentication",
58-
"name": "GetSubscriptionInfo",
59-
"filename": "src/test_api.js",
60-
"groupTitle": "Authentication",
61-
"header": {
62-
"fields": {
63-
"Header": [
64-
{
65-
"group": "Header",
66-
"type": "String",
67-
"optional": false,
68-
"field": "Authorization",
69-
"description": "<p>Auth header with JWT Token</p> "
70-
}
71-
]
72-
},
73-
"examples": [
74-
{
75-
"title": "Authorization-Example:",
76-
"content": "Authorization: Bearer <jwt-token>",
77-
"type": "String"
78-
}
79-
]
80-
},
81-
"error": {
82-
"fields": {
83-
"500 Internal Server Error": [
84-
{
85-
"group": "500 Internal Server Error",
86-
"optional": false,
87-
"field": "InternalServerError",
88-
"description": "<p>The server encountered an internal error</p> "
89-
}
90-
]
91-
},
92-
"examples": [
93-
{
94-
"title": "500 Internal Server Error",
95-
"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}",
96-
"type": "json"
97-
}
98-
]
99-
}
100-
},
101-
{
102-
"type": "get",
103-
"url": "/api/subscriptioninfo/:userid",
104-
"title": "",
105-
"version": "0.2.0",
106-
"description": "<p>Get the subscription information for a user.</p> ",
107-
"parameter": {
108-
"fields": {
109-
"Parameter": [
110-
{
111-
"group": "Parameter",
112-
"type": "<p>Number</p> ",
113-
"optional": false,
114-
"field": "userid",
115-
"description": "<p>user id</p> "
116-
}
117-
]
118-
}
119-
},
120-
"group": "Authentication",
121-
"name": "GetSubscriptionInfo",
122-
"filename": "folder2/History.js",
123-
"groupTitle": "Authentication",
124-
"error": {
125-
"fields": {
126-
"500 Internal Server Error": [
127-
{
128-
"group": "500 Internal Server Error",
129-
"optional": false,
130-
"field": "InternalServerError",
131-
"description": "<p>The server encountered an internal error</p> "
132-
}
133-
]
134-
},
135-
"examples": [
136-
{
137-
"title": "500 Internal Server Error",
138-
"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}",
139-
"type": "json"
140-
}
141-
]
142-
}
143-
}
1+
define({ "api": [
2+
{
3+
"type": "post",
4+
"url": "/api/authenticate",
5+
"title": "",
6+
"version": "0.3.0",
7+
"group": "Authentication",
8+
"name": "Authenticate",
9+
"parameter": {
10+
"fields": {
11+
"Credentials": [
12+
{
13+
"group": "Credentials",
14+
"type": "<p>String</p> ",
15+
"optional": false,
16+
"field": "username",
17+
"description": "<p>Username</p> "
18+
},
19+
{
20+
"group": "Credentials",
21+
"type": "<p>String</p> ",
22+
"optional": false,
23+
"field": "password",
24+
"description": "<p>password</p> "
25+
}
26+
]
27+
}
28+
},
29+
"filename": "src/test_api.js",
30+
"groupTitle": "Authentication",
31+
"error": {
32+
"fields": {
33+
"500 Internal Server Error": [
34+
{
35+
"group": "500 Internal Server Error",
36+
"optional": false,
37+
"field": "InternalServerError",
38+
"description": "<p>The server encountered an internal error</p> "
39+
}
40+
]
41+
},
42+
"examples": [
43+
{
44+
"title": "500 Internal Server Error",
45+
"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}",
46+
"type": "json"
47+
}
48+
]
49+
}
50+
},
51+
{
52+
"type": "get",
53+
"url": "/api/subscriptioninfo",
54+
"title": "",
55+
"version": "0.3.0",
56+
"description": "<p>Get the subscription information from an authenticated user.</p> ",
57+
"group": "Authentication",
58+
"name": "GetSubscriptionInfo",
59+
"filename": "src/test_api.js",
60+
"groupTitle": "Authentication",
61+
"header": {
62+
"fields": {
63+
"Header": [
64+
{
65+
"group": "Header",
66+
"type": "String",
67+
"optional": false,
68+
"field": "Authorization",
69+
"description": "<p>Auth header with JWT Token</p> "
70+
}
71+
]
72+
},
73+
"examples": [
74+
{
75+
"title": "Authorization-Example:",
76+
"content": "Authorization: Bearer <jwt-token>",
77+
"type": "String"
78+
}
79+
]
80+
},
81+
"error": {
82+
"fields": {
83+
"500 Internal Server Error": [
84+
{
85+
"group": "500 Internal Server Error",
86+
"optional": false,
87+
"field": "InternalServerError",
88+
"description": "<p>The server encountered an internal error</p> "
89+
}
90+
]
91+
},
92+
"examples": [
93+
{
94+
"title": "500 Internal Server Error",
95+
"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}",
96+
"type": "json"
97+
}
98+
]
99+
}
100+
},
101+
{
102+
"type": "get",
103+
"url": "/api/subscriptioninfo/:userid",
104+
"title": "",
105+
"version": "0.2.0",
106+
"description": "<p>Get the subscription information for a user.</p> ",
107+
"parameter": {
108+
"fields": {
109+
"Parameter": [
110+
{
111+
"group": "Parameter",
112+
"type": "<p>Number</p> ",
113+
"optional": false,
114+
"field": "userid",
115+
"description": "<p>user id</p> "
116+
}
117+
]
118+
}
119+
},
120+
"group": "Authentication",
121+
"name": "GetSubscriptionInfo",
122+
"filename": "folder2/History.js",
123+
"groupTitle": "Authentication",
124+
"error": {
125+
"fields": {
126+
"500 Internal Server Error": [
127+
{
128+
"group": "500 Internal Server Error",
129+
"optional": false,
130+
"field": "InternalServerError",
131+
"description": "<p>The server encountered an internal error</p> "
132+
}
133+
]
134+
},
135+
"examples": [
136+
{
137+
"title": "500 Internal Server Error",
138+
"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}",
139+
"type": "json"
140+
}
141+
]
142+
}
143+
}
144144
] });

0 commit comments

Comments
 (0)