docjs 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data/CONCEPT.md +80 -0
  2. data/DOCUMENTATION.md +41 -0
  3. data/LICENSE.md +19 -0
  4. data/README.md +19 -0
  5. data/RENDERING.md +8 -0
  6. data/bin/docjs +190 -0
  7. data/docjs.gemspec +32 -0
  8. data/lib/boot.rb +34 -0
  9. data/lib/code_object/base.rb +48 -0
  10. data/lib/code_object/converter.rb +48 -0
  11. data/lib/code_object/exceptions.rb +5 -0
  12. data/lib/code_object/function.rb +84 -0
  13. data/lib/code_object/object.rb +18 -0
  14. data/lib/code_object/type.rb +43 -0
  15. data/lib/configs.rb +53 -0
  16. data/lib/document/document.rb +25 -0
  17. data/lib/dom/dom.rb +188 -0
  18. data/lib/dom/exceptions.rb +12 -0
  19. data/lib/dom/no_doc.rb +26 -0
  20. data/lib/dom/node.rb +415 -0
  21. data/lib/helper/helper.rb +120 -0
  22. data/lib/helper/linker.rb +130 -0
  23. data/lib/logger.rb +49 -0
  24. data/lib/parser/comment.rb +69 -0
  25. data/lib/parser/comment_parser.rb +90 -0
  26. data/lib/parser/exceptions.rb +6 -0
  27. data/lib/parser/meta_container.rb +20 -0
  28. data/lib/parser/parser.rb +269 -0
  29. data/lib/processor.rb +123 -0
  30. data/lib/renderer.rb +108 -0
  31. data/lib/tasks/render_task.rb +112 -0
  32. data/lib/thor.rb +27 -0
  33. data/lib/token/container.rb +84 -0
  34. data/lib/token/exceptions.rb +6 -0
  35. data/lib/token/handler.rb +242 -0
  36. data/lib/token/token.rb +46 -0
  37. data/templates/application.rb +14 -0
  38. data/templates/helpers/template.rb +66 -0
  39. data/templates/resources/css/.sass-cache/98c121fba905284c2c8ca6220fe3c590e5c9ec19/application.scssc +0 -0
  40. data/templates/resources/css/application.css +836 -0
  41. data/templates/resources/img/arrow_down.png +0 -0
  42. data/templates/resources/img/arrow_right.png +0 -0
  43. data/templates/resources/img/arrow_up.png +0 -0
  44. data/templates/resources/img/bullet_toggle_minus.png +0 -0
  45. data/templates/resources/img/bullet_toggle_plus.png +0 -0
  46. data/templates/resources/img/constructor.png +0 -0
  47. data/templates/resources/img/function.png +0 -0
  48. data/templates/resources/img/object.png +0 -0
  49. data/templates/resources/img/page.png +0 -0
  50. data/templates/resources/img/prototype.png +0 -0
  51. data/templates/resources/img/tag.png +0 -0
  52. data/templates/resources/js/application.js +318 -0
  53. data/templates/resources/js/jcore.js +129 -0
  54. data/templates/resources/js/jquery.cookie.js +92 -0
  55. data/templates/resources/js/jquery.js +16 -0
  56. data/templates/resources/js/jquery.tooltip.js +77 -0
  57. data/templates/resources/js/jquery.treeview.js +238 -0
  58. data/templates/resources/scss/_footer.scss +10 -0
  59. data/templates/resources/scss/_header.scss +184 -0
  60. data/templates/resources/scss/_helpers.scss +91 -0
  61. data/templates/resources/scss/_print.scss +20 -0
  62. data/templates/resources/scss/_resets.scss +132 -0
  63. data/templates/resources/scss/_tooltip.scss +26 -0
  64. data/templates/resources/scss/application.scss +442 -0
  65. data/templates/tasks/api_index_task.rb +26 -0
  66. data/templates/tasks/docs_task.rb +33 -0
  67. data/templates/tasks/json_data_task.rb +55 -0
  68. data/templates/tasks/typed_task.rb +54 -0
  69. data/templates/tokens/tokens.rb +22 -0
  70. data/templates/types/prototype.rb +20 -0
  71. data/templates/views/api_index.html.erb +21 -0
  72. data/templates/views/doc_page.html.erb +11 -0
  73. data/templates/views/function/_detail.html.erb +8 -0
  74. data/templates/views/function/index.html.erb +53 -0
  75. data/templates/views/index.html.erb +0 -0
  76. data/templates/views/layout/application.html.erb +73 -0
  77. data/templates/views/layout/json.html.erb +3 -0
  78. data/templates/views/object/index.html.erb +63 -0
  79. data/templates/views/tokens/_default.html.erb +11 -0
  80. data/templates/views/tokens/_default_token.html.erb +19 -0
  81. data/templates/views/tokens/_example.html.erb +2 -0
  82. data/templates/views/tokens/_examples.html.erb +1 -0
  83. data/test/code_object/converter.rb +78 -0
  84. data/test/code_object/prototype.rb +70 -0
  85. data/test/configs.rb +65 -0
  86. data/test/docs/README.CONCEPT.md +83 -0
  87. data/test/docs/README.md +14 -0
  88. data/test/dom/dom.absolute_nodes.rb +40 -0
  89. data/test/dom/dom.rb +72 -0
  90. data/test/dom/node.rb +53 -0
  91. data/test/integration/converter.rb +72 -0
  92. data/test/integration/parser_factory.rb +28 -0
  93. data/test/interactive.rb +7 -0
  94. data/test/js-files/absolute.js +11 -0
  95. data/test/js-files/comments_in_strings.js +31 -0
  96. data/test/js-files/core-doc-relative.js +77 -0
  97. data/test/js-files/core-doc.js +145 -0
  98. data/test/js-files/nested.js +34 -0
  99. data/test/js-files/nested_with_strings.js +35 -0
  100. data/test/js-files/prototype.js +33 -0
  101. data/test/js-files/simple.js +17 -0
  102. data/test/js-files/tokens.js +32 -0
  103. data/test/parser/comments_in_strings.rb +51 -0
  104. data/test/parser/intelligent_skip_until.rb +110 -0
  105. data/test/parser/parser.rb +273 -0
  106. data/test/rspec_helper.rb +23 -0
  107. data/test/token/handler.rb +136 -0
  108. data/test/token/tokens.rb +52 -0
  109. metadata +184 -0
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @function Outer
3
+ */
4
+ var Outer = function(){
5
+
6
+ /**
7
+ * This is an inner function
8
+ * @function .inner
9
+ */
10
+ var inner = function() {
11
+ string = "}}"
12
+ }
13
+
14
+
15
+ /**
16
+ * This is a second inner function
17
+ * @function .inner_two
18
+ */
19
+ var innerTwo = function() {
20
+
21
+ var another_string = "({{}})\n\n\n)){()[])"
22
+
23
+ /**
24
+ * And again, here is a inner function
25
+ * @object .foo
26
+ */
27
+ var foo = {
28
+ bar: 4,
29
+ baz: function() {}
30
+ };
31
+
32
+
33
+ }
34
+
35
+ };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * This function can be used like the following:
3
+ * @example
4
+ * p = new Person("Peter Griffin");
5
+ *
6
+ * @constructor Person
7
+ */
8
+ var Person = function(name) {
9
+
10
+ this.name = name;
11
+
12
+ };
13
+
14
+ /**
15
+ * Single argument version. Only supplies the function to which this object
16
+ * acts as a prototype
17
+ *
18
+ * @prototype Person
19
+ */
20
+ Person.prototype = {
21
+
22
+ /**
23
+ * Alerts a string containing the name of the person
24
+ *
25
+ * @function .sayHello
26
+ */
27
+ sayHello: function() {
28
+
29
+ alert("Hello my name is " + this.name);
30
+
31
+ }
32
+
33
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Some documentation
3
+ * And some more
4
+ *
5
+ * @first tokenline
6
+ * @second tokenline, which should be a multiline token
7
+ * because it is intended with at least 2 spaces and
8
+ * it won't stop, until there is an empty line, or a
9
+ * new token
10
+ *
11
+ * And another docline
12
+ */
13
+ var foo = {
14
+
15
+ property: "A String with //something, that /*looks like a comment */"
16
+
17
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * This is some documentation
3
+ * with multiple lines
4
+ *
5
+ * @function say_hello
6
+ *
7
+ * @public
8
+ * @param [String] foo some parameter
9
+ * @return [String, Integer] returns a string "hello"
10
+ */
11
+ var say_hello = function(foo) {
12
+ return "hello";
13
+ };
14
+
15
+ /**
16
+ * This is some documentation
17
+ * with multiple lines
18
+ *
19
+ * @object FOO
20
+ */
21
+ var FOO = {};
22
+
23
+ /**
24
+ * This is some documentation
25
+ * with multiple lines
26
+ *
27
+ * @constructor FOO.bar.some_function
28
+ * @param [String] parameter1 The first parameter
29
+ */
30
+ var FOO.some_function = function(parameter1) {
31
+ // some comment without tokens
32
+ };
@@ -0,0 +1,51 @@
1
+ #encoding utf-8
2
+
3
+ require_relative '../../lib/parser/parser'
4
+
5
+ describe Parser::Parser, ".parse" do
6
+
7
+ context "Parsing comments_in_strings.js" do
8
+
9
+ before do
10
+ stream = File.read File.expand_path('../../js-files/comments_in_strings.js', __FILE__)
11
+ @parser = Parser::Parser.new stream
12
+ @comments = @parser.parse
13
+ end
14
+
15
+ subject { @comments }
16
+
17
+ it "should find 1 comment" do
18
+ subject.length.should == 1
19
+ end
20
+
21
+
22
+ describe "The First Comment" do
23
+
24
+ subject { @comments.first }
25
+
26
+ it "should contain 1 docline and 1 tokenline" do
27
+ subject.doclines.length.should == 1
28
+ subject.tokenlines.length.should == 1
29
+ end
30
+
31
+ it "should have got correct tokenline-contents" do
32
+ tokens = subject.tokenlines
33
+ tokens[0].token.should == :object
34
+ tokens[0].content.should == "only_one\n"
35
+ end
36
+
37
+ it "should have got correct source" do
38
+ subject.source.should == " var innerTwo = function() {
39
+
40
+ var another_string = \"({})\\n\\n\\n)){()[])\"
41
+
42
+ single_string = '// @object .foo'
43
+ var foo = {
44
+ bar: 4,
45
+ baz: function() {}
46
+ };
47
+ } "
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,110 @@
1
+ require_relative '../../lib/parser/parser'
2
+
3
+ describe StringScanner, "#intelligent_skip_until" do
4
+
5
+ context "closing braces in strings" do
6
+ before do
7
+ @scanner = StringScanner.new "Foo bar baz \"this is a) string\" this is not) - and some more"
8
+ @scanner.intelligent_skip_until /\)/
9
+ end
10
+
11
+ it "should find ) at pos 44" do
12
+ @scanner.pos.should == 44
13
+ @scanner.matched.should == ")"
14
+ end
15
+ end
16
+
17
+
18
+ context "closing braces in single-strings" do
19
+ before do
20
+ @scanner = StringScanner.new "Foo bar baz 'this is a) string' this is not) - and some more"
21
+ @scanner.intelligent_skip_until /\)/
22
+ end
23
+
24
+ it "should find ) at pos 44" do
25
+ @scanner.pos.should == 44
26
+ @scanner.matched.should == ")"
27
+ end
28
+ end
29
+
30
+
31
+ context "escaped string-ends" do
32
+ before do
33
+ @scanner = StringScanner.new "Foo bar baz \"this is a) string\\\" this is not)\" - and )some more"
34
+ @scanner.intelligent_skip_until /\)/
35
+ end
36
+
37
+ it "should find ) at pos 54" do
38
+ @scanner.pos.should == 54
39
+ @scanner.matched.should == ")"
40
+ end
41
+ end
42
+
43
+
44
+ context "regular expressions" do
45
+ before do
46
+ @scanner = StringScanner.new "Foo bar baz /(a-z)_[\\(\\)]/ix - and )some more"
47
+ @scanner.intelligent_skip_until /\)/
48
+ end
49
+
50
+ it "should find ) at pos 36" do
51
+ @scanner.pos.should == 36
52
+ @scanner.matched.should == ")"
53
+ end
54
+ end
55
+
56
+
57
+ context "escaped regular expressions" do
58
+ before do
59
+ @scanner = StringScanner.new "Foo bar baz /(a-z)_[\\(\\)]\\/foo/ix - and )some more"
60
+ @scanner.intelligent_skip_until /\)/
61
+ end
62
+
63
+ it "should find ) at pos 41" do
64
+ @scanner.pos.should == 41
65
+ @scanner.matched.should == ")"
66
+ end
67
+ end
68
+
69
+
70
+ context "single line comments" do
71
+ before do
72
+ @scanner = StringScanner.new "Foo bar baz //(Oh a comment))\n - and )some more"
73
+ @scanner.intelligent_skip_until /\)/
74
+ end
75
+
76
+ it "should find ) at pos 38" do
77
+ @scanner.pos.should == 38
78
+ @scanner.matched.should == ")"
79
+ end
80
+ end
81
+
82
+
83
+ context "multi line comments" do
84
+ before do
85
+ @scanner = StringScanner.new "Foo bar baz
86
+ /**
87
+ * (Oh a comment))
88
+ */ - and )some more"
89
+ @scanner.intelligent_skip_until /\)/
90
+ end
91
+
92
+ it "should find ) at pos 47" do
93
+ @scanner.pos.should == 47
94
+ @scanner.matched.should == ")"
95
+ end
96
+ end
97
+
98
+ context "not ending single line comments" do
99
+ before do
100
+ @scanner = StringScanner.new "Foo bar baz //(Oh a comment)) - and )some more"
101
+ end
102
+
103
+ it "should raise an exception" do
104
+ should_raise StringScanner::Error do
105
+ @scanner.intelligent_skip_until /\)/
106
+ end
107
+ end
108
+ end
109
+
110
+ end
@@ -0,0 +1,273 @@
1
+ #encoding utf-8
2
+
3
+ require_relative '../../lib/parser/parser'
4
+
5
+ describe Parser::Parser, ".parse" do
6
+
7
+ context "Parsing simple.js" do
8
+
9
+ before do
10
+ stream = File.read File.expand_path('../../js-files/simple.js', __FILE__)
11
+ @parser = Parser::Parser.new stream
12
+ @comments = @parser.parse
13
+ end
14
+
15
+ subject { @comments }
16
+
17
+ it "should find 1 comment" do
18
+ subject.length.should == 1
19
+ end
20
+
21
+
22
+ describe "The First Comment" do
23
+
24
+ subject { @comments.first }
25
+
26
+ it "should contain 3 doclines and 2 tokenlines" do
27
+ subject.doclines.length.should == 5
28
+ subject.tokenlines.length.should == 2
29
+ end
30
+
31
+ it "should have got correct tokenline-contents" do
32
+ tokens = subject.tokenlines
33
+
34
+ tokens[0].token.should == :first
35
+ tokens[1].token.should == :second
36
+
37
+ tokens[0].content.should == "tokenline\n"
38
+ tokens[1].content.should == "tokenline, which should be a multiline token\nbecause it is intended with at least 2 spaces and\nit won't stop, until there is an empty line, or a\nnew token\n"
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+ context "Parsing a File with nested comments" do
45
+
46
+ before do
47
+ @path = File.expand_path('../../js-files/nested.js', __FILE__)
48
+ stream = File.read @path
49
+ @parser = Parser::Parser.new(stream, :filepath => @path)
50
+ @comments = @parser.parse
51
+ end
52
+
53
+ subject { @comments }
54
+
55
+ it "should find 1 root comments" do
56
+ subject.length.should == 1
57
+ end
58
+
59
+
60
+ describe "the first comment" do
61
+
62
+ subject { @comments.first }
63
+
64
+ it "should containt 0 doclines and 1 tokenline" do
65
+ subject.doclines.length.should == 0
66
+ subject.tokenlines.length.should == 1
67
+ end
68
+
69
+ it "should have got correct tokenline-contents" do
70
+ tokens = subject.tokenlines
71
+ tokens[0].token.should == :function
72
+ tokens[0].content.should == "Outer\n"
73
+ end
74
+
75
+ it "should start at line 4" do
76
+ subject.line_start.should == 4
77
+ end
78
+
79
+ it "should contain the right filepath" do
80
+ subject.filepath.should == @path
81
+ end
82
+
83
+ it "should contain the right source" do
84
+ subject.source.should == "var Outer = function(){
85
+
86
+ /**
87
+ * This is an inner function
88
+ * @function .inner
89
+ */
90
+ var inner = function() {
91
+
92
+ }
93
+
94
+
95
+ /**
96
+ * This is a second inner function
97
+ * @function .inner_two
98
+ */
99
+ var innerTwo = function() {
100
+
101
+
102
+ /**
103
+ * And again, here is a inner function
104
+ * @object .foo
105
+ */
106
+ var foo = {
107
+ bar: 4,
108
+ baz: function() {}
109
+ };
110
+
111
+
112
+ }
113
+
114
+ };"
115
+ end
116
+
117
+ it "should contain 2 child-comments" do
118
+ subject.children.length.should == 2
119
+ end
120
+ end
121
+
122
+
123
+ describe "the first inner comment" do
124
+
125
+ subject { @comments.first.children.first }
126
+
127
+ it "should contain 1 doclines and 1 tokenline" do
128
+ subject.doclines.length.should == 1
129
+ subject.tokenlines.length.should == 1
130
+ end
131
+
132
+ it "should have got correct tokenline-contents" do
133
+ tokens = subject.tokenlines
134
+ tokens[0].token.should == :function
135
+ tokens[0].content.should == ".inner\n"
136
+ end
137
+
138
+ it "should start at line 10" do
139
+ subject.line_start.should == 10
140
+ end
141
+
142
+ it "should contain the right filepath" do
143
+ subject.filepath.should == @path
144
+ end
145
+
146
+ end
147
+
148
+
149
+ describe "the second inner comment" do
150
+
151
+ subject { @comments.first.children[1] }
152
+
153
+ it "should contain 1 doclines and 1 tokenline" do
154
+ subject.doclines.length.should == 1
155
+ subject.tokenlines.length.should == 1
156
+ end
157
+
158
+ it "should have got correct tokenline-contents" do
159
+ tokens = subject.tokenlines
160
+ tokens[0].token.should == :function
161
+ tokens[0].content.should == ".inner_two\n"
162
+ end
163
+
164
+ it "should start at line 19" do
165
+ subject.line_start.should == 19
166
+ end
167
+
168
+ it "should contain the right filepath" do
169
+ subject.filepath.should == @path
170
+ end
171
+
172
+ end
173
+
174
+
175
+ describe "the most inner comment" do
176
+
177
+ subject { @comments.first.children[1].children.first }
178
+
179
+ it "should contain 1 doclines and 1 tokenline" do
180
+ subject.doclines.length.should == 1
181
+ subject.tokenlines.length.should == 1
182
+ end
183
+
184
+ it "should have got correct tokenline-contents" do
185
+ tokens = subject.tokenlines
186
+ tokens[0].token.should == :object
187
+ tokens[0].content.should == ".foo\n"
188
+ end
189
+
190
+ it "should start at line 26" do
191
+ subject.line_start.should == 26
192
+ end
193
+
194
+ it "should contain the right filepath" do
195
+ subject.filepath.should == @path
196
+ end
197
+
198
+ end
199
+
200
+ end
201
+
202
+
203
+
204
+ context "being confronted with windows-linebreaks \\r \\n" do
205
+
206
+ before do
207
+ @parser = Parser::Parser.new("/**\r\n *\r\n * @tokenline with something fancy\r\n * @multiline token with\r\n * continue over line end\r\n * */")
208
+ @comments = @parser.parse
209
+ end
210
+
211
+ it "should parse tokenlines correct" do
212
+ tokens = @comments.first.tokenlines
213
+
214
+ tokens[0].token.should == :tokenline
215
+ tokens[1].token.should == :multiline
216
+
217
+ tokens[0].content.should == "with something fancy\n"
218
+ tokens[1].content.should == "token with\ncontinue over line end\n"
219
+ end
220
+
221
+ end
222
+
223
+ context "multiline tokens with empty first line" do
224
+
225
+ before do
226
+ @comments = Parser::Parser.new("
227
+ /**
228
+ * @multiline
229
+ * this is a multiline token with
230
+ * empty first line
231
+ */
232
+ ").parse
233
+ end
234
+
235
+ describe "the multiline token" do
236
+
237
+ subject { @comments.first.tokenlines[0] }
238
+
239
+ it "should be named :multiline" do
240
+ subject.token.should == :multiline
241
+ subject.content.should == "\nthis is a multiline token with\nempty first line\n"
242
+ end
243
+ end
244
+ end
245
+
246
+
247
+ context "parsing multibyte character" do
248
+ =begin
249
+ before do
250
+
251
+ @parser = Parser::Parser.new("/**
252
+ *
253
+ * @tokenline ÜÄÖÖüäöüöäßø
254
+ * @multiline token with
255
+ * continue over line end
256
+ *
257
+ */
258
+ Foo Bar")
259
+ @comments = @parser.parse
260
+ end
261
+
262
+ subject { @comments.first }
263
+
264
+ it "should find the correct source" do
265
+ subject.source.should == "Foo Bar"
266
+ end
267
+
268
+ =end
269
+ pending("There are Problems with utf-8 encoded string")
270
+
271
+ end
272
+
273
+ end