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,11 @@
1
+ <%
2
+
3
+ opts = tokens.first.html
4
+ opts[:class] = (opts[:class] || "") + " subsection"
5
+ %>
6
+ <section <%= attributize opts %>>
7
+ <%= tag :h3, tokens.first %>
8
+ <ul>
9
+ <%= render :partial => 'tokens/default_token', :collection => tokens %>
10
+ </ul>
11
+ </section>
@@ -0,0 +1,19 @@
1
+ <li>
2
+ <% unless default_token.name.nil? %>
3
+ <h4><%= default_token.name %></h4>
4
+ <% end %>
5
+
6
+ <% unless default_token.children.nil? %>
7
+ <ul>
8
+ <%= render :partial => 'tokens/default_token', :collection => default_token.children %>
9
+ </ul>
10
+
11
+ <% else %>
12
+
13
+ <% unless default_token.types.nil? %>
14
+ (<span class="types"><%= default_token.types.map {|t| link_to(t) }.join ', ' %></span>)
15
+ <% end %>
16
+ <%= replace_links to_html default_token.content %>
17
+
18
+ <% end %>
19
+ </li>
@@ -0,0 +1,2 @@
1
+ <h3>Example <%= example.name %></h3>
2
+ <%=code example.content %>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'tokens/example', :collection => tokens %>
@@ -0,0 +1,78 @@
1
+ # ../data.img#1785915:1
2
+ require_relative '../../lib/parser/comment'
3
+
4
+ describe CodeObject::Converter, "#to_code_object" do
5
+
6
+ before :each do
7
+ @comment = Parser::Comment.new
8
+ end
9
+
10
+ context "comment with function-token" do
11
+
12
+ before do
13
+ @comment.add_tokenline :function, "foo"
14
+ end
15
+
16
+ describe "the result" do
17
+
18
+ subject { @comment.to_code_object }
19
+
20
+ it "should be a CodeObject::Function" do
21
+ subject.class.should == CodeObject::Function
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+ context "comment with object-token" do
28
+
29
+ before do
30
+ @comment.add_tokenline "object", "bar"
31
+ end
32
+
33
+ describe "the result" do
34
+
35
+ subject { @comment.to_code_object }
36
+
37
+ it "should be a CodeObject::Object" do
38
+ subject.class.should == CodeObject::Object
39
+ subject.name.should == "bar"
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+ context "comment with unknown token" do
46
+
47
+ before do
48
+ @comment.add_tokenline "some_unkown_token", "bar"
49
+ end
50
+
51
+ it "should not create a CodeObject" do
52
+ @comment.to_code_object.should == nil
53
+ end
54
+ end
55
+
56
+ context "comment with no tokens" do
57
+
58
+ it "should not create a CodeObject" do
59
+ @comment.to_code_object.should == nil
60
+ end
61
+
62
+ end
63
+
64
+ context "comment with multiple tokens" do
65
+
66
+ before do
67
+ @comment.add_tokenline "function", "foobar"
68
+ @comment.add_tokenline "object", "baz"
69
+ end
70
+
71
+ it "should raise an error" do
72
+ should_raise CodeObject::MultipleTypeDeclarations do
73
+ @comment.to_code_object
74
+ end
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,70 @@
1
+ # ../data.img#1774507:1
2
+ require_relative '../../lib/boot'
3
+
4
+ describe CodeObject::Prototype, ".new" do
5
+
6
+ context "Parsing prototype.js" do
7
+
8
+ before do
9
+ Logger.setup :level => :warn
10
+
11
+ Dom.clear
12
+ Processor.process_files_to_dom File.expand_path('../../js-files/prototype.js', __FILE__)
13
+ end
14
+
15
+ describe "the constructor-function" do
16
+
17
+ subject { Dom[:Person] }
18
+
19
+ it "should be a CodeObject::Function" do
20
+ subject.is_a?(CodeObject::Function).should == true
21
+ end
22
+
23
+ it "should have a children, called 'prototype'" do
24
+ subject[:prototype].should == subject.prototype
25
+ subject[:prototype].nil?.should == false
26
+ end
27
+
28
+ it "should be flagged as constructor" do
29
+ subject.constructor?.should == true
30
+ end
31
+
32
+ it "should contain only one child" do
33
+ subject.children.length.should == 1
34
+ end
35
+
36
+ end
37
+
38
+
39
+ describe "the prototype-object" do
40
+
41
+ subject { Dom[:Person][:prototype] }
42
+
43
+ it "should be a CodeObject::Prototype" do
44
+ subject.is_a?(CodeObject::Prototype).should == true
45
+ end
46
+
47
+ it "should have Person as parent" do
48
+ subject.parent.should == Dom[:Person]
49
+ subject.constructor.should == subject.parent
50
+ subject.constructor.nil?.should == false
51
+ end
52
+
53
+ it "should contain only one child" do
54
+ subject.children.length.should == 1
55
+ end
56
+ end
57
+
58
+
59
+ describe "the child of the prototype" do
60
+
61
+ subject { Dom[:Person][:prototype][:sayHello] }
62
+
63
+ it "should be a function" do
64
+ subject.is_a?(CodeObject::Function).should == true
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,65 @@
1
+ # ../data.img#1818355:1
2
+ require_relative '../lib/configs.rb'
3
+
4
+ describe Configs, ".new" do
5
+ it "should throw an error, when trying to instantiate" do
6
+ begin
7
+ Configs.new.should == nil
8
+ rescue NoMethodError
9
+ # Maybe there is a better way for this
10
+ true.should == true
11
+ end
12
+ end
13
+ end
14
+
15
+ describe Configs, ".set" do
16
+
17
+ before do
18
+ Configs.clear
19
+ end
20
+
21
+ context "adding a single property" do
22
+
23
+ it "should be added as a symbol" do
24
+ Configs.set :foo, 1234
25
+ Configs.foo.should == 1234
26
+ end
27
+
28
+ it "should be added as a string" do
29
+ Configs.set "bar", 1234
30
+ Configs.bar.should == 1234
31
+ end
32
+
33
+ it "should overwrite existing keys" do
34
+ Configs.set :foo, 456
35
+ Configs.foo.should == 456
36
+ end
37
+ end
38
+
39
+ it "should add multiple properties" do
40
+ Configs.set :prop1 => 1,
41
+ :prop2 => 2,
42
+ :prop3 => 3
43
+
44
+ Configs.prop1.should == 1
45
+ Configs.prop2.should == 2
46
+ Configs.prop3.should == 3
47
+ end
48
+
49
+ it "should return nil when trying to access not existing property" do
50
+ Configs.prop99.should == nil
51
+ end
52
+ end
53
+
54
+ describe Configs, ".clear" do
55
+
56
+ it "should contain no items after clearing" do
57
+ Configs.set :foo => 4,
58
+ :bar => 5
59
+
60
+ Configs.clear
61
+
62
+ Configs.foo.should == nil
63
+ Configs.bar.should == nil
64
+ end
65
+ end
@@ -0,0 +1,83 @@
1
+ Concept of the Documententation
2
+ ===============================
3
+
4
+ There are only two build-in types, we want to pay attention to:
5
+
6
+ 1. Objects
7
+ 2. Functions
8
+
9
+
10
+ Object
11
+ ------
12
+ By **Objects** we mean all kind of *things*, that can contain other things. Those containted ones, we call **properties** of the Object.
13
+
14
+ In JavaScript this may look like:
15
+
16
+ var obj = {
17
+ property_one: function() { ... },
18
+ property_two: {
19
+ // another object
20
+ },
21
+ property_three: 3
22
+ }
23
+
24
+
25
+ Function
26
+ --------
27
+ **Functions** are *things*, that can be executed. They can have **parameters** and **return-values** There are two types of Functions: plain functions and **constructors**.
28
+
29
+ Example for a plain function:
30
+
31
+ function my_func(param) {
32
+ return "Hello world!";
33
+ }
34
+
35
+ Example for a function as a constructor
36
+
37
+ function my_constructor() {
38
+ this.message = "Hello world!";
39
+ }
40
+
41
+
42
+ Remember: any return-value of a constructor-function will be ignored and replaced by this
43
+
44
+ ### Some third Headline ##
45
+
46
+ But a function can be an object at the same time. For example:
47
+
48
+ function my_func_two() {
49
+ return "fancy function";
50
+ }
51
+ my_func_two.message = "Say hello to Mr. Foo";
52
+
53
+ Most important a function can contain one special property **prototype**.
54
+ Linktest: {Core.logger The logger} and another doc-link: {doc:README.CONCEPT}
55
+
56
+ Remember: In this case the function has to be a constructor. Otherwise prototype would be useless, because it is only used when creating instances of the function using new. After creating an instance the prototype-object is accessible in the this-context of the instance.
57
+
58
+ function my_constructor() {
59
+ this.message = "Hello world!";
60
+ }
61
+ my_constructor.prop1 = 456;
62
+ my_constructor.prototype = {
63
+ some_proto_prop: 123
64
+ }
65
+
66
+ Revealing Module Pattern
67
+ ------------------------
68
+ But what about revealing modules?
69
+
70
+ function my_module() {
71
+
72
+ // some private stuff here
73
+
74
+ return {
75
+ property_of_the: "returned object"
76
+ };
77
+ }
78
+
79
+ One should pay attention to this pattern while creating a documentation tool.
80
+
81
+ Conclusion
82
+ ----------
83
+ So we can break it down to Functions and Objects. Objects can have properties. Functions can, at the same time, be Objects. There are special functions, called *constructors*, which in turn have one special property called *prototype*. This property has to be handled special in documentation.
@@ -0,0 +1,14 @@
1
+ jsdoc
2
+ =====
3
+ After total dataloss i have to rewrite the Readme's and Test's, so please be patient.
4
+ jsdoc is currently **not a bit** stable. Stay tuned. {doc:README.CONCEPT#Function} oder {doc:README}
5
+
6
+ For some more information about the architecture see:
7
+
8
+ - {Core Kern}
9
+ - {CodeObject}
10
+ - {Token}
11
+ - {Dom}
12
+ - {Renderer}
13
+
14
+ The 'executable' is {JsDoc}
@@ -0,0 +1,40 @@
1
+ require_relative '../../lib/dom/dom'
2
+ require_relative '../../lib/code_object/function'
3
+ require_relative '../../lib/processor'
4
+
5
+ describe Dom, ".add_child" do
6
+
7
+ context "Parsing absolute.js" do
8
+
9
+ before do
10
+ Dom.clear
11
+ Processor.process_files_to_dom File.expand_path('../../js-files/absolute.js', __FILE__)
12
+ end
13
+
14
+ it "should find only one root-object" do
15
+ Dom.children.length.should == 1
16
+ end
17
+
18
+ describe "Object 'Person'" do
19
+
20
+ subject { Dom[:Person] }
21
+
22
+ it "should have one child 'config'" do
23
+ subject[:config].nil?.should == false
24
+ end
25
+
26
+ end
27
+
28
+ describe "Object 'config'" do
29
+
30
+ subject { Dom[:Person][:config] }
31
+
32
+ it "should have 'Person' as parent" do
33
+ subject.parent.should == Dom[:Person]
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,72 @@
1
+ # ../data.img#1811393:1
2
+ require_relative '../../lib/dom/dom'
3
+ require_relative '../../lib/code_object/function'
4
+
5
+ describe Dom, ".add_child" do
6
+
7
+ before do
8
+ Dom.clear
9
+ @o1 = CodeObject::Object.new
10
+ @o2 = CodeObject::Object.new
11
+ end
12
+
13
+ it "should add absolute nodes" do
14
+ Dom.add_node "Foo", @o1
15
+ Dom[:Foo].should == @o1
16
+ end
17
+
18
+ it "should add absolute nodes from node" do
19
+ @o1.add_node "Foo", @o2
20
+ Dom[:Foo].should == @o2
21
+ end
22
+
23
+ it "should insert missing nodes as NoDoc" do
24
+ Dom.add_node "Foo.bar.baz.bam", @o1
25
+ Dom[:Foo].class.should == Dom::NoDoc
26
+ Dom[:Foo][:bar].class.should == Dom::NoDoc
27
+ Dom[:Foo][:bar][:baz].class.should == Dom::NoDoc
28
+ Dom[:Foo][:bar][:baz][:bam].should == @o1
29
+ end
30
+
31
+ it "should replace NoDoc-leafs with nodes" do
32
+ Dom.add_node "Foo.bar.baz.bam", @o1
33
+ Dom.add_node "Foo.bar.baz", @o2
34
+ Dom[:Foo].class.should == Dom::NoDoc
35
+ Dom[:Foo][:bar].class.should == Dom::NoDoc
36
+ Dom[:Foo][:bar][:baz].should == @o2
37
+ Dom[:Foo][:bar][:baz][:bam].should == @o1
38
+ end
39
+
40
+ it "should not allow replacing existing node" do
41
+ Dom.add_node "Foo.bar.baz.bam", @o1
42
+
43
+ should_raise Dom::NodeAlreadyExists do
44
+ Dom.add_node "Foo.bar.baz.bam", @o2
45
+ end
46
+ end
47
+
48
+ it "should reject not wellformed paths" do
49
+ [ "Foo..bar.baz.bam",
50
+ "-foo.bar-baz.foo",
51
+ ""
52
+ ].each do |path|
53
+ should_raise Dom::WrongPath do
54
+ Dom.add_node path, @o2
55
+ end
56
+ end
57
+ end
58
+
59
+ it "should set correct parent, while rebuilding" do
60
+ Dom.add_node "Foo.bar.baz.bam", @o1
61
+ Dom.add_node "Foo.bar.baz", @o2
62
+
63
+ @o1.parent.should == @o2
64
+ end
65
+
66
+ it "should append relative paths to current object" do
67
+ Dom.add_node "Foo.bar", @o1
68
+ @o1.add_node ".poo", @o2
69
+
70
+ Dom[:Foo][:bar][:poo].should == @o2
71
+ end
72
+ end