Skip to content

Commit

Permalink
Add multiple input locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed May 8, 2015
1 parent 07ebfda commit 3baedf7
Show file tree
Hide file tree
Showing 14 changed files with 533 additions and 3 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/multi_input_folder/fixtures
2 changes: 1 addition & 1 deletion bin/apidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var argv = nomnom
.option('exclude-filters', { abbr: 'e', 'default': '', list: true,
help: 'RegEx-Filter to select files / dirs that should not be parsed (many -e can be used).', })

.option('input', { abbr: 'i', 'default': './', help: 'Input / source dirname.' })
.option('input', { abbr: 'i', 'default': './', list: true, help: 'Input / source dirname.' })

.option('output', { abbr: 'o', 'default': './doc/', help: 'Output dirname.' })

Expand Down
29 changes: 27 additions & 2 deletions lib/package_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ PackageInfo.prototype.get = function() {
*/
PackageInfo.prototype._readPackageData = function(filename) {
var result = {};
var jsonFilename = path.join(app.options.src, filename);
//var jsonFilename = path.join(app.options.src, filename);
var dir = this._resolveSrcPath();
var jsonFilename = path.join(dir, filename);

// read from source dir
if ( ! fs.existsSync(jsonFilename)) {
Expand Down Expand Up @@ -88,10 +90,14 @@ PackageInfo.prototype._readPackageData = function(filename) {
*/
PackageInfo.prototype._getHeaderFooter = function(json) {
var result = {};
var self = this;

['header', 'footer'].forEach(function(key) {
if (json[key] && json[key].filename) {
var filename = path.join(app.options.src, json[key].filename);
// var filename = path.join(app.options.src, json[key].filename);
var dir = self._resolveSrcPath();
var filename = path.join(dir, json[key].filename);

if ( ! fs.existsSync(filename))
filename = path.join('./', json[key].filename);

Expand All @@ -110,3 +116,22 @@ PackageInfo.prototype._getHeaderFooter = function(json) {

return result;
};

/**
* Resolve source path.
*
* If multiple input dirs are given, the current workdir './' will be returned.
* On one input dir, the current workdir will be the input dir.
*
* @returns {string}
* @private
*/
PackageInfo.prototype._resolveSrcPath = function() {
var dir = './';

if (app.options.src instanceof Array && app.options.src.length === 1)
dir = app.options.src[0];

return dir;
};

144 changes: 144 additions & 0 deletions test/multi_input_folder/fixtures/api_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +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"
}
]
}
}
] });
144 changes: 144 additions & 0 deletions test/multi_input_folder/fixtures/api_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
[
{
"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"
}
]
}
}
]
13 changes: 13 additions & 0 deletions test/multi_input_folder/fixtures/api_project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
define({
"name": "Multiple Input Folder Test",
"version": "1.0.0",
"description": "Example of feeding apidoc from multiple input folder locations",
"sampleUrl": false,
"apidoc": "0.2.0",
"generator": {
"name": "apidoc",
"time": "2015-05-08T10:26:38.294Z",
"url": "http://apidocjs.com",
"version": "0.12.3"
}
});
13 changes: 13 additions & 0 deletions test/multi_input_folder/fixtures/api_project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Multiple Input Folder Test",
"version": "1.0.0",
"description": "Example of feeding apidoc from multiple input folder locations",
"sampleUrl": false,
"apidoc": "0.2.0",
"generator": {
"name": "apidoc",
"time": "2015-05-08T10:26:38.294Z",
"url": "http://apidocjs.com",
"version": "0.12.3"
}
}
13 changes: 13 additions & 0 deletions test/multi_input_folder/fixtures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>apiDoc</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>

Empty Test Template.

</body>
</html>
Loading

0 comments on commit 3baedf7

Please sign in to comment.