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,159 @@
1
+ LOG.inform("XMLDOC.DomReader loaded");
2
+
3
+ XMLDOC.DomReader = function(root) {
4
+
5
+ this.dom = root;
6
+
7
+ /**
8
+ * The current node the reader is on
9
+ */
10
+ this.node = root;
11
+
12
+ /**
13
+ * Get the current node the reader is on
14
+ * @type XMLDOC.Parser.node
15
+ */
16
+ XMLDOC.DomReader.prototype.getNode = function() {
17
+ return this.node;
18
+ };
19
+
20
+ /**
21
+ * Set the node the reader should be positioned on.
22
+ * @param node {XMLDOC.Parser.node}
23
+ */
24
+ XMLDOC.DomReader.prototype.setNode = function(node) {
25
+ this.node = node;
26
+ };
27
+
28
+ /**
29
+ * A helper method to make sure the current node will
30
+ * never return null, unless null is passed as the root.
31
+ * @param step {String} An expression to evaluate - should return a node or null
32
+ */
33
+ XMLDOC.DomReader.prototype.navigate = function(step) {
34
+ var n;
35
+ if ((n = step) != null)
36
+ {
37
+ this.node = n;
38
+ return this.node;
39
+ }
40
+ return null;
41
+ };
42
+
43
+ /**
44
+ * Get the root node of the current node's document.
45
+ */
46
+ XMLDOC.DomReader.prototype.root = function() {
47
+ this.navigate(this.dom);
48
+ };
49
+
50
+ /**
51
+ * Get the parent of the current node.
52
+ */
53
+ XMLDOC.DomReader.prototype.parent = function() {
54
+ return this.navigate(this.node.parentNode());
55
+ };
56
+
57
+ /**
58
+ * Get the first child of the current node.
59
+ */
60
+ XMLDOC.DomReader.prototype.firstChild = function() {
61
+ return this.navigate(this.node.firstChild());
62
+ };
63
+
64
+ /**
65
+ * Get the last child of the current node.
66
+ */
67
+ XMLDOC.DomReader.prototype.lastChild = function() {
68
+ return this.navigate(this.node.lastChild());
69
+ };
70
+
71
+ /**
72
+ * Get the next sibling of the current node.
73
+ */
74
+ XMLDOC.DomReader.prototype.nextSibling = function() {
75
+ return this.navigate(this.node.nextSibling());
76
+ };
77
+
78
+ /**
79
+ * Get the previous sibling of the current node.
80
+ */
81
+ XMLDOC.DomReader.prototype.prevSibling = function() {
82
+ return this.navigate(this.node.prevSibling());
83
+ };
84
+
85
+ //===============================================================================================
86
+ // Support methods
87
+
88
+ /**
89
+ * Walk the tree starting with the current node, calling the plug-in for
90
+ * each node visited. Each time the plug-in is called, the DomReader
91
+ * is passed as the only parameter. Use the {@link XMLDOC.DomReader#getNode} method
92
+ * to access the current node. <i>This method uses a depth first traversal pattern.</i>
93
+ *
94
+ * @param srcFile {String} The source file being evaluated
95
+ */
96
+ XMLDOC.DomReader.prototype.getSymbols = function(srcFile)
97
+ {
98
+ XMLDOC.DomReader.symbols = [];
99
+ XMLDOC.DomReader.currentFile = srcFile;
100
+ JSDOC.Symbol.srcFile = (srcFile || "");
101
+
102
+ if (defined(JSDOC.PluginManager)) {
103
+ JSDOC.PluginManager.run("onDomGetSymbols", this);
104
+ }
105
+
106
+ return XMLDOC.DomReader.symbols;
107
+ };
108
+
109
+ /**
110
+ * Find the node with the given name using a depth first traversal.
111
+ * Does not modify the DomReader's current node.
112
+ *
113
+ * @param name {String} The name of the node to find
114
+ * @return the node that was found, or null if not found
115
+ */
116
+ XMLDOC.DomReader.prototype.findNode = function(name)
117
+ {
118
+ var findNode = null;
119
+
120
+ // Start at the current node and move into the subtree,
121
+ // looking for the node with the given name
122
+ function deeper(node, find)
123
+ {
124
+ var look = null;
125
+
126
+ if (node) {
127
+ if (node.name == find)
128
+ {
129
+ return node;
130
+ }
131
+
132
+ if (node.firstChild())
133
+ {
134
+ look = deeper(node.firstChild(), find);
135
+ }
136
+
137
+ if (!look && node.nextSibling())
138
+ {
139
+ look = deeper(node.nextSibling(), find);
140
+ }
141
+ }
142
+
143
+ return look;
144
+ }
145
+
146
+ return deeper(this.getNode().firstChild(), name);
147
+ };
148
+
149
+ /**
150
+ * Find the next node with the given name using a depth first traversal.
151
+ *
152
+ * @param name {String} The name of the node to find
153
+ */
154
+ XMLDOC.DomReader.prototype.findPreviousNode = function(name)
155
+ {
156
+ };
157
+
158
+ };
159
+
@@ -0,0 +1,16 @@
1
+ LOG.inform("XMLDOC.symbolize loaded");
2
+
3
+ /**
4
+ * Convert the source file to a set of symbols
5
+ */
6
+ XMLDOC.symbolize = function(srcFile, src) {
7
+
8
+ LOG.inform("Symbolizing file '" + srcFile + "'");
9
+
10
+ // XML files already have a defined structure, so we don't need to
11
+ // do anything but parse them. The DOM reader can create a symbol
12
+ // table from the parsed XML.
13
+ var dr = new XMLDOC.DomReader(XMLDOC.Parser.parse(src));
14
+ return dr.getSymbols(srcFile);
15
+
16
+ };
@@ -0,0 +1,292 @@
1
+ LOG.inform("XMLDOC.Parser loaded");
2
+
3
+ /**
4
+ * XML Parser object. Returns an {@link #XMLDOC.Parser.node} which is
5
+ * the root element of the parsed document.
6
+ * <p/>
7
+ * By default, this parser will only handle well formed XML. To
8
+ * allow the parser to handle HTML, set the <tt>XMLDOC.Parser.strictMode</tt>
9
+ * variable to <tt>false</tt> before calling <tt>XMLDOC.Parser.parse()</tt>.
10
+ * <p/>
11
+ * <i>Note: If you pass poorly formed XML, it will cause the parser to throw
12
+ * an exception.</i>
13
+ *
14
+ * @author Brett Fattori (bfattori@fry.com)
15
+ * @author $Author: micmath $
16
+ * @version $Revision: 497 $
17
+ */
18
+ XMLDOC.Parser = {};
19
+
20
+ /**
21
+ * Strict mode setting. Setting this to false allows HTML-style source to
22
+ * be parsed. Normally, well formed XML has defined end tags, or empty tags
23
+ * are properly formed. Default: <tt>true</tt>
24
+ * @type Boolean
25
+ */
26
+ XMLDOC.Parser.strictMode = true;
27
+
28
+ /**
29
+ * A node in an XML Document. Node types are ROOT, ELEMENT, COMMENT, PI, and TEXT.
30
+ * @param parent {XMLDOC.Parser.node} The parent node
31
+ * @param name {String} The node name
32
+ * @param type {String} One of the types
33
+ */
34
+ XMLDOC.Parser.node = function(parent, name, type)
35
+ {
36
+ this.name = name;
37
+ this.type = type || "ELEMENT";
38
+ this.parent = parent;
39
+ this.charData = "";
40
+ this.attrs = {};
41
+ this.nodes = [];
42
+ this.cPtr = 0;
43
+
44
+ XMLDOC.Parser.node.prototype.getAttributeNames = function() {
45
+ var a = [];
46
+ for (var o in this.attrs)
47
+ {
48
+ a.push(o);
49
+ }
50
+
51
+ return a;
52
+ };
53
+
54
+ XMLDOC.Parser.node.prototype.getAttribute = function(attr) {
55
+ return this.attrs[attr];
56
+ };
57
+
58
+ XMLDOC.Parser.node.prototype.setAttribute = function(attr, val) {
59
+ this.attrs[attr] = val;
60
+ };
61
+
62
+ XMLDOC.Parser.node.prototype.getChild = function(idx) {
63
+ return this.nodes[idx];
64
+ };
65
+
66
+ XMLDOC.Parser.node.prototype.parentNode = function() {
67
+ return this.parent;
68
+ };
69
+
70
+ XMLDOC.Parser.node.prototype.firstChild = function() {
71
+ return this.nodes[0];
72
+ };
73
+
74
+ XMLDOC.Parser.node.prototype.lastChild = function() {
75
+ return this.nodes[this.nodes.length - 1];
76
+ };
77
+
78
+ XMLDOC.Parser.node.prototype.nextSibling = function() {
79
+ var p = this.parent;
80
+ if (p && (p.nodes.indexOf(this) + 1 != p.nodes.length))
81
+ {
82
+ return p.getChild(p.nodes.indexOf(this) + 1);
83
+ }
84
+ return null;
85
+ };
86
+
87
+ XMLDOC.Parser.node.prototype.prevSibling = function() {
88
+ var p = this.parent;
89
+ if (p && (p.nodes.indexOf(this) - 1 >= 0))
90
+ {
91
+ return p.getChild(p.nodes.indexOf(this) - 1);
92
+ }
93
+ return null;
94
+ };
95
+ };
96
+
97
+ /**
98
+ * Parse an XML Document from the specified source. The XML should be
99
+ * well formed, unless strict mode is disabled, then the parser will
100
+ * handle HTML-style XML documents.
101
+ * @param src {String} The source to parse
102
+ */
103
+ XMLDOC.Parser.parse = function(src)
104
+ {
105
+ var A = [];
106
+
107
+ // Normailize whitespace
108
+ A = src.split("\r\n");
109
+ src = A.join("\n");
110
+ A = src.split("\r");
111
+ src = A.join("\n");
112
+
113
+ // Remove XML and DOCTYPE specifier
114
+ src.replace(/<\?XML .*\?>/i, "");
115
+ src.replace(/<!DOCTYPE .*\>/i, "");
116
+
117
+ // The document is the root node and cannot be modified or removed
118
+ var doc = new XMLDOC.Parser.node(null, "ROOT", "DOCUMENT");
119
+
120
+ // Let's break it down
121
+ XMLDOC.Parser.eat(doc, src);
122
+
123
+ return doc;
124
+ };
125
+
126
+ /**
127
+ * The XML fragment processing routine. This method is private and should not be called
128
+ * directly.
129
+ * @param parentNode {XMLDOC.Parser.node} The node which is the parent of this fragment
130
+ * @param src {String} The source within the fragment to process
131
+ * @private
132
+ */
133
+ XMLDOC.Parser.eat = function(parentNode, src)
134
+ {
135
+ // A simple tag def
136
+ var reTag = new RegExp("<(!|)(\\?|--|)((.|\\s)*?)\\2>","g");
137
+
138
+ // Special tag types
139
+ var reCommentTag = /<!--((.|\s)*?)-->/;
140
+ var rePITag = /<\?((.|\s)*?)\?>/;
141
+
142
+ // A start tag (with potential empty marker)
143
+ var reStartTag = /<(.*?)( +([\w_\-]*)=(\"|')(.*)\4)*(\/)?>/;
144
+
145
+ // An empty HTML style tag (not proper XML, but we'll accept it so we can process HTML)
146
+ var reHTMLEmptyTag = /<(.*?)( +([\w_\-]*)=(\"|')(.*)\4)*>/;
147
+
148
+ // Fully enclosing tag with nested tags
149
+ var reEnclosingTag = /<(.*?)( +([\w_\-]*)=(\"|')(.*?)\4)*>((.|\s)*?)<\/\1>/;
150
+
151
+ // Breaks down attributes
152
+ var reAttributes = new RegExp(" +([\\w_\\-]*)=(\"|')(.*?)\\2","g");
153
+
154
+ // Find us a tag
155
+ var tag;
156
+ while ((tag = reTag.exec(src)) != null)
157
+ {
158
+ if (tag.index > 0)
159
+ {
160
+ // The next tag has some text before it
161
+ var text = src.substring(0, tag.index).replace(/^[ \t\n]+((.|\n)*?)[ \t\n]+$/, "$1");
162
+
163
+ if (text.length > 0 && (text != "\n"))
164
+ {
165
+ var txtnode = new XMLDOC.Parser.node(parentNode, "", "TEXT");
166
+ txtnode.charData = text;
167
+
168
+ // Append the new text node
169
+ parentNode.nodes.push(txtnode);
170
+ }
171
+
172
+ // Reset the lastIndex of reTag
173
+ reTag.lastIndex -= src.substring(0, tag.index).length;
174
+
175
+ // Eat the text
176
+ src = src.substring(tag.index);
177
+ }
178
+
179
+ if (reCommentTag.test(tag[0]))
180
+ {
181
+ // Is this a comment?
182
+ var comment = new XMLDOC.Parser.node(parentNode, "", "COMMENT");
183
+ comment.charData = reCommentTag.exec(tag[0])[1];
184
+
185
+ // Append the comment
186
+ parentNode.nodes.push(comment);
187
+
188
+ // Move the lastIndex of reTag
189
+ reTag.lastIndex -= tag[0].length;
190
+
191
+ // Eat the tag
192
+ src = src.replace(reCommentTag, "");
193
+ }
194
+ else if (rePITag.test(tag[0]))
195
+ {
196
+ // Is this a processing instruction?
197
+ var pi = new XMLDOC.Parser.node(parentNode, "", "PI");
198
+ pi.charData = rePITag.exec(tag[0])[1];
199
+
200
+ // Append the processing instruction
201
+ parentNode.nodes.push(pi);
202
+
203
+ // Move the lastIndex of reTag
204
+ reTag.lastIndex -= tag[0].length;
205
+
206
+ // Eat the tag
207
+ src = src.replace(rePITag, "");
208
+ }
209
+ else if (reStartTag.test(tag[0]))
210
+ {
211
+ // Break it down
212
+ var e = reStartTag.exec(tag[0]);
213
+ var elem = new XMLDOC.Parser.node(parentNode, e[1], "ELEMENT");
214
+
215
+ // Get attributes from the tag
216
+ var a;
217
+ while ((a = reAttributes.exec(e[2])) != null )
218
+ {
219
+ elem.attrs[a[1]] = a[3];
220
+ }
221
+
222
+ // Is this an empty XML-style tag?
223
+ if (e[6] == "/")
224
+ {
225
+ // Append the empty element
226
+ parentNode.nodes.push(elem);
227
+
228
+ // Move the lastIndex of reTag (include the start tag length)
229
+ reTag.lastIndex -= e[0].length;
230
+
231
+ // Eat the tag
232
+ src = src.replace(reStartTag, "");
233
+ }
234
+ else
235
+ {
236
+ // Check for malformed XML tags
237
+ var htmlParsed = false;
238
+ var htmlStartTag = reHTMLEmptyTag.exec(src);
239
+
240
+ // See if there isn't an end tag within this block
241
+ var reHTMLEndTag = new RegExp("</" + htmlStartTag[1] + ">");
242
+ var htmlEndTag = reHTMLEndTag.exec(src);
243
+
244
+ if (XMLDOC.Parser.strictMode && htmlEndTag == null)
245
+ {
246
+ // Poorly formed XML fails in strict mode
247
+ var err = new Error("Malformed XML passed to XMLDOC.Parser... Error contains malformed 'src'");
248
+ err.src = src;
249
+ throw err;
250
+ }
251
+ else if (htmlEndTag == null)
252
+ {
253
+ // This is an HTML-style empty tag, store the element for it in non-strict mode
254
+ parentNode.nodes.push(elem);
255
+
256
+ // Eat the tag
257
+ src = src.replace(reHTMLEmptyTag, "");
258
+ htmlParsed = true;
259
+ }
260
+
261
+ // If we didn't parse HTML-style, it must be an enclosing tag
262
+ if (!htmlParsed)
263
+ {
264
+ var enc = reEnclosingTag.exec(src);
265
+
266
+ // Go deeper into the document
267
+ XMLDOC.Parser.eat(elem, enc[6]);
268
+
269
+ // Append the new element node
270
+ parentNode.nodes.push(elem);
271
+
272
+ // Eat the tag
273
+ src = src.replace(reEnclosingTag, "");
274
+ }
275
+ }
276
+
277
+ // Reset the lastIndex of reTag
278
+ reTag.lastIndex = 0;
279
+ }
280
+ }
281
+
282
+ // No tag was found... append the text if there is any
283
+ src = src.replace(/^[ \t\n]+((.|\n)*?)[ \t\n]+$/, "$1");
284
+ if (src.length > 0 && (src != "\n"))
285
+ {
286
+ var txtNode = new XMLDOC.Parser.node(parentNode, "", "TEXT");
287
+ txtNode.charData = src;
288
+
289
+ // Append the new text node
290
+ parentNode.nodes.push(txtNode);
291
+ }
292
+ };