Skip to content

Commit

Permalink
Add language test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed Mar 4, 2014
1 parent 4e857ab commit b531ec0
Show file tree
Hide file tree
Showing 15 changed files with 554 additions and 24 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# apiDoc Changelog

#### 0.4.0
Add support for other comment-style. Now apiDoc supports:
* Erlang
* JavaScript (DocStyle: e.g. also used C#, Go, Dart, Java, PHP)
* Python
* Ruby
Add some programming language test cases.
Remove german code comments.
Upgrade all used node modules.

#### 0.3.0
Replace deprecated node-markdown with [marked](https://github.com/chjj/marked).
Add cli parameter for marked `--marked-...`, watch all params with`--help`.
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function(grunt)
}, // clean

jshint: {
all: ["Gruntfile.js", "lib/**/*.js", "test/**/*.js"],
all: ["Gruntfile.js", "lib/**/*.js", "test/**/*.js", "!test/fixtures/**"],
options: {
// Enforcing Options
bitwise: true,
Expand Down
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
# apiDoc 0.3.0
# apiDoc 0.4.0

Generates a RESTful web API Documentation.

Documentation at [apidocjs.com](http://apidocjs.com).

[Example](http://apidocjs.com/example/) output.

## Supported programming languages

* **C#, Go, Dart, Java, JavaScript, PHP** (all DocStyle capable languages like ):

```javascript
/**
* This is a comment.
*/
```

* **Erlang**:

```erlang
%{
This is a comment.
%}
```

* **Python**

```python
"""
This is a comment.
"""
```

* **Ruby**

```ruby
=begin
This is a comment.
=end
```

## Installation

Expand Down
2 changes: 1 addition & 1 deletion bin/apidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var argv = optimist

.option("f", {
alias: "file-filters",
"default": ".*\\.js$",
"default": ".*\\.(cs|dart|erl|go|java|js|php?|py|rb|ts)$",
describe: "RegEx-Filter to select files that should be parsed (multiple -f can be used)."
})

Expand Down
2 changes: 1 addition & 1 deletion lib/apidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var colors = require("colors");
// Options
var _defaultOptions = {
excludeFilters: [],
includeFilters: [ ".*\\.js$" ],
includeFilters: [ ".*\\.(cs|dart|erl|go|java|js|php?|py|rb|ts)$" ],

src: path.join(__dirname, "../example/"),
dest: path.join(__dirname, "../doc/"),
Expand Down
39 changes: 33 additions & 6 deletions lib/parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var fs = require("fs");
var path = require("path");
var util = require("util");
var _ = require("underscore");

Expand Down Expand Up @@ -53,6 +54,7 @@ Parser.prototype.parseFile = function(filename)
app.debug("inspect file: " + filename);

self.filename = filename;
self.extension = path.extname(filename).toLowerCase();
self.src = fs.readFileSync(filename, "utf8").toString();
app.debug("size: " + self.src.length);

Expand Down Expand Up @@ -263,16 +265,41 @@ Parser.prototype._findBlocks = function()
var self = this;
var blocks = [];
var src = self.src;
var inlineRegExp;
var docBlocksRegExp;

// Replace Linebreak with Unicode
src = src.replace(/\n/g, "\uffff");

// Remove not needed " * " and " " (tab) at the beginning
//var starsRegExp = /^\s?(\*|\s)?\s?/gm;
var starsRegExp = /^(\s+)?(\*|\s)[ ]?/gm;
// Blocksearch depending on file-extension
switch(self.extension)
{
case ".erl":
// Find document blocks between "%{" and "%}"
docBlocksRegExp = /\%\{\uffff(.+?)\%\}/g;
// Remove not needed " % " and " " (tabs) at the beginning
// HINT: Not sure if erlang developer use the %, but i think it should be no problem
inlineRegExp = /^(\t+)?(\%)[ ]?/gm;
break;
case ".py":
// Find document blocks between """ and """
docBlocksRegExp = /\"\"\"\uffff(.+?)\"\"\"/g;
// Remove not needed " " (tabs) at the beginning
inlineRegExp = /^(\t+)?[ ]?/gm;
break;
case ".rb":
// Find document blocks between "=begin" and "=end"
docBlocksRegExp = /\=begin\uffff(.+?)\=end/g;
// Remove not needed " " (tabs) at the beginning
inlineRegExp = /^(\t+)?[ ]?/gm;
break;
default:
// Find document blocks between "/**" and "*/"
docBlocksRegExp = /\/\*\*\uffff(.+?)\*\//g;
// Remove not needed " * " and " " (tabs) at the beginning
inlineRegExp = /^(\s+)?(\*)[ ]?/gm;
} // switch

// Find documentsblocks between "/**" and "*/"
var docBlocksRegExp = /\/\*\*\uffff(.+?)\*\//g;
var matches = docBlocksRegExp.exec(src);
while(matches)
{
Expand All @@ -281,7 +308,7 @@ Parser.prototype._findBlocks = function()
// Reverse Unicode Linebreaks
block = block.replace(/\uffff/g, "\n");

block = block.replace(starsRegExp, "");
block = block.replace(inlineRegExp, "");

blocks.push(block);

Expand Down
168 changes: 164 additions & 4 deletions test/fixtures/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,166 @@ define({ api: [
},
"filename": "test/fixtures/example/_grouping.js"
},
{
"type": "get",
"url": "/language/erlang",
"title": "Erlang",
"name": "GetLanguageErlang",
"group": "Language",
"version": "0.4.0",
"description": "Test for Erlang Comment-Syntax.",
"filename": "test/fixtures/example/language.erl"
},
{
"type": "get",
"url": "/language/erlang/indented1",
"title": "Erlang indented 1",
"name": "GetLanguageErlangIndented1",
"group": "Language",
"version": "0.4.0",
"examples": [
{
"title": "Test for indented comment.",
"content": "This is example line 2.\nThis is example line 3.\n\t Line 4 indented (with tab at beginning).\n Line 5 indented.\nThis is example line 6.\n"
}
],
"filename": "test/fixtures/example/language.erl"
},
{
"type": "get",
"url": "/language/erlang/indented2",
"title": "Erlang indented 2",
"name": "GetLanguageErlangIndented2",
"group": "Language",
"version": "0.4.0",
"examples": [
{
"title": "Test for indented comment.",
"content": "This is example line 2.\nThis is example line 3.\n Line 4 indented (with tab at beginning).\n Line 5 indented.\nThis is example line 6.\n"
}
],
"filename": "test/fixtures/example/language.erl"
},
{
"type": "get",
"url": "/language/javascript",
"title": "JavaScript",
"name": "GetLanguageJavaScript",
"group": "Language",
"version": "0.4.0",
"description": "Test for JavaScript Comment-Syntax.",
"filename": "test/fixtures/example/language.js"
},
{
"type": "get",
"url": "/language/javascript/indented1",
"title": "JavaScript indented 1",
"name": "GetLanguageJavaScriptIndented1",
"group": "Language",
"version": "0.4.0",
"examples": [
{
"title": "Test for indented comment.",
"content": "This is example line 2.\nThis is example line 3.\n Line 4 indented (with tab at beginning).\n Line 5 indented.\nThis is example line 6.\n"
}
],
"filename": "test/fixtures/example/language.js"
},
{
"type": "get",
"url": "/language/javascript/indented2",
"title": "JavaScript indented 2",
"name": "GetLanguageJavaScriptIndented2",
"group": "Language",
"version": "0.4.0",
"examples": [
{
"title": "Test for indented comment.",
"content": "This is example line 2.\nThis is example line 3.\n Line 4 indented (with tab at beginning).\n Line 5 indented.\nThis is example line 6.\n"
}
],
"filename": "test/fixtures/example/language.js"
},
{
"type": "get",
"url": "/language/python",
"title": "Python",
"name": "GetLanguagePython",
"group": "Language",
"version": "0.4.0",
"description": "Test for Python Comment-Syntax.",
"filename": "test/fixtures/example/language.py"
},
{
"type": "get",
"url": "/language/python/indented1",
"title": "Python indented 1",
"name": "GetLanguagePythonIndented1",
"group": "Language",
"version": "0.4.0",
"examples": [
{
"title": "Test for indented comment.",
"content": "This is example line 2.\nThis is example line 3.\n Line 4 indented (with tab at beginning).\n Line 5 indented.\nThis is example line 6.\n"
}
],
"filename": "test/fixtures/example/language.py"
},
{
"type": "get",
"url": "/language/python/indented2",
"title": "Python indented 2",
"name": "GetLanguagePythonIndented2",
"group": "Language",
"version": "0.4.0",
"examples": [
{
"title": "Test for indented comment.",
"content": "This is example line 2.\nThis is example line 3.\n Line 4 indented (with tab at beginning).\n Line 5 indented.\nThis is example line 6.\n"
}
],
"filename": "test/fixtures/example/language.py"
},
{
"type": "get",
"url": "/language/ruby",
"title": "Ruby",
"name": "GetLanguageRuby",
"group": "Language",
"version": "0.4.0",
"description": "Test for Ruby Comment-Syntax.",
"filename": "test/fixtures/example/language.rb"
},
{
"type": "get",
"url": "/language/ruby/indented1",
"title": "Ruby indented 1",
"name": "GetLanguageRubyIndented1",
"group": "Language",
"version": "0.4.0",
"examples": [
{
"title": "Test for indented comment.",
"content": "This is example line 2.\nThis is example line 3.\n Line 4 indented (with tab at beginning).\n Line 5 indented.\nThis is example line 6.\n"
}
],
"filename": "test/fixtures/example/language.rb"
},
{
"type": "get",
"url": "/language/ruby/indented2",
"title": "Ruby indented 2",
"name": "GetLanguageRubyIndented2",
"group": "Language",
"version": "0.4.0",
"examples": [
{
"title": "Test for indented comment.",
"content": "This is example line 2.\nThis is example line 3.\n Line 4 indented (with tab at beginning).\n Line 5 indented.\nThis is example line 6.\n"
}
],
"filename": "test/fixtures/example/language.rb"
},
{
"type": "get",
"url": "/param/:id",
Expand Down Expand Up @@ -549,9 +709,9 @@ define({ api: [
"Parameter": [
{
"group": "Parameter",
"field": "field1",
"field": "field2",
"optional": false,
"description": "This is Field 1."
"description": "This is Field 2."
}
]
}
Expand All @@ -568,9 +728,9 @@ define({ api: [
"Parameter": [
{
"group": "Parameter",
"field": "field2",
"field": "field1",
"optional": false,
"description": "This is Field 2."
"description": "This is Field 1."
}
]
}
Expand Down
Loading

0 comments on commit b531ec0

Please sign in to comment.