Permalink
Browse files

Version 0.2.0

  • Loading branch information...
1 parent 66286fa commit 9863ae42631da5b599b0cf705d086c6bf3c24687 @rottmann rottmann committed Dec 17, 2014
Showing with 6,123 additions and 29 deletions.
  1. +1 −28 .gitignore
  2. +6 −0 .npmignore
  3. +3 −0 .travis.yml
  4. +9 −1 README.md
  5. +27 −0 lib/errors/file_error.js
  6. +23 −0 lib/errors/parameter_error.js
  7. +25 −0 lib/errors/parser_error.js
  8. +26 −0 lib/errors/worker_error.js
  9. +68 −0 lib/filter.js
  10. +19 −0 lib/filters/api_error.js
  11. +19 −0 lib/filters/api_header.js
  12. +40 −0 lib/filters/api_param.js
  13. +19 −0 lib/filters/api_success.js
  14. +271 −0 lib/index.js
  15. +461 −0 lib/parser.js
  16. +27 −0 lib/parsers/api.js
  17. +55 −0 lib/parsers/api_define.js
  18. +27 −0 lib/parsers/api_define_error_structure.js
  19. +27 −0 lib/parsers/api_define_header_structure.js
  20. +27 −0 lib/parsers/api_define_permission.js
  21. +27 −0 lib/parsers/api_define_structure.js
  22. +27 −0 lib/parsers/api_define_success_structure.js
  23. +21 −0 lib/parsers/api_description.js
  24. +20 −0 lib/parsers/api_error.js
  25. +11 −0 lib/parsers/api_error_example.js
  26. +14 −0 lib/parsers/api_error_structure.js
  27. +14 −0 lib/parsers/api_error_title.js
  28. +42 −0 lib/parsers/api_example.js
  29. +20 −0 lib/parsers/api_group.js
  30. +23 −0 lib/parsers/api_group_description.js
  31. +20 −0 lib/parsers/api_header.js
  32. +11 −0 lib/parsers/api_header_example.js
  33. +14 −0 lib/parsers/api_header_structure.js
  34. +14 −0 lib/parsers/api_header_title.js
  35. +20 −0 lib/parsers/api_name.js
  36. +134 −0 lib/parsers/api_param.js
  37. +11 −0 lib/parsers/api_param_example.js
  38. +31 −0 lib/parsers/api_param_title.js
  39. +12 −0 lib/parsers/api_permission.js
  40. +20 −0 lib/parsers/api_sample_request.js
  41. +14 −0 lib/parsers/api_structure.js
  42. +20 −0 lib/parsers/api_success.js
  43. +11 −0 lib/parsers/api_success_example.js
  44. +14 −0 lib/parsers/api_success_structure.js
  45. +14 −0 lib/parsers/api_success_title.js
  46. +21 −0 lib/parsers/api_use.js
  47. +28 −0 lib/parsers/api_version.js
  48. +125 −0 lib/utils/find_files.js
  49. +98 −0 lib/worker.js
  50. +43 −0 lib/workers/api_error_structure.js
  51. +43 −0 lib/workers/api_error_title.js
  52. +177 −0 lib/workers/api_group.js
  53. +43 −0 lib/workers/api_header_structure.js
  54. +43 −0 lib/workers/api_header_title.js
  55. +52 −0 lib/workers/api_name.js
  56. +165 −0 lib/workers/api_param_title.js
  57. +157 −0 lib/workers/api_permission.js
  58. +47 −0 lib/workers/api_sample_request.js
  59. +43 −0 lib/workers/api_structure.js
  60. +43 −0 lib/workers/api_success_structure.js
  61. +43 −0 lib/workers/api_success_title.js
  62. +160 −0 lib/workers/api_use.js
  63. +34 −0 lib/workers/deprecated_api_error_title.js
  64. +34 −0 lib/workers/deprecated_api_header_title.js
  65. +87 −0 lib/workers/deprecated_api_param_title.js
  66. +34 −0 lib/workers/deprecated_api_success_title.js
  67. +64 −0 package.json
  68. +129 −0 test/apidoc_test.js
  69. +1,750 −0 test/fixtures/api_data.json
  70. +29 −0 test/fixtures/api_project.json
  71. +29 −0 test/fixtures/example/_grouping.js
  72. +9 −0 test/fixtures/example/_syntax.js
  73. +22 −0 test/fixtures/example/apidoc.json
  74. +26 −0 test/fixtures/example/define.js
  75. +28 −0 test/fixtures/example/error_structure.js
  76. +39 −0 test/fixtures/example/escape.js
  77. +45 −0 test/fixtures/example/example.js
  78. +3 −0 test/fixtures/example/footer.md
  79. +8 −0 test/fixtures/example/group.js
  80. +27 −0 test/fixtures/example/header.js
  81. +3 −0 test/fixtures/example/header.md
  82. +10 −0 test/fixtures/example/header_example.js
  83. +28 −0 test/fixtures/example/header_structure.js
  84. +11 −0 test/fixtures/example/header_title.js
  85. +35 −0 test/fixtures/example/language.coffee
  86. +35 −0 test/fixtures/example/language.erl
  87. +35 −0 test/fixtures/example/language.js
  88. +48 −0 test/fixtures/example/language.pm
  89. +35 −0 test/fixtures/example/language.py
  90. +35 −0 test/fixtures/example/language.rb
  91. +19 −0 test/fixtures/example/markdown.js
  92. +71 −0 test/fixtures/example/param.js
  93. +16 −0 test/fixtures/example/param_example.js
  94. +11 −0 test/fixtures/example/param_title.js
  95. +26 −0 test/fixtures/example/permission.js
  96. +23 −0 test/fixtures/example/sample_request.js
  97. +28 −0 test/fixtures/example/structure.js
  98. +28 −0 test/fixtures/example/success_structure.js
  99. +24 −0 test/fixtures/example/title_and_structure.js
  100. +102 −0 test/parser_api_param_test.js
  101. +13 −0 test/template/index.html
View
@@ -1,28 +1 @@
-# Logs
-logs
-*.log
-
-# Runtime data
-pids
-*.pid
-*.seed
-
-# Directory for instrumented libs generated by jscoverage/JSCover
-lib-cov
-
-# Coverage directory used by tools like istanbul
-coverage
-
-# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
-.grunt
-
-# Compiled binary addons (http://nodejs.org/api/addons.html)
-build/Release
-
-# Dependency directory
-# Commenting this out is preferred by some people, see
-# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
-node_modules
-
-# Users Environment Variables
-.lock-wscript
+node_modules/
View
@@ -0,0 +1,6 @@
+.git/
+node_modules/
+test/
+.gitignore
+.npmignore
+.travis.yml
View
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - 0.10
View
@@ -1,5 +1,13 @@
# apidoc-core
-Core parser library to generate apidoc.json result following the [apidoc-spec](https://github.com/apidoc/apidoc-spec)
+Core parser library to generate apidoc result following the [apidoc-spec](https://github.com/apidoc/apidoc-spec)
+
+[![Build Status](https://travis-ci.org/apidoc/apidoc-core.svg?branch=master)](https://travis-ci.org/apidoc/apidoc-core)
+[![Dependency Status](https://david-dm.org/apidoc/apidoc-core.svg)](https://david-dm.org/apidoc/apidoc-core)
+[![NPM version](https://badge.fury.io/js/apidoc-core.svg)](http://badge.fury.io/js/apidoc-core)
If you are an end user, please proceed to [apidoc](https://github.com/apidoc/apidoc) or [apidoc-documentation](http://apidocjs.com).
+
+[Changelog](https://github.com/apidoc/apidoc/blob/master/CHANGELOG.md).
+
+The apidoc-core major and minor version represent the used apidoc-spec version.
@@ -0,0 +1,27 @@
+var util = require('util');
+var fs = require('path');
+
+function FileError(message, file, path) {
+ // enable stack trace
+ Error.call(this);
+ Error.captureStackTrace(this, this.constructor);
+ this.name = this.constructor.name;
+
+ this.message = message;
+ this.file = file || '';
+ this.path = path || file;
+
+ if (this.path && this.path.charAt(this.path.length - 1) !== '/') {
+ this.path = fs.dirname(this.path);
+ }
+}
+
+/**
+ * Inherit from Error
+ */
+util.inherits(FileError, Error);
+
+/**
+ * Exports
+ */
+module.exports = FileError;
@@ -0,0 +1,23 @@
+var util = require('util');
+
+function ParameterError(message, element, definition, example) {
+ // enable stack trace
+ Error.call(this);
+ Error.captureStackTrace(this, this.constructor);
+ this.name = this.constructor.name;
+
+ this.message = message;
+ this.element = element;
+ this.definition = definition;
+ this.example = example;
+}
+
+/**
+ * Inherit from Error
+ */
+util.inherits(ParameterError, Error);
+
+/**
+ * Exports
+ */
+module.exports = ParameterError;
@@ -0,0 +1,25 @@
+var util = require('util');
+
+function ParserError(message, file, block, element, source, extra) {
+ // enable stack trace
+ Error.call(this);
+ Error.captureStackTrace(this, this.constructor);
+ this.name = this.constructor.name;
+
+ this.message = message;
+ this.file = file;
+ this.block = block;
+ this.element = element;
+ this.source = source;
+ this.extra = extra || [];
+}
+
+/**
+ * Inherit from Error
+ */
+util.inherits(ParserError, Error);
+
+/**
+ * Exports
+ */
+module.exports = ParserError;
@@ -0,0 +1,26 @@
+var util = require('util');
+
+function WorkerError(message, file, block, element, definition, example, extra) {
+ // enable stack trace
+ Error.call(this);
+ Error.captureStackTrace(this, this.constructor);
+ this.name = this.constructor.name;
+
+ this.message = message;
+ this.file = file;
+ this.block = block;
+ this.element = element;
+ this.definition = definition;
+ this.example = example;
+ this.extra = extra;
+}
+
+/**
+ * Inherit from Error
+ */
+util.inherits(WorkerError, Error);
+
+/**
+ * Exports
+ */
+module.exports = WorkerError;
View
@@ -0,0 +1,68 @@
+var util = require('util');
+var _ = require('lodash');
+
+var app = {};
+
+/**
+ * Filter
+ * Cleanup the data, e.g.: remove double fields, happen when overwrite a global inherited field with a local definition.
+ *
+ * @param {Object} _app
+ */
+function Filter(_app) {
+ var self = this;
+
+ // global variables
+ app = _app;
+
+ // class variables
+ this.filters = {};
+
+ // load filters
+ var filters = Object.keys(app.filters);
+ filters.forEach(function(filter) {
+ var filename = app.filters[filter];
+ app.log.debug('load filter: ' + filter + ', ' + filename);
+ self.addFilter(filter, require(filename));
+ });
+}
+
+/**
+ * Inherit
+ */
+util.inherits(Filter, Object);
+
+/**
+ * Exports
+ */
+module.exports = Filter;
+
+/**
+ * Add Filter
+ */
+Filter.prototype.addFilter = function(name, filter) {
+ this.filters[name] = filter;
+};
+
+/**
+ * Execute filter
+ */
+Filter.prototype.process = function(parsedFiles, parsedFilenames) {
+ // filter each @api-Parameter
+ _.each(this.filters, function(filter, name) {
+ if (filter.postFilter) {
+ app.log.verbose('filter postFilter: ' + name);
+ filter.postFilter(parsedFiles, parsedFilenames);
+ }
+ });
+
+ // reduce to local blocks where global is empty
+ var blocks = [];
+ parsedFiles.forEach(function(parsedFile) {
+ parsedFile.forEach(function(block) {
+ if (Object.keys(block.global).length === 0 && Object.keys(block.local).length > 0)
+ blocks.push(block.local);
+ });
+ });
+ return blocks;
+};
@@ -0,0 +1,19 @@
+// Same as @apiParam
+var filterApiParam = require('./api_param.js');
+
+/**
+ * Post Filter parsed results.
+ *
+ * @param {Object[]} parsedFiles
+ * @param {String[]} filenames
+ */
+function postFilter(parsedFiles, filenames) {
+ filterApiParam.postFilter(parsedFiles, filenames, 'error');
+}
+
+/**
+ * Exports
+ */
+module.exports = {
+ postFilter: postFilter
+};
@@ -0,0 +1,19 @@
+// Same as @apiParam
+var filterApiParam = require('./api_param.js');
+
+/**
+ * Post Filter parsed results.
+ *
+ * @param {Object[]} parsedFiles
+ * @param {String[]} filenames
+ */
+function postFilter(parsedFiles, filenames) {
+ filterApiParam.postFilter(parsedFiles, filenames, 'header');
+}
+
+/**
+ * Exports
+ */
+module.exports = {
+ postFilter: postFilter
+};
@@ -0,0 +1,40 @@
+/**
+ * Post Filter parsed results
+ * Remove double fields, happen when overwrite a global inherited field with a local definition.
+ *
+ * @param {Object[]} parsedFiles
+ * @param {String[]} filenames
+ * @param {String} tagName Example: 'parameter'
+ * @returns {Object}
+ */
+function postFilter(parsedFiles, filenames, tagName) {
+ tagName = tagName || 'parameter';
+
+ parsedFiles.forEach(function(parsedFile) {
+ parsedFile.forEach(function(block) {
+ if (block.local[tagName] && block.local[tagName].fields) {
+ var blockFields = block.local[tagName].fields;
+ Object.keys(blockFields).forEach(function(blockFieldKey) {
+ var fields = block.local[tagName].fields[blockFieldKey];
+ var newFields = [];
+ var existingKeys = {};
+ fields.forEach(function(field) {
+ var key = field.field; // .field (=id) is the key to check if it exists twice
+ if ( ! existingKeys[key]) {
+ existingKeys[key] = 1;
+ newFields.push(field);
+ }
+ });
+ block.local[tagName].fields[blockFieldKey] = newFields;
+ });
+ }
+ });
+ });
+}
+
+/**
+ * Exports
+ */
+module.exports = {
+ postFilter: postFilter
+};
@@ -0,0 +1,19 @@
+// Same as @apiParam
+var filterApiParam = require('./api_param.js');
+
+/**
+ * Post Filter parsed results.
+ *
+ * @param {Object[]} parsedFiles
+ * @param {String[]} filenames
+ */
+function postFilter(parsedFiles, filenames) {
+ filterApiParam.postFilter(parsedFiles, filenames, 'success');
+}
+
+/**
+ * Exports
+ */
+module.exports = {
+ postFilter: postFilter
+};
Oops, something went wrong.

0 comments on commit 9863ae4

Please sign in to comment.