pdoc 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/README.markdown +34 -0
  2. data/Rakefile +46 -0
  3. data/bin/pdoc +58 -0
  4. data/lib/pdoc.rb +32 -0
  5. data/lib/pdoc/error.rb +4 -0
  6. data/lib/pdoc/generators.rb +6 -0
  7. data/lib/pdoc/generators/abstract_generator.rb +16 -0
  8. data/lib/pdoc/generators/html.rb +8 -0
  9. data/lib/pdoc/generators/html/helpers.rb +256 -0
  10. data/lib/pdoc/generators/html/page.rb +71 -0
  11. data/lib/pdoc/generators/html/syntax_highlighter.rb +41 -0
  12. data/lib/pdoc/generators/html/template.rb +37 -0
  13. data/lib/pdoc/generators/html/website.rb +194 -0
  14. data/lib/pdoc/generators/json.rb +15 -0
  15. data/lib/pdoc/generators/pythonesque.rb +105 -0
  16. data/lib/pdoc/models.rb +47 -0
  17. data/lib/pdoc/models/argument.rb +37 -0
  18. data/lib/pdoc/models/base.rb +107 -0
  19. data/lib/pdoc/models/callable.rb +19 -0
  20. data/lib/pdoc/models/class.rb +28 -0
  21. data/lib/pdoc/models/class_method.rb +18 -0
  22. data/lib/pdoc/models/class_property.rb +9 -0
  23. data/lib/pdoc/models/constant.rb +9 -0
  24. data/lib/pdoc/models/constructor.rb +14 -0
  25. data/lib/pdoc/models/container.rb +114 -0
  26. data/lib/pdoc/models/entity.rb +54 -0
  27. data/lib/pdoc/models/instance_method.rb +18 -0
  28. data/lib/pdoc/models/instance_property.rb +9 -0
  29. data/lib/pdoc/models/mixin.rb +10 -0
  30. data/lib/pdoc/models/namespace.rb +10 -0
  31. data/lib/pdoc/models/root.rb +27 -0
  32. data/lib/pdoc/models/section.rb +19 -0
  33. data/lib/pdoc/models/signature.rb +27 -0
  34. data/lib/pdoc/models/utility.rb +11 -0
  35. data/lib/pdoc/parser.rb +109 -0
  36. data/lib/pdoc/parser/argument_description_nodes.rb +21 -0
  37. data/lib/pdoc/parser/basic_nodes.rb +31 -0
  38. data/lib/pdoc/parser/description_nodes.rb +42 -0
  39. data/lib/pdoc/parser/documentation_nodes.rb +483 -0
  40. data/lib/pdoc/parser/ebnf_arguments_nodes.rb +58 -0
  41. data/lib/pdoc/parser/ebnf_expression_nodes.rb +227 -0
  42. data/lib/pdoc/parser/fragment.rb +55 -0
  43. data/lib/pdoc/parser/section_content_nodes.rb +19 -0
  44. data/lib/pdoc/parser/tags_nodes.rb +14 -0
  45. data/lib/pdoc/parser/treetop_files/argument_description.treetop +31 -0
  46. data/lib/pdoc/parser/treetop_files/basic.treetop +41 -0
  47. data/lib/pdoc/parser/treetop_files/description.treetop +7 -0
  48. data/lib/pdoc/parser/treetop_files/documentation.treetop +75 -0
  49. data/lib/pdoc/parser/treetop_files/ebnf_arguments.treetop +33 -0
  50. data/lib/pdoc/parser/treetop_files/ebnf_expression.treetop +70 -0
  51. data/lib/pdoc/parser/treetop_files/ebnf_javascript.treetop +54 -0
  52. data/lib/pdoc/parser/treetop_files/events.treetop +17 -0
  53. data/lib/pdoc/parser/treetop_files/section_content.treetop +8 -0
  54. data/lib/pdoc/parser/treetop_files/tags.treetop +31 -0
  55. data/lib/pdoc/runner.rb +110 -0
  56. data/lib/pdoc/treemaker.rb +94 -0
  57. data/pdoc.gemspec +31 -0
  58. data/templates/html/assets/images/pdoc/alias.png +0 -0
  59. data/templates/html/assets/images/pdoc/class.png +0 -0
  60. data/templates/html/assets/images/pdoc/class_deprecated.png +0 -0
  61. data/templates/html/assets/images/pdoc/class_method.png +0 -0
  62. data/templates/html/assets/images/pdoc/class_property.png +0 -0
  63. data/templates/html/assets/images/pdoc/constant.png +0 -0
  64. data/templates/html/assets/images/pdoc/constructor.png +0 -0
  65. data/templates/html/assets/images/pdoc/deprecated.png +0 -0
  66. data/templates/html/assets/images/pdoc/description.png +0 -0
  67. data/templates/html/assets/images/pdoc/information.png +0 -0
  68. data/templates/html/assets/images/pdoc/instance_method.png +0 -0
  69. data/templates/html/assets/images/pdoc/instance_property.png +0 -0
  70. data/templates/html/assets/images/pdoc/method.png +0 -0
  71. data/templates/html/assets/images/pdoc/method_deprecated.png +0 -0
  72. data/templates/html/assets/images/pdoc/mixin.png +0 -0
  73. data/templates/html/assets/images/pdoc/namespace.png +0 -0
  74. data/templates/html/assets/images/pdoc/property.png +0 -0
  75. data/templates/html/assets/images/pdoc/related_to.png +0 -0
  76. data/templates/html/assets/images/pdoc/search-background.png +0 -0
  77. data/templates/html/assets/images/pdoc/section-background.png +0 -0
  78. data/templates/html/assets/images/pdoc/section.png +0 -0
  79. data/templates/html/assets/images/pdoc/selected-section-background.png +0 -0
  80. data/templates/html/assets/images/pdoc/subclass.png +0 -0
  81. data/templates/html/assets/images/pdoc/superclass.png +0 -0
  82. data/templates/html/assets/images/pdoc/utility.png +0 -0
  83. data/templates/html/assets/javascripts/pdoc/application.js +478 -0
  84. data/templates/html/assets/javascripts/pdoc/prototype.js +4874 -0
  85. data/templates/html/assets/javascripts/pdoc/tabs.js +506 -0
  86. data/templates/html/assets/stylesheets/pdoc/api.css +677 -0
  87. data/templates/html/assets/stylesheets/pdoc/pygments.css +62 -0
  88. data/templates/html/helpers.rb +35 -0
  89. data/templates/html/index.erb +18 -0
  90. data/templates/html/item_index.js.erb +6 -0
  91. data/templates/html/layout.erb +67 -0
  92. data/templates/html/leaf.erb +22 -0
  93. data/templates/html/node.erb +30 -0
  94. data/templates/html/partials/class_relationships.erb +19 -0
  95. data/templates/html/partials/classes.erb +7 -0
  96. data/templates/html/partials/constructor.erb +5 -0
  97. data/templates/html/partials/description.erb +5 -0
  98. data/templates/html/partials/link_list.erb +1 -0
  99. data/templates/html/partials/method_signatures.erb +14 -0
  100. data/templates/html/partials/methodized_note.erb +9 -0
  101. data/templates/html/partials/mixins.erb +7 -0
  102. data/templates/html/partials/namespaces.erb +7 -0
  103. data/templates/html/partials/related_utilities.erb +5 -0
  104. data/templates/html/partials/relationships.erb +11 -0
  105. data/templates/html/partials/short_description_list.erb +7 -0
  106. data/templates/html/partials/title.erb +22 -0
  107. data/templates/html/section.erb +18 -0
  108. data/test/unit/parser/argument_description_test.rb +40 -0
  109. data/test/unit/parser/basic_test.rb +55 -0
  110. data/test/unit/parser/description_test.rb +34 -0
  111. data/test/unit/parser/documentation_test.rb +520 -0
  112. data/test/unit/parser/ebnf_arguments_test.rb +81 -0
  113. data/test/unit/parser/ebnf_expression_test.rb +382 -0
  114. data/test/unit/parser/ebnf_javascript_test.rb +37 -0
  115. data/test/unit/parser/events_test.rb +27 -0
  116. data/test/unit/parser/section_content_test.rb +44 -0
  117. data/test/unit/parser/tags_test.rb +39 -0
  118. data/test/unit/parser/test_fragment.rb +80 -0
  119. data/test/unit/parser_test_helper.rb +62 -0
  120. data/test/unit/runner/basic_test.rb +14 -0
  121. data/test/unit/templates/html_helpers_test.rb +25 -0
  122. metadata +222 -0
@@ -0,0 +1,47 @@
1
+ $:.unshift(File.dirname(__FILE__), 'models')
2
+
3
+ require 'models/base'
4
+ require 'models/entity'
5
+ require 'models/container'
6
+ require 'models/callable'
7
+ require 'models/section'
8
+ require 'models/root'
9
+ require 'models/argument'
10
+ require 'models/class'
11
+ require 'models/class_method'
12
+ require 'models/class_property'
13
+ require 'models/constant'
14
+ require 'models/constructor'
15
+ require 'models/instance_method'
16
+ require 'models/instance_property'
17
+ require 'models/mixin'
18
+ require 'models/namespace'
19
+ require 'models/signature'
20
+ require 'models/utility'
21
+
22
+ module PDoc
23
+ module Models
24
+ class << Models
25
+ attr_accessor :src_code_href
26
+ attr_accessor :doc_href
27
+ end
28
+
29
+ class Base
30
+ @@subclasses_by_type = {
31
+ 'section' => Section,
32
+ 'argument' => Argument,
33
+ 'class' => Class,
34
+ 'class method' => ClassMethod,
35
+ 'class property' => ClassProperty,
36
+ 'constant' => Constant,
37
+ 'constructor' => Constructor,
38
+ 'instance method' => InstanceMethod,
39
+ 'instance property' => InstanceProperty,
40
+ 'mixin' => Mixin,
41
+ 'namespace' => Namespace,
42
+ 'signature' => Signature,
43
+ 'utility' => Utility
44
+ }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,37 @@
1
+ module PDoc
2
+ module Models
3
+ class Argument < Base
4
+ attr_reader :name
5
+ attr_reader :default_value
6
+
7
+ def attach_to_parent(parent)
8
+ parent.arguments << self
9
+ end
10
+
11
+ # returns the argument's id in the form
12
+ # method_id:argument_name. So, for example:
13
+ # document.querySelectorAll:cssSelector
14
+ def id
15
+ @id ||= "#{parent.id}:#{name}"
16
+ end
17
+
18
+ def optional?
19
+ !!@optional
20
+ end
21
+
22
+ def types
23
+ @types ||= []
24
+ end
25
+
26
+ def to_hash
27
+ {
28
+ :name => name,
29
+ :description => description,
30
+ :default_value => default_value,
31
+ :optional => optional?,
32
+ :types => types
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,107 @@
1
+ module PDoc
2
+ module Models
3
+ class Base
4
+ @@subclasses_by_type = {}
5
+
6
+ def self.instantiate(attributes)
7
+ @@subclasses_by_type[attributes['type']].new(attributes)
8
+ end
9
+
10
+ attr_accessor :parent
11
+ attr_reader :description
12
+ attr_reader :id
13
+ attr_reader :type
14
+ attr_reader :file
15
+ attr_reader :line_number
16
+
17
+ def initialize(attributes = {})
18
+ attributes.each { |k, v| instance_variable_set("@#{k}", v) }
19
+ end
20
+
21
+ def register_on(registry)
22
+ registry[id] = self
23
+ end
24
+
25
+ def short_description
26
+ @short_description ||= description.split(/\n\n/).first
27
+ end
28
+
29
+ def deprecated?
30
+ return !!@deprecated if @deprecated
31
+ parent.respond_to?(:deprecated?) ? parent.deprecated? : false
32
+ end
33
+
34
+ def full_name
35
+ @id
36
+ end
37
+
38
+ def name
39
+ @name ||= @id.match(/[\w\d\$]+$/)[0]
40
+ end
41
+
42
+ def ancestor_of?(obj)
43
+ while obj = obj.parent
44
+ return true if obj == self
45
+ end
46
+ false
47
+ end
48
+
49
+ def descendant_of?(obj)
50
+ obj.ancestor_of?(self)
51
+ end
52
+
53
+ def doc_href
54
+ proc = Models.doc_href
55
+ @doc_href ||= proc ? proc.call(self) : nil
56
+ end
57
+
58
+ def url(separator = '/')
59
+ result = []
60
+ obj = self
61
+ begin
62
+ result << obj.normalized_name
63
+ if obj.is_a?(Models::InstanceMethod) || obj.is_a?(Models::InstanceProperty)
64
+ result << 'prototype'
65
+ end
66
+ obj = obj.parent
67
+ end until obj.is_a?(Models::Root)
68
+ result.reverse.join(separator)
69
+ end
70
+
71
+ def to_hash
72
+ {
73
+ :deprecated => deprecated?,
74
+ :id => id,
75
+ :type => type,
76
+ :description => description,
77
+ :short_description => short_description,
78
+ :parent => parent.is_a?(Models::Root) ? nil : parent.id,
79
+ :doc_href => doc_href
80
+ }
81
+ end
82
+
83
+ def to_json(*args)
84
+ to_hash.to_json(*args)
85
+ end
86
+
87
+ def normalized_name
88
+ @normalized_name ||= name.gsub(/(^\$+$)|(^\$+)|(\$+$)|(\$+)/) do |m|
89
+ dollar = Array.new(m.length, 'dollar').join('-')
90
+ if $1
91
+ dollar
92
+ elsif $2
93
+ "#{dollar}-"
94
+ elsif $3
95
+ "-#{dollar}"
96
+ elsif $4
97
+ "-#{dollar}-"
98
+ end
99
+ end
100
+ end
101
+
102
+ def inspect
103
+ "#<#{self.class} #{id}>"
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,19 @@
1
+ module PDoc
2
+ module Models
3
+ module Callable
4
+ def arguments
5
+ @arguments ||= []
6
+ end
7
+
8
+ def arguments?
9
+ @arguments && !@arguments.empty?
10
+ end
11
+
12
+ def to_hash
13
+ super.merge({
14
+ :arguments => arguments
15
+ })
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ module PDoc
2
+ module Models
3
+ class Class < Entity
4
+ include Container
5
+ attr_accessor :constructor
6
+ attr_accessor :superclass
7
+ def attach_to_parent(parent)
8
+ parent.classes << self
9
+ end
10
+
11
+ def subclasses
12
+ @subclasses ||= []
13
+ end
14
+
15
+ def subclasses?
16
+ @subclasses && !@subclasses.empty?
17
+ end
18
+
19
+ def to_hash
20
+ super.merge({
21
+ :superclass => superclass,
22
+ :constructor => constructor,
23
+ :subclasses => subclasses.map { |obj| obj.id }
24
+ })
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ module PDoc
2
+ module Models
3
+ class ClassMethod < Entity
4
+ include Callable
5
+ attr_accessor :methodized_self
6
+ def attach_to_parent(parent)
7
+ parent.class_methods << self
8
+ end
9
+
10
+ def to_hash
11
+ m = methodized_self
12
+ super.merge({
13
+ :methodized_self => m ? m.id : nil
14
+ })
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module PDoc
2
+ module Models
3
+ class ClassProperty < Entity
4
+ def attach_to_parent(parent)
5
+ parent.class_properties << self
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module PDoc
2
+ module Models
3
+ class Constant < Entity
4
+ def attach_to_parent(parent)
5
+ parent.constants << self
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module PDoc
2
+ module Models
3
+ class Constructor < Entity
4
+ include Callable
5
+ def attach_to_parent(parent)
6
+ parent.constructor = self
7
+ end
8
+
9
+ def name
10
+ @name ||= 'new'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,114 @@
1
+ module PDoc
2
+ module Models
3
+ module Container
4
+ def children
5
+ @children ||= []
6
+ end
7
+
8
+ def children?
9
+ @children && !@children.empty?
10
+ end
11
+
12
+ # returns an array of Namespace objects belonging to this section
13
+ def namespaces
14
+ @namespaces ||= []
15
+ end
16
+
17
+ def namespaces?
18
+ @namespaces && !@namespaces.empty?
19
+ end
20
+
21
+ # returns an array of Class objects belonging to this section
22
+ def classes
23
+ @classes ||= []
24
+ end
25
+
26
+ def classes?
27
+ @classes && !@classes.empty?
28
+ end
29
+
30
+ # returns an array of Mixin objects belonging to this section
31
+ def mixins
32
+ @mixins ||= []
33
+ end
34
+
35
+ def mixins?
36
+ @mixins && !@mixins.empty?
37
+ end
38
+
39
+ def included_mixins
40
+ @included_mixins ||= []
41
+ end
42
+
43
+ def included_mixins?
44
+ @included_mixins && !@included_mixins.empty?
45
+ end
46
+
47
+ # returns an array of Function objects belonging to this section
48
+ def utilities
49
+ @utilities ||= []
50
+ end
51
+
52
+ def utilities?
53
+ @utilities && !@utilities.empty?
54
+ end
55
+
56
+ # returns an array of constants objects belonging to this section
57
+ def constants
58
+ @constants ||= []
59
+ end
60
+
61
+ def constants?
62
+ @constants && !@constants.empty?
63
+ end
64
+
65
+ def class_methods
66
+ @class_methods ||= []
67
+ end
68
+
69
+ def class_methods?
70
+ @class_methods && !@class_methods.empty?
71
+ end
72
+
73
+ def class_properties
74
+ @class_properties ||= []
75
+ end
76
+
77
+ def class_properties?
78
+ @class_properties && !@class_properties.empty?
79
+ end
80
+
81
+ def instance_methods
82
+ @instance_methods ||= []
83
+ end
84
+
85
+ def instance_methods?
86
+ @instance_methods && !@instance_methods.empty?
87
+ end
88
+
89
+ def instance_properties
90
+ @instance_properties ||= []
91
+ end
92
+
93
+ def instance_properties?
94
+ @instance_properties && !@instance_properties.empty?
95
+ end
96
+
97
+ def to_hash
98
+ super.merge({
99
+ :children => children.map { |obj| obj.id },
100
+ :namespaces => namespaces.map { |obj| obj.id },
101
+ :classes => classes.map { |obj| obj.id },
102
+ :mixins => mixins.map { |obj| obj.id },
103
+ :included_mixins => included_mixins.map { |obj| obj.id },
104
+ :utilities => utilities.map { |obj| obj.id },
105
+ :constants => constants.map { |obj| obj.id },
106
+ :class_methods => class_methods.map { |obj| obj.id },
107
+ :class_properties => class_properties.map { |obj| obj.id },
108
+ :instance_methods => instance_methods.map { |obj| obj.id },
109
+ :instance_properties => instance_properties.map { |obj| obj.id }
110
+ })
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,54 @@
1
+ module PDoc
2
+ module Models
3
+ class Entity < Base
4
+ attr_accessor :alias
5
+
6
+ def signatures
7
+ @signatures ||= []
8
+ end
9
+
10
+ def <=>(other)
11
+ id.downcase <=> other.id.downcase
12
+ end
13
+
14
+ def src_code_href
15
+ proc = Models.src_code_href
16
+ @src_code_href ||= proc ? proc.call(self) : nil
17
+ end
18
+
19
+ def signatures?
20
+ @signatures && !@signatures.empty?
21
+ end
22
+
23
+ def signature
24
+ @signature ||= signatures.first
25
+ end
26
+
27
+ def methodized?
28
+ !!@methodized
29
+ end
30
+
31
+ def alias?
32
+ !!@alias
33
+ end
34
+
35
+ # returns an array of aliases
36
+ def aliases
37
+ @aliases ||= []
38
+ end
39
+
40
+ def aliases?
41
+ @aliases && !@aliases.empty?
42
+ end
43
+
44
+ def to_hash
45
+ super.merge({
46
+ :aliases => aliases.map { |a| a.id },
47
+ :alias => self.alias ? self.alias.id : nil,
48
+ :signatures => signatures,
49
+ :src_code_href => src_code_href
50
+ })
51
+ end
52
+ end
53
+ end
54
+ end