jsdoc-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +5 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +94 -0
  5. data/Rakefile +29 -0
  6. data/app/controllers/jsdoc/documentation_controller.rb +48 -0
  7. data/app/helpers/jsdoc/documentation_helper.rb +50 -0
  8. data/app/models/jsdoc/borrowed_function.rb +7 -0
  9. data/app/models/jsdoc/borrowed_property.rb +7 -0
  10. data/app/models/jsdoc/example.rb +5 -0
  11. data/app/models/jsdoc/function.rb +21 -0
  12. data/app/models/jsdoc/param.rb +7 -0
  13. data/app/models/jsdoc/property.rb +13 -0
  14. data/app/models/jsdoc/require.rb +5 -0
  15. data/app/models/jsdoc/return.rb +5 -0
  16. data/app/models/jsdoc/see.rb +4 -0
  17. data/app/models/jsdoc/symbol.rb +58 -0
  18. data/app/models/jsdoc/throw.rb +4 -0
  19. data/app/views/jsdoc/documentation/_inheritance_tree_branch.html.erb +12 -0
  20. data/app/views/jsdoc/documentation/_members_table.html.erb +38 -0
  21. data/app/views/jsdoc/documentation/_param_list.html.erb +11 -0
  22. data/app/views/jsdoc/documentation/index.html.erb +7 -0
  23. data/app/views/jsdoc/documentation/source.html.erb +11 -0
  24. data/app/views/jsdoc/documentation/symbol.html.erb +111 -0
  25. data/app/views/layouts/jsdoc/_aside_symbol_list.html.erb +12 -0
  26. data/app/views/layouts/jsdoc/_header.html.erb +1 -0
  27. data/app/views/layouts/jsdoc/_symbol_tree_branch.html.erb +3 -0
  28. data/app/views/layouts/jsdoc/documentation.html.erb +44 -0
  29. data/app/views/layouts/jsdoc/documentation_wrapper.html.erb +2 -0
  30. data/config/routes.rb +8 -0
  31. data/jsdoc-rails.gemspec +25 -0
  32. data/jsdoc-toolkit/README.txt +183 -0
  33. data/jsdoc-toolkit/app/frame.js +33 -0
  34. data/jsdoc-toolkit/app/frame/Chain.js +102 -0
  35. data/jsdoc-toolkit/app/frame/Dumper.js +144 -0
  36. data/jsdoc-toolkit/app/frame/Hash.js +84 -0
  37. data/jsdoc-toolkit/app/frame/Link.js +173 -0
  38. data/jsdoc-toolkit/app/frame/Namespace.js +10 -0
  39. data/jsdoc-toolkit/app/frame/Opt.js +134 -0
  40. data/jsdoc-toolkit/app/frame/Reflection.js +26 -0
  41. data/jsdoc-toolkit/app/frame/String.js +93 -0
  42. data/jsdoc-toolkit/app/frame/Testrun.js +129 -0
  43. data/jsdoc-toolkit/app/handlers/FOODOC.js +26 -0
  44. data/jsdoc-toolkit/app/handlers/XMLDOC.js +26 -0
  45. data/jsdoc-toolkit/app/handlers/XMLDOC/DomReader.js +159 -0
  46. data/jsdoc-toolkit/app/handlers/XMLDOC/XMLDoc.js +16 -0
  47. data/jsdoc-toolkit/app/handlers/XMLDOC/XMLParse.js +292 -0
  48. data/jsdoc-toolkit/app/lib/JSDOC.js +106 -0
  49. data/jsdoc-toolkit/app/lib/JSDOC/DocComment.js +204 -0
  50. data/jsdoc-toolkit/app/lib/JSDOC/DocTag.js +294 -0
  51. data/jsdoc-toolkit/app/lib/JSDOC/JsDoc.js +140 -0
  52. data/jsdoc-toolkit/app/lib/JSDOC/JsPlate.js +109 -0
  53. data/jsdoc-toolkit/app/lib/JSDOC/Lang.js +144 -0
  54. data/jsdoc-toolkit/app/lib/JSDOC/Parser.js +146 -0
  55. data/jsdoc-toolkit/app/lib/JSDOC/PluginManager.js +33 -0
  56. data/jsdoc-toolkit/app/lib/JSDOC/Symbol.js +646 -0
  57. data/jsdoc-toolkit/app/lib/JSDOC/SymbolSet.js +243 -0
  58. data/jsdoc-toolkit/app/lib/JSDOC/TextStream.js +41 -0
  59. data/jsdoc-toolkit/app/lib/JSDOC/Token.js +18 -0
  60. data/jsdoc-toolkit/app/lib/JSDOC/TokenReader.js +332 -0
  61. data/jsdoc-toolkit/app/lib/JSDOC/TokenStream.js +133 -0
  62. data/jsdoc-toolkit/app/lib/JSDOC/Util.js +32 -0
  63. data/jsdoc-toolkit/app/lib/JSDOC/Walker.js +557 -0
  64. data/jsdoc-toolkit/app/main.js +111 -0
  65. data/jsdoc-toolkit/app/plugins/commentSrcJson.js +20 -0
  66. data/jsdoc-toolkit/app/plugins/frameworkPrototype.js +16 -0
  67. data/jsdoc-toolkit/app/plugins/functionCall.js +10 -0
  68. data/jsdoc-toolkit/app/plugins/publishSrcHilite.js +62 -0
  69. data/jsdoc-toolkit/app/plugins/symbolLink.js +10 -0
  70. data/jsdoc-toolkit/app/plugins/tagParamConfig.js +31 -0
  71. data/jsdoc-toolkit/app/plugins/tagSynonyms.js +45 -0
  72. data/jsdoc-toolkit/app/run.js +348 -0
  73. data/jsdoc-toolkit/app/t/TestDoc.js +144 -0
  74. data/jsdoc-toolkit/app/t/runner.js +13 -0
  75. data/jsdoc-toolkit/app/test.js +342 -0
  76. data/jsdoc-toolkit/app/test/addon.js +24 -0
  77. data/jsdoc-toolkit/app/test/anon_inner.js +14 -0
  78. data/jsdoc-toolkit/app/test/augments.js +31 -0
  79. data/jsdoc-toolkit/app/test/augments2.js +26 -0
  80. data/jsdoc-toolkit/app/test/borrows.js +46 -0
  81. data/jsdoc-toolkit/app/test/borrows2.js +23 -0
  82. data/jsdoc-toolkit/app/test/config.js +22 -0
  83. data/jsdoc-toolkit/app/test/constructs.js +18 -0
  84. data/jsdoc-toolkit/app/test/encoding.js +10 -0
  85. data/jsdoc-toolkit/app/test/encoding_other.js +12 -0
  86. data/jsdoc-toolkit/app/test/event.js +54 -0
  87. data/jsdoc-toolkit/app/test/exports.js +14 -0
  88. data/jsdoc-toolkit/app/test/functions_anon.js +39 -0
  89. data/jsdoc-toolkit/app/test/functions_nested.js +33 -0
  90. data/jsdoc-toolkit/app/test/global.js +13 -0
  91. data/jsdoc-toolkit/app/test/globals.js +25 -0
  92. data/jsdoc-toolkit/app/test/ignore.js +10 -0
  93. data/jsdoc-toolkit/app/test/inner.js +16 -0
  94. data/jsdoc-toolkit/app/test/jsdoc_test.js +477 -0
  95. data/jsdoc-toolkit/app/test/lend.js +33 -0
  96. data/jsdoc-toolkit/app/test/memberof.js +19 -0
  97. data/jsdoc-toolkit/app/test/memberof2.js +38 -0
  98. data/jsdoc-toolkit/app/test/memberof3.js +33 -0
  99. data/jsdoc-toolkit/app/test/memberof_constructor.js +17 -0
  100. data/jsdoc-toolkit/app/test/module.js +17 -0
  101. data/jsdoc-toolkit/app/test/multi_methods.js +25 -0
  102. data/jsdoc-toolkit/app/test/name.js +19 -0
  103. data/jsdoc-toolkit/app/test/namespace_nested.js +23 -0
  104. data/jsdoc-toolkit/app/test/nocode.js +13 -0
  105. data/jsdoc-toolkit/app/test/oblit_anon.js +20 -0
  106. data/jsdoc-toolkit/app/test/overview.js +20 -0
  107. data/jsdoc-toolkit/app/test/param_inline.js +37 -0
  108. data/jsdoc-toolkit/app/test/params_optional.js +8 -0
  109. data/jsdoc-toolkit/app/test/prototype.js +17 -0
  110. data/jsdoc-toolkit/app/test/prototype_nested.js +9 -0
  111. data/jsdoc-toolkit/app/test/prototype_oblit.js +13 -0
  112. data/jsdoc-toolkit/app/test/prototype_oblit_constructor.js +24 -0
  113. data/jsdoc-toolkit/app/test/public.js +10 -0
  114. data/jsdoc-toolkit/app/test/scripts/code.js +5 -0
  115. data/jsdoc-toolkit/app/test/scripts/notcode.txt +5 -0
  116. data/jsdoc-toolkit/app/test/shared.js +42 -0
  117. data/jsdoc-toolkit/app/test/shared2.js +2 -0
  118. data/jsdoc-toolkit/app/test/shortcuts.js +22 -0
  119. data/jsdoc-toolkit/app/test/static_this.js +13 -0
  120. data/jsdoc-toolkit/app/test/synonyms.js +31 -0
  121. data/jsdoc-toolkit/app/test/tosource.js +23 -0
  122. data/jsdoc-toolkit/app/test/variable_redefine.js +14 -0
  123. data/jsdoc-toolkit/changes.txt +124 -0
  124. data/jsdoc-toolkit/conf/sample.conf +31 -0
  125. data/jsdoc-toolkit/java/build.xml +36 -0
  126. data/jsdoc-toolkit/java/build_1.4.xml +36 -0
  127. data/jsdoc-toolkit/java/classes/js.jar +0 -0
  128. data/jsdoc-toolkit/java/src/JsDebugRun.java +21 -0
  129. data/jsdoc-toolkit/java/src/JsRun.java +21 -0
  130. data/jsdoc-toolkit/jsdebug.jar +0 -0
  131. data/jsdoc-toolkit/jsrun.jar +0 -0
  132. data/jsdoc-toolkit/jsrun.sh +52 -0
  133. data/jsdoc-toolkit/templates/jsdoc-rails/publish.js +202 -0
  134. data/jsdoc-toolkit/templates/jsdoc-rails/seeds.tmpl +449 -0
  135. data/jsdoc-toolkit/templates/jsdoc/allclasses.tmpl +17 -0
  136. data/jsdoc-toolkit/templates/jsdoc/allfiles.tmpl +56 -0
  137. data/jsdoc-toolkit/templates/jsdoc/class.tmpl +649 -0
  138. data/jsdoc-toolkit/templates/jsdoc/index.tmpl +39 -0
  139. data/jsdoc-toolkit/templates/jsdoc/publish.js +201 -0
  140. data/jsdoc-toolkit/templates/jsdoc/static/default.css +162 -0
  141. data/jsdoc-toolkit/templates/jsdoc/static/header.html +2 -0
  142. data/jsdoc-toolkit/templates/jsdoc/static/index.html +19 -0
  143. data/jsdoc-toolkit/templates/jsdoc/symbol.tmpl +35 -0
  144. data/lib/generators/jsdoc/jsdoc_generator.rb +71 -0
  145. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_borrowed_functions_table.rb +19 -0
  146. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_borrowed_properties_table.rb +19 -0
  147. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_examples_table.rb +18 -0
  148. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_functions_table.rb +33 -0
  149. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_params_table.rb +24 -0
  150. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_properties_table.rb +37 -0
  151. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_requires_table.rb +16 -0
  152. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_returns_table.rb +18 -0
  153. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_sees_table.rb +18 -0
  154. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_symbols_table.rb +31 -0
  155. data/lib/generators/jsdoc/templates/migrations/jsdoc_create_throws_table.rb +18 -0
  156. data/lib/jsdoc.rb +3 -0
  157. data/lib/jsdoc/engine.rb +30 -0
  158. data/lib/jsdoc/railties/tasks.rake +89 -0
  159. data/lib/jsdoc/version.rb +3 -0
  160. data/public/images/jsdoc/icons/class.gif +0 -0
  161. data/public/images/jsdoc/icons/cmp.gif +0 -0
  162. data/public/images/jsdoc/icons/docs.gif +0 -0
  163. data/public/images/jsdoc/icons/elbow-end.gif +0 -0
  164. data/public/images/jsdoc/icons/elbow-minus.gif +0 -0
  165. data/public/images/jsdoc/icons/elbow-plus.gif +0 -0
  166. data/public/images/jsdoc/icons/elbow.gif +0 -0
  167. data/public/images/jsdoc/icons/event.gif +0 -0
  168. data/public/images/jsdoc/icons/inherited.gif +0 -0
  169. data/public/images/jsdoc/icons/method.gif +0 -0
  170. data/public/images/jsdoc/icons/pkg.gif +0 -0
  171. data/public/images/jsdoc/icons/prop.gif +0 -0
  172. data/public/images/jsdoc/icons/static.gif +0 -0
  173. data/public/javascripts/jsdoc/jsdoc.js +52 -0
  174. data/public/stylesheets/jsdoc/documentation.css +483 -0
  175. data/test/dummy/.gitignore +4 -0
  176. data/test/dummy/Rakefile +7 -0
  177. data/test/dummy/app/controllers/application_controller.rb +3 -0
  178. data/test/dummy/app/helpers/application_helper.rb +2 -0
  179. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  180. data/test/dummy/config.ru +4 -0
  181. data/test/dummy/config/application.rb +45 -0
  182. data/test/dummy/config/boot.rb +10 -0
  183. data/test/dummy/config/database.yml +22 -0
  184. data/test/dummy/config/environment.rb +5 -0
  185. data/test/dummy/config/environments/development.rb +26 -0
  186. data/test/dummy/config/environments/production.rb +49 -0
  187. data/test/dummy/config/environments/test.rb +35 -0
  188. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  189. data/test/dummy/config/initializers/inflections.rb +10 -0
  190. data/test/dummy/config/initializers/jsdoc.rb +5 -0
  191. data/test/dummy/config/initializers/mime_types.rb +5 -0
  192. data/test/dummy/config/initializers/secret_token.rb +7 -0
  193. data/test/dummy/config/initializers/session_store.rb +8 -0
  194. data/test/dummy/config/locales/en.yml +5 -0
  195. data/test/dummy/config/routes.rb +58 -0
  196. data/test/dummy/db/.gitkeep +0 -0
  197. data/test/dummy/public/404.html +26 -0
  198. data/test/dummy/public/422.html +26 -0
  199. data/test/dummy/public/500.html +26 -0
  200. data/test/dummy/public/favicon.ico +0 -0
  201. data/test/dummy/public/javascripts/application.js +2 -0
  202. data/test/dummy/public/javascripts/controls.js +965 -0
  203. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  204. data/test/dummy/public/javascripts/effects.js +1123 -0
  205. data/test/dummy/public/javascripts/prototype.js +6001 -0
  206. data/test/dummy/public/javascripts/rails.js +175 -0
  207. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  208. data/test/dummy/script/rails +6 -0
  209. data/test/integration/navigation_test.rb +7 -0
  210. data/test/jsdoc_test.rb +7 -0
  211. data/test/support/integration_case.rb +5 -0
  212. data/test/test_helper.rb +22 -0
  213. metadata +297 -0
@@ -0,0 +1,106 @@
1
+ /**
2
+ @overview
3
+ @date $Date: 2010-06-13 22:02:44 +0100 (Sun, 13 Jun 2010) $
4
+ @version $Revision: 837 $
5
+ @location $HeadURL: https://jsdoc-toolkit.googlecode.com/svn/tags/jsdoc_toolkit-2.4.0/jsdoc-toolkit/app/lib/JSDOC.js $
6
+ @name JSDOC.js
7
+ */
8
+
9
+ /**
10
+ This is the main container for the JSDOC application.
11
+ @namespace
12
+ */
13
+ JSDOC = {
14
+ };
15
+
16
+ /**
17
+ @requires Opt
18
+ */
19
+ if (typeof arguments == "undefined") arguments = [];
20
+ JSDOC.opt = Opt.get(
21
+ arguments,
22
+ {
23
+ a: "allfunctions",
24
+ c: "conf",
25
+ d: "directory",
26
+ "D[]": "define",
27
+ e: "encoding",
28
+ "E[]": "exclude",
29
+ h: "help",
30
+ m: "multiple",
31
+ n: "nocode",
32
+ o: "out",
33
+ p: "private",
34
+ q: "quiet",
35
+ r: "recurse",
36
+ S: "securemodules",
37
+ s: "suppress",
38
+ t: "template",
39
+ T: "testmode",
40
+ u: "unique",
41
+ v: "verbose",
42
+ x: "ext"
43
+ }
44
+ );
45
+
46
+ /** The current version string of this application. */
47
+ JSDOC.VERSION = "2.4.0";
48
+
49
+ /** Print out usage information and quit. */
50
+ JSDOC.usage = function() {
51
+ print("USAGE: java -jar jsrun.jar app/run.js [OPTIONS] <SRC_DIR> <SRC_FILE> ...");
52
+ print("");
53
+ print("OPTIONS:");
54
+ print(" -a or --allfunctions\n Include all functions, even undocumented ones.\n");
55
+ print(" -c or --conf\n Load a configuration file.\n");
56
+ print(" -d=<PATH> or --directory=<PATH>\n Output to this directory (defaults to \"out\").\n");
57
+ print(" -D=\"myVar:My value\" or --define=\"myVar:My value\"\n Multiple. Define a variable, available in JsDoc as JSDOC.opt.D.myVar.\n");
58
+ print(" -e=<ENCODING> or --encoding=<ENCODING>\n Use this encoding to read and write files.\n");
59
+ print(" -E=\"REGEX\" or --exclude=\"REGEX\"\n Multiple. Exclude files based on the supplied regex.\n");
60
+ print(" -h or --help\n Show this message and exit.\n");
61
+ print(" -m or --multiples\n Don't warn about symbols being documented more than once.\n");
62
+ print(" -n or --nocode\n Ignore all code, only document comments with @name tags.\n");
63
+ print(" -o=<PATH> or --out=<PATH>\n Print log messages to a file (defaults to stdout).\n");
64
+ print(" -p or --private\n Include symbols tagged as private, underscored and inner symbols.\n");
65
+ print(" -q or --quiet\n Do not output any messages, not even warnings.\n");
66
+ print(" -r=<DEPTH> or --recurse=<DEPTH>\n Descend into src directories.\n");
67
+ print(" -s or --suppress\n Suppress source code output.\n");
68
+ print(" -S or --securemodules\n Use Secure Modules mode to parse source code.\n");
69
+ print(" -t=<PATH> or --template=<PATH>\n Required. Use this template to format the output.\n");
70
+ print(" -T or --test\n Run all unit tests and exit.\n");
71
+ print(" -u or --unique\n Force file names to be unique, but not based on symbol names.\n");
72
+ print(" -v or --verbose\n Provide verbose feedback about what is happening.\n");
73
+ print(" -x=<EXT>[,EXT]... or --ext=<EXT>[,EXT]...\n Scan source files with the given extension/s (defaults to js).\n");
74
+
75
+ quit();
76
+ }
77
+
78
+ /*t:
79
+ plan(4, "Testing JSDOC namespace.");
80
+
81
+ is(
82
+ typeof JSDOC,
83
+ "object",
84
+ "JSDOC.usage is a function."
85
+ );
86
+
87
+ is(
88
+ typeof JSDOC.VERSION,
89
+ "string",
90
+ "JSDOC.VERSION is a string."
91
+ );
92
+
93
+ is(
94
+ typeof JSDOC.usage,
95
+ "function",
96
+ "JSDOC.usage is a function."
97
+ );
98
+
99
+ is(
100
+ typeof JSDOC.opt,
101
+ "object",
102
+ "JSDOC.opt is a object."
103
+ );
104
+ */
105
+
106
+ if (this.IO) IO.includeDir("lib/JSDOC/");
@@ -0,0 +1,204 @@
1
+ if (typeof JSDOC == "undefined") JSDOC = {};
2
+
3
+ /**
4
+ Create a new DocComment. This takes a raw documentation comment,
5
+ and wraps it in useful accessors.
6
+ @class Represents a documentation comment object.
7
+ */
8
+ JSDOC.DocComment = function(/**String*/comment) {
9
+ this.init();
10
+ if (typeof comment != "undefined") {
11
+ this.parse(comment);
12
+ }
13
+ }
14
+
15
+ JSDOC.DocComment.prototype.init = function() {
16
+ this.isUserComment = true;
17
+ this.src = "";
18
+ this.meta = "";
19
+ this.tagTexts = [];
20
+ this.tags = [];
21
+ }
22
+
23
+ /**
24
+ @requires JSDOC.DocTag
25
+ */
26
+ JSDOC.DocComment.prototype.parse = function(/**String*/comment) {
27
+ if (comment == "") {
28
+ comment = "/** @desc */";
29
+ this.isUserComment = false;
30
+ }
31
+
32
+ this.src = JSDOC.DocComment.unwrapComment(comment);
33
+
34
+ this.meta = "";
35
+ if (this.src.indexOf("#") == 0) {
36
+ this.src.match(/#(.+[+-])([\s\S]*)$/);
37
+ if (RegExp.$1) this.meta = RegExp.$1;
38
+ if (RegExp.$2) this.src = RegExp.$2;
39
+ }
40
+
41
+ if (typeof JSDOC.PluginManager != "undefined") {
42
+ JSDOC.PluginManager.run("onDocCommentSrc", this);
43
+ }
44
+
45
+ this.fixDesc();
46
+
47
+ this.src = JSDOC.DocComment.shared+"\n"+this.src;
48
+
49
+ this.tagTexts =
50
+ this.src
51
+ .split(/(^|[\r\n])\s*@/)
52
+ .filter(function($){return $.match(/\S/)});
53
+
54
+ /**
55
+ The tags found in the comment.
56
+ @type JSDOC.DocTag[]
57
+ */
58
+ this.tags = this.tagTexts.map(function($){return new JSDOC.DocTag($)});
59
+
60
+ if (typeof JSDOC.PluginManager != "undefined") {
61
+ JSDOC.PluginManager.run("onDocCommentTags", this);
62
+ }
63
+ }
64
+
65
+ /*t:
66
+ plan(5, "testing JSDOC.DocComment");
67
+ requires("../frame/String.js");
68
+ requires("../lib/JSDOC/DocTag.js");
69
+
70
+ var com = new JSDOC.DocComment("/**@foo some\n* comment here*"+"/");
71
+ is(com.tagTexts[0], "foo some\ncomment here", "first tag text is found.");
72
+ is(com.tags[0].title, "foo", "the title is found in a comment with one tag.");
73
+
74
+ var com = new JSDOC.DocComment("/** @foo first\n* @bar second*"+"/");
75
+ is(com.getTag("bar").length, 1, "getTag() returns one tag by that title.");
76
+
77
+ JSDOC.DocComment.shared = "@author John Smith";
78
+ var com = new JSDOC.DocComment("/**@foo some\n* comment here*"+"/");
79
+ is(com.tags[0].title, "author", "shared comment is added.");
80
+ is(com.tags[1].title, "foo", "shared comment is added to existing tag.");
81
+ */
82
+
83
+ /**
84
+ If no @desc tag is provided, this function will add it.
85
+ */
86
+ JSDOC.DocComment.prototype.fixDesc = function() {
87
+ if (this.meta && this.meta != "@+") return;
88
+ if (/^\s*[^@\s]/.test(this.src)) {
89
+ this.src = "@desc "+this.src;
90
+ }
91
+ }
92
+
93
+ /*t:
94
+ plan(5, "testing JSDOC.DocComment#fixDesc");
95
+
96
+ var com = new JSDOC.DocComment();
97
+
98
+ com.src = "this is a desc\n@author foo";
99
+ com.fixDesc();
100
+ is(com.src, "@desc this is a desc\n@author foo", "if no @desc tag is provided one is added.");
101
+
102
+ com.src = "x";
103
+ com.fixDesc();
104
+ is(com.src, "@desc x", "if no @desc tag is provided one is added to a single character.");
105
+
106
+ com.src = "\nx";
107
+ com.fixDesc();
108
+ is(com.src, "@desc \nx", "if no @desc tag is provided one is added to return and character.");
109
+
110
+ com.src = " ";
111
+ com.fixDesc();
112
+ is(com.src, " ", "if no @desc tag is provided one is not added to just whitespace.");
113
+
114
+ com.src = "";
115
+ com.fixDesc();
116
+ is(com.src, "", "if no @desc tag is provided one is not added to empty.");
117
+ */
118
+
119
+ /**
120
+ Remove slash-star comment wrapper from a raw comment string.
121
+ @type String
122
+ */
123
+ JSDOC.DocComment.unwrapComment = function(/**String*/comment) {
124
+ if (!comment) return "";
125
+ var unwrapped = comment.replace(/(^\/\*\*|\*\/$)/g, "").replace(/^\s*\* ?/gm, "");
126
+ return unwrapped;
127
+ }
128
+
129
+ /*t:
130
+ plan(5, "testing JSDOC.DocComment.unwrapComment");
131
+
132
+ var com = "/**x*"+"/";
133
+ var unwrapped = JSDOC.DocComment.unwrapComment(com);
134
+ is(unwrapped, "x", "a single character jsdoc is found.");
135
+
136
+ com = "/***x*"+"/";
137
+ unwrapped = JSDOC.DocComment.unwrapComment(com);
138
+ is(unwrapped, "x", "three stars are allowed in the opener.");
139
+
140
+ com = "/****x*"+"/";
141
+ unwrapped = JSDOC.DocComment.unwrapComment(com);
142
+ is(unwrapped, "*x", "fourth star in the opener is kept.");
143
+
144
+ com = "/**x\n * y\n*"+"/";
145
+ unwrapped = JSDOC.DocComment.unwrapComment(com);
146
+ is(unwrapped, "x\ny\n", "leading stars and spaces are trimmed.");
147
+
148
+ com = "/**x\n * y\n*"+"/";
149
+ unwrapped = JSDOC.DocComment.unwrapComment(com);
150
+ is(unwrapped, "x\n y\n", "only first space after leading stars are trimmed.");
151
+ */
152
+
153
+ /**
154
+ Provides a printable version of the comment.
155
+ @type String
156
+ */
157
+ JSDOC.DocComment.prototype.toString = function() {
158
+ return this.src;
159
+ }
160
+
161
+ /*t:
162
+ plan(1, "testing JSDOC.DocComment#fixDesc");
163
+ var com = new JSDOC.DocComment();
164
+ com.src = "foo";
165
+ is(""+com, "foo", "stringifying a comment returns the unwrapped src.");
166
+ */
167
+
168
+ /**
169
+ Given the title of a tag, returns all tags that have that title.
170
+ @type JSDOC.DocTag[]
171
+ */
172
+ JSDOC.DocComment.prototype.getTag = function(/**String*/tagTitle) {
173
+ return this.tags.filter(function($){return $.title == tagTitle});
174
+ }
175
+
176
+ JSDOC.DocComment.prototype.deleteTag = function(/**String*/tagTitle) {
177
+ this.tags = this.tags.filter(function($){return $.title != tagTitle})
178
+ }
179
+
180
+ /*t:
181
+ plan(1, "testing JSDOC.DocComment#getTag");
182
+ requires("../frame/String.js");
183
+ requires("../lib/JSDOC/DocTag.js");
184
+
185
+ var com = new JSDOC.DocComment("/**@foo some\n* @bar\n* @bar*"+"/");
186
+ is(com.getTag("bar").length, 2, "getTag returns expected number of tags.");
187
+ */
188
+
189
+ /**
190
+ Used to store the currently shared tag text.
191
+ */
192
+ JSDOC.DocComment.shared = "";
193
+
194
+ /*t:
195
+ plan(2, "testing JSDOC.DocComment.shared");
196
+ requires("../frame/String.js");
197
+ requires("../lib/JSDOC/DocTag.js");
198
+
199
+ JSDOC.DocComment.shared = "@author Michael";
200
+
201
+ var com = new JSDOC.DocComment("/**@foo\n* @foo*"+"/");
202
+ is(com.getTag("author").length, 1, "getTag returns shared tag.");
203
+ is(com.getTag("foo").length, 2, "getTag returns unshared tags too.");
204
+ */
@@ -0,0 +1,294 @@
1
+ if (typeof JSDOC == "undefined") JSDOC = {};
2
+
3
+ /**
4
+ @constructor
5
+ */
6
+ JSDOC.DocTag = function(src) {
7
+ this.init();
8
+ if (typeof src != "undefined") {
9
+ this.parse(src);
10
+ }
11
+ }
12
+
13
+ /**
14
+ Create and initialize the properties of this.
15
+ */
16
+ JSDOC.DocTag.prototype.init = function() {
17
+ this.title = "";
18
+ this.type = "";
19
+ this.name = "";
20
+ this.isOptional = false;
21
+ this.defaultValue = "";
22
+ this.desc = "";
23
+
24
+ return this;
25
+ }
26
+
27
+ /**
28
+ Populate the properties of this from the given tag src.
29
+ @param {string} src
30
+ */
31
+ JSDOC.DocTag.prototype.parse = function(src) {
32
+ if (typeof src != "string") throw "src must be a string not "+(typeof src);
33
+
34
+ try {
35
+ src = this.nibbleTitle(src);
36
+ if (JSDOC.PluginManager) {
37
+ JSDOC.PluginManager.run("onDocTagSynonym", this);
38
+ }
39
+
40
+ src = this.nibbleType(src);
41
+
42
+ // only some tags are allowed to have names.
43
+ if (this.title == "param" || this.title == "property" || this.title == "config" || this.title == "option" || this.title == "opt") { // @config is deprecated
44
+ src = this.nibbleName(src);
45
+ }
46
+ }
47
+ catch(e) {
48
+ if (LOG) LOG.warn(e);
49
+ else throw e;
50
+ }
51
+ this.desc = src; // whatever is left
52
+
53
+ // example tags need to have whitespace preserved
54
+ if (this.title != "example") this.desc = this.desc.trim();
55
+
56
+ if (JSDOC.PluginManager) {
57
+ JSDOC.PluginManager.run("onDocTag", this);
58
+ }
59
+ }
60
+
61
+ /**
62
+ Automatically called when this is stringified.
63
+ */
64
+ JSDOC.DocTag.prototype.toString = function() {
65
+ return this.desc;
66
+ }
67
+
68
+ /*t:
69
+ plan(1, "testing JSDOC.DocTag#toString");
70
+
71
+ var tag = new JSDOC.DocTag("param {object} date A valid date.");
72
+ is(""+tag, "A valid date.", "stringifying a tag returns the desc.");
73
+ */
74
+
75
+ /**
76
+ Find and shift off the title of a tag.
77
+ @param {string} src
78
+ @return src
79
+ */
80
+ JSDOC.DocTag.prototype.nibbleTitle = function(src) {
81
+ if (typeof src != "string") throw "src must be a string not "+(typeof src);
82
+
83
+ var parts = src.match(/^\s*(\S+)(?:\s([\s\S]*))?$/);
84
+
85
+ if (parts && parts[1]) this.title = parts[1];
86
+ if (parts && parts[2]) src = parts[2];
87
+ else src = "";
88
+
89
+ return src;
90
+ }
91
+
92
+ /*t:
93
+ plan(8, "testing JSDOC.DocTag#nibbleTitle");
94
+
95
+ var tag = new JSDOC.DocTag();
96
+
97
+ tag.init().nibbleTitle("aTitleGoesHere");
98
+ is(tag.title, "aTitleGoesHere", "a title can be found in a single-word string.");
99
+
100
+ var src = tag.init().nibbleTitle("aTitleGoesHere and the rest");
101
+ is(tag.title, "aTitleGoesHere", "a title can be found in a multi-word string.");
102
+ is(src, "and the rest", "the rest is returned when the title is nibbled off.");
103
+
104
+ src = tag.init().nibbleTitle("");
105
+ is(tag.title, "", "given an empty string the title is empty.");
106
+ is(src, "", "the rest is empty when the tag is empty.");
107
+
108
+ var src = tag.init().nibbleTitle(" aTitleGoesHere\n a description");
109
+ is(tag.title, "aTitleGoesHere", "leading and trailing spaces are not part of the title.");
110
+ is(src, " a description", "leading spaces (less one) are part of the description.");
111
+
112
+ tag.init().nibbleTitle("a.Title::Goes_Here foo");
113
+ is(tag.title, "a.Title::Goes_Here", "titles with punctuation are allowed.");
114
+ */
115
+
116
+ /**
117
+ Find and shift off the type of a tag.
118
+ @requires frame/String.js
119
+ @param {string} src
120
+ @return src
121
+ */
122
+ JSDOC.DocTag.prototype.nibbleType = function(src) {
123
+ if (typeof src != "string") throw "src must be a string not "+(typeof src);
124
+
125
+ if (src.match(/^\s*\{/)) {
126
+ var typeRange = src.balance("{", "}");
127
+ if (typeRange[1] == -1) {
128
+ throw "Malformed comment tag ignored. Tag type requires an opening { and a closing }: "+src;
129
+ }
130
+ this.type = src.substring(typeRange[0]+1, typeRange[1]).trim();
131
+ this.type = this.type.replace(/\s*,\s*/g, "|"); // multiples can be separated by , or |
132
+ src = src.substring(typeRange[1]+1);
133
+ }
134
+
135
+ return src;
136
+ }
137
+
138
+ /*t:
139
+ plan(5, "testing JSDOC.DocTag.parser.nibbleType");
140
+ requires("../frame/String.js");
141
+
142
+ var tag = new JSDOC.DocTag();
143
+
144
+ tag.init().nibbleType("{String[]} aliases");
145
+ is(tag.type, "String[]", "type can have non-alpha characters.");
146
+
147
+ tag.init().nibbleType("{ aTypeGoesHere } etc etc");
148
+ is(tag.type, "aTypeGoesHere", "type is trimmed.");
149
+
150
+ tag.init().nibbleType("{ oneType, twoType ,\n threeType } etc etc");
151
+ is(tag.type, "oneType|twoType|threeType", "multiple types can be separated by commas.");
152
+
153
+ var error;
154
+ try { tag.init().nibbleType("{widget foo"); }
155
+ catch(e) { error = e; }
156
+ is(typeof error, "string", "malformed tag type throws error.");
157
+ isnt(error.indexOf("Malformed"), -1, "error message tells tag is malformed.");
158
+ */
159
+
160
+ /**
161
+ Find and shift off the name of a tag.
162
+ @requires frame/String.js
163
+ @param {string} src
164
+ @return src
165
+ */
166
+ JSDOC.DocTag.prototype.nibbleName = function(src) {
167
+ if (typeof src != "string") throw "src must be a string not "+(typeof src);
168
+
169
+ src = src.trim();
170
+
171
+ // is optional?
172
+ if (src.charAt(0) == "[") {
173
+ var nameRange = src.balance("[", "]");
174
+ if (nameRange[1] == -1) {
175
+ throw "Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: "+src;
176
+ }
177
+ this.name = src.substring(nameRange[0]+1, nameRange[1]).trim();
178
+ this.isOptional = true;
179
+
180
+ src = src.substring(nameRange[1]+1);
181
+
182
+ // has default value?
183
+ var nameAndValue = this.name.split("=");
184
+ if (nameAndValue.length) {
185
+ this.name = nameAndValue.shift().trim();
186
+ this.defaultValue = nameAndValue.join("=");
187
+ }
188
+ }
189
+ else {
190
+ var parts = src.match(/^(\S+)(?:\s([\s\S]*))?$/);
191
+ if (parts) {
192
+ if (parts[1]) this.name = parts[1];
193
+ if (parts[2]) src = parts[2].trim();
194
+ else src = "";
195
+ }
196
+ }
197
+
198
+ return src;
199
+ }
200
+
201
+ /*t:
202
+ requires("../frame/String.js");
203
+ plan(9, "testing JSDOC.DocTag.parser.nibbleName");
204
+
205
+ var tag = new JSDOC.DocTag();
206
+
207
+ tag.init().nibbleName("[foo] This is a description.");
208
+ is(tag.isOptional, true, "isOptional syntax is detected.");
209
+ is(tag.name, "foo", "optional param name is found.");
210
+
211
+ tag.init().nibbleName("[foo] This is a description.");
212
+ is(tag.isOptional, true, "isOptional syntax is detected when no type.");
213
+ is(tag.name, "foo", "optional param name is found when no type.");
214
+
215
+ tag.init().nibbleName("[foo=7] This is a description.");
216
+ is(tag.name, "foo", "optional param name is found when default value.");
217
+ is(tag.defaultValue, 7, "optional param default value is found when default value.");
218
+
219
+ //tag.init().nibbleName("[foo= a value] This is a description.");
220
+ //is(tag.defaultValue, " a value", "optional param default value is found when default value has spaces (issue #112).");
221
+
222
+ tag.init().nibbleName("[foo=[]] This is a description.");
223
+ is(tag.defaultValue, "[]", "optional param default value is found when default value is [] (issue #95).");
224
+
225
+ tag.init().nibbleName("[foo=a=b] This is a description.");
226
+ is(tag.name, "foo", "optional param name is found when default value is a=b.");
227
+ is(tag.defaultValue, "a=b", "optional param default value is found when default value is a=b.")
228
+ */
229
+
230
+ /*t:
231
+ plan(32, "Testing JSDOC.DocTag.parser.");
232
+ requires("../frame/String.js");
233
+
234
+ var tag = new JSDOC.DocTag();
235
+
236
+ is(typeof tag, "object", "JSDOC.DocTag.parser with an empty string returns an object.");
237
+ is(typeof tag.title, "string", "returned object has a string property 'title'.");
238
+ is(typeof tag.type, "string", "returned object has a string property 'type'.");
239
+ is(typeof tag.name, "string", "returned object has a string property 'name'.");
240
+ is(typeof tag.defaultValue, "string", "returned object has a string property 'defaultValue'.");
241
+ is(typeof tag.isOptional, "boolean", "returned object has a boolean property 'isOptional'.");
242
+ is(typeof tag.desc, "string", "returned object has a string property 'desc'.");
243
+
244
+ tag = new JSDOC.DocTag("param {widget} foo");
245
+ is(tag.title, "param", "param title is found.");
246
+ is(tag.name, "foo", "param name is found when desc is missing.");
247
+ is(tag.desc, "", "param desc is empty when missing.");
248
+
249
+ tag = new JSDOC.DocTag("param {object} date A valid date.");
250
+ is(tag.name, "date", "param name is found with a type.");
251
+ is(tag.type, "object", "param type is found.");
252
+ is(tag.desc, "A valid date.", "param desc is found with a type.");
253
+
254
+ tag = new JSDOC.DocTag("param aName a description goes\n here.");
255
+ is(tag.name, "aName", "param name is found without a type.");
256
+ is(tag.desc, "a description goes\n here.", "param desc is found without a type.");
257
+
258
+ tag = new JSDOC.DocTag("param {widget}");
259
+ is(tag.name, "", "param name is empty when it is not given.");
260
+
261
+ tag = new JSDOC.DocTag("param {widget} [foo] This is a description.");
262
+ is(tag.name, "foo", "optional param name is found.");
263
+
264
+ tag = new JSDOC.DocTag("return {aType} This is a description.");
265
+ is(tag.type, "aType", "when return tag has no name, type is found.");
266
+ is(tag.desc, "This is a description.", "when return tag has no name, desc is found.");
267
+
268
+ tag = new JSDOC.DocTag("author Joe Coder <jcoder@example.com>");
269
+ is(tag.title, "author", "author tag has a title.");
270
+ is(tag.type, "", "the author tag has no type.");
271
+ is(tag.name, "", "the author tag has no name.");
272
+ is(tag.desc, "Joe Coder <jcoder@example.com>", "author tag has desc.");
273
+
274
+ tag = new JSDOC.DocTag("private \t\n ");
275
+ is(tag.title, "private", "private tag has a title.");
276
+ is(tag.type, "", "the private tag has no type.");
277
+ is(tag.name, "", "the private tag has no name.");
278
+ is(tag.desc, "", "private tag has no desc.");
279
+
280
+ tag = new JSDOC.DocTag("example\n example(code);\n more();");
281
+ is(tag.desc, " example(code);\n more();", "leading whitespace (less one) in examples code is preserved.");
282
+
283
+ tag = new JSDOC.DocTag("param theName \n");
284
+ is(tag.name, "theName", "name only is found.");
285
+
286
+ tag = new JSDOC.DocTag("type theDesc \n");
287
+ is(tag.desc, "theDesc", "desc only is found.");
288
+
289
+ tag = new JSDOC.DocTag("type {theType} \n");
290
+ is(tag.type, "theType", "type only is found.");
291
+
292
+ tag = new JSDOC.DocTag("");
293
+ is(tag.title, "", "title is empty when tag is empty.");
294
+ */