rdoc 3.9.5 → 3.10.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (183) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +6 -3
  3. data/History.txt +63 -13
  4. data/LICENSE.rdoc +57 -0
  5. data/Manifest.txt +60 -6
  6. data/Rakefile +24 -12
  7. data/TODO.rdoc +30 -0
  8. data/bin/rdoc +0 -2
  9. data/lib/rdoc.rb +55 -2
  10. data/lib/rdoc/alias.rb +0 -2
  11. data/lib/rdoc/anon_class.rb +0 -2
  12. data/lib/rdoc/any_method.rb +0 -3
  13. data/lib/rdoc/attr.rb +0 -2
  14. data/lib/rdoc/class_module.rb +40 -7
  15. data/lib/rdoc/code_object.rb +1 -3
  16. data/lib/rdoc/code_objects.rb +3 -21
  17. data/lib/rdoc/comment.rb +225 -0
  18. data/lib/rdoc/constant.rb +0 -2
  19. data/lib/rdoc/context.rb +37 -120
  20. data/lib/rdoc/context/section.rb +114 -0
  21. data/lib/rdoc/cross_reference.rb +16 -7
  22. data/lib/rdoc/encoding.rb +0 -2
  23. data/lib/rdoc/gauntlet.rb +1 -1
  24. data/lib/rdoc/generator.rb +7 -2
  25. data/lib/rdoc/generator/darkfish.rb +126 -20
  26. data/lib/rdoc/generator/json_index.rb +240 -0
  27. data/lib/rdoc/generator/markup.rb +17 -54
  28. data/lib/rdoc/generator/ri.rb +0 -3
  29. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  30. data/lib/rdoc/generator/template/darkfish/_head.rhtml +16 -0
  31. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +18 -0
  32. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +8 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +16 -0
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +7 -0
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  38. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +10 -0
  39. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +10 -0
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +10 -0
  41. data/lib/rdoc/generator/template/darkfish/class.rhtml +161 -0
  42. data/lib/rdoc/generator/template/darkfish/fileinfo.rhtml +32 -0
  43. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  44. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  45. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  46. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  47. data/lib/rdoc/generator/template/darkfish/index.rhtml +16 -61
  48. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +99 -64
  49. data/lib/rdoc/generator/template/darkfish/js/jquery.js +15 -29
  50. data/lib/rdoc/generator/template/darkfish/js/search.js +94 -0
  51. data/lib/rdoc/generator/template/darkfish/page.rhtml +16 -0
  52. data/lib/rdoc/generator/template/darkfish/rdoc.css +126 -286
  53. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +50 -0
  54. data/lib/rdoc/generator/template/json_index/js/navigation.js +142 -0
  55. data/lib/rdoc/generator/template/json_index/js/searcher.js +228 -0
  56. data/lib/rdoc/ghost_method.rb +0 -2
  57. data/lib/rdoc/include.rb +0 -2
  58. data/lib/rdoc/markup.rb +204 -43
  59. data/lib/rdoc/markup/attr_changer.rb +25 -0
  60. data/lib/rdoc/markup/attr_span.rb +29 -0
  61. data/lib/rdoc/markup/attribute.rb +51 -0
  62. data/lib/rdoc/markup/document.rb +22 -1
  63. data/lib/rdoc/markup/formatter.rb +4 -11
  64. data/lib/rdoc/markup/formatter_test_case.rb +1 -2
  65. data/lib/rdoc/markup/heading.rb +44 -0
  66. data/lib/rdoc/markup/include.rb +42 -0
  67. data/lib/rdoc/markup/inline.rb +1 -144
  68. data/lib/rdoc/markup/list.rb +2 -1
  69. data/lib/rdoc/markup/parser.rb +6 -16
  70. data/lib/rdoc/markup/pre_process.rb +64 -10
  71. data/lib/rdoc/markup/raw.rb +1 -1
  72. data/lib/rdoc/markup/special.rb +40 -0
  73. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -2
  74. data/lib/rdoc/markup/to_ansi.rb +0 -2
  75. data/lib/rdoc/markup/to_bs.rb +0 -2
  76. data/lib/rdoc/markup/to_html.rb +102 -34
  77. data/lib/rdoc/markup/to_html_crossref.rb +36 -5
  78. data/lib/rdoc/markup/to_html_snippet.rb +270 -0
  79. data/lib/rdoc/markup/to_label.rb +55 -0
  80. data/lib/rdoc/markup/to_rdoc.rb +0 -3
  81. data/lib/rdoc/markup/to_table_of_contents.rb +62 -0
  82. data/lib/rdoc/markup/to_test.rb +0 -3
  83. data/lib/rdoc/markup/to_tt_only.rb +0 -3
  84. data/lib/rdoc/markup/verbatim.rb +18 -0
  85. data/lib/rdoc/meta_method.rb +0 -2
  86. data/lib/rdoc/method_attr.rb +17 -1
  87. data/lib/rdoc/normal_class.rb +0 -2
  88. data/lib/rdoc/normal_module.rb +0 -2
  89. data/lib/rdoc/options.rb +18 -3
  90. data/lib/rdoc/parser.rb +74 -42
  91. data/lib/rdoc/parser/c.rb +79 -118
  92. data/lib/rdoc/parser/rd.rb +22 -0
  93. data/lib/rdoc/parser/ruby.rb +86 -54
  94. data/lib/rdoc/parser/simple.rb +21 -9
  95. data/lib/rdoc/parser/text.rb +11 -0
  96. data/lib/rdoc/rd.rb +95 -0
  97. data/lib/rdoc/rd/block_parser.ry +638 -0
  98. data/lib/rdoc/rd/inline.rb +71 -0
  99. data/lib/rdoc/rd/inline_parser.ry +575 -0
  100. data/lib/rdoc/rdoc.rb +8 -23
  101. data/lib/rdoc/require.rb +0 -2
  102. data/lib/rdoc/ri.rb +4 -2
  103. data/lib/rdoc/ri/driver.rb +2 -6
  104. data/lib/rdoc/ri/store.rb +0 -1
  105. data/lib/rdoc/ruby_lex.rb +43 -20
  106. data/lib/rdoc/ruby_token.rb +44 -2
  107. data/lib/rdoc/single_class.rb +0 -2
  108. data/lib/rdoc/stats.rb +0 -5
  109. data/lib/rdoc/task.rb +2 -6
  110. data/lib/rdoc/test_case.rb +59 -0
  111. data/lib/rdoc/text.rb +42 -30
  112. data/lib/rdoc/token_stream.rb +45 -0
  113. data/lib/rdoc/tom_doc.rb +232 -0
  114. data/lib/rdoc/top_level.rb +36 -4
  115. data/test/test_attribute_manager.rb +26 -29
  116. data/test/test_rdoc_any_method.rb +2 -26
  117. data/test/test_rdoc_attr.rb +4 -4
  118. data/test/test_rdoc_class_module.rb +95 -12
  119. data/test/test_rdoc_code_object.rb +10 -3
  120. data/test/test_rdoc_comment.rb +504 -0
  121. data/test/test_rdoc_context.rb +60 -11
  122. data/test/test_rdoc_context_section.rb +16 -17
  123. data/test/test_rdoc_cross_reference.rb +17 -2
  124. data/test/test_rdoc_encoding.rb +4 -7
  125. data/test/test_rdoc_generator_darkfish.rb +12 -11
  126. data/test/test_rdoc_generator_json_index.rb +255 -0
  127. data/test/test_rdoc_generator_markup.rb +56 -0
  128. data/test/test_rdoc_generator_ri.rb +8 -11
  129. data/test/test_rdoc_markup.rb +9 -5
  130. data/test/test_rdoc_markup_attribute_manager.rb +5 -8
  131. data/test/test_rdoc_markup_document.rb +34 -6
  132. data/test/test_rdoc_markup_formatter.rb +11 -13
  133. data/test/test_rdoc_markup_heading.rb +20 -0
  134. data/test/test_rdoc_markup_include.rb +19 -0
  135. data/test/test_rdoc_markup_indented_paragraph.rb +4 -5
  136. data/test/test_rdoc_markup_paragraph.rb +2 -5
  137. data/test/test_rdoc_markup_parser.rb +87 -7
  138. data/test/test_rdoc_markup_pre_process.rb +60 -9
  139. data/test/test_rdoc_markup_raw.rb +4 -6
  140. data/test/test_rdoc_markup_to_ansi.rb +1 -4
  141. data/test/test_rdoc_markup_to_bs.rb +1 -4
  142. data/test/test_rdoc_markup_to_html.rb +170 -31
  143. data/test/test_rdoc_markup_to_html_crossref.rb +89 -11
  144. data/test/test_rdoc_markup_to_html_snippet.rb +668 -0
  145. data/test/test_rdoc_markup_to_label.rb +50 -0
  146. data/test/test_rdoc_markup_to_rdoc.rb +1 -4
  147. data/test/test_rdoc_markup_to_table_of_contents.rb +90 -0
  148. data/test/test_rdoc_markup_to_tt_only.rb +1 -4
  149. data/test/test_rdoc_markup_verbatim.rb +16 -0
  150. data/test/test_rdoc_method_attr.rb +16 -1
  151. data/test/test_rdoc_options.rb +17 -7
  152. data/test/test_rdoc_parser.rb +75 -6
  153. data/test/test_rdoc_parser_c.rb +56 -104
  154. data/test/test_rdoc_parser_rd.rb +52 -0
  155. data/test/test_rdoc_parser_ruby.rb +264 -323
  156. data/test/test_rdoc_parser_simple.rb +33 -17
  157. data/test/test_rdoc_rd.rb +30 -0
  158. data/test/test_rdoc_rd_block_parser.rb +527 -0
  159. data/test/test_rdoc_rd_inline.rb +63 -0
  160. data/test/test_rdoc_rd_inline_parser.rb +173 -0
  161. data/test/test_rdoc_rdoc.rb +7 -9
  162. data/test/test_rdoc_ri_driver.rb +10 -15
  163. data/test/test_rdoc_ri_paths.rb +6 -6
  164. data/test/test_rdoc_ri_store.rb +6 -13
  165. data/test/test_rdoc_ruby_lex.rb +53 -5
  166. data/test/test_rdoc_rubygems_hook.rb +2 -1
  167. data/test/test_rdoc_stats.rb +83 -103
  168. data/test/test_rdoc_task.rb +5 -4
  169. data/test/test_rdoc_text.rb +156 -11
  170. data/test/test_rdoc_token_stream.rb +42 -0
  171. data/test/test_rdoc_tom_doc.rb +458 -0
  172. data/test/test_rdoc_top_level.rb +49 -2
  173. data/test/xref_test_case.rb +4 -8
  174. metadata +217 -111
  175. metadata.gz.sig +0 -0
  176. checksums.yaml +0 -7
  177. checksums.yaml.gz.sig +0 -0
  178. data/CVE-2013-0256.rdoc +0 -49
  179. data/LICENSE.txt +0 -57
  180. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -321
  181. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  182. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  183. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
@@ -1,5 +1,3 @@
1
- require 'rdoc/code_object'
2
-
3
1
  ##
4
2
  # A constant
5
3
 
@@ -1,4 +1,4 @@
1
- require 'rdoc/code_object'
1
+ require 'cgi'
2
2
 
3
3
  ##
4
4
  # A Context is something that can hold modules, classes, methods, attributes,
@@ -14,6 +14,12 @@ class RDoc::Context < RDoc::CodeObject
14
14
 
15
15
  TYPES = %w[class instance]
16
16
 
17
+ ##
18
+ # If a context has these titles it will be sorted in this order.
19
+
20
+ TOMDOC_TITLES = [nil, 'Public', 'Internal', 'Deprecated'] # :nodoc:
21
+ TOMDOC_TITLES_SORT = TOMDOC_TITLES.sort_by { |title| title.to_s } # :nodoc:
22
+
17
23
  ##
18
24
  # Class/module aliases
19
25
 
@@ -92,118 +98,6 @@ class RDoc::Context < RDoc::CodeObject
92
98
 
93
99
  attr_reader :constants_hash
94
100
 
95
- ##
96
- # A section of documentation like:
97
- #
98
- # # :section: The title
99
- # # The body
100
- #
101
- # Sections can be referenced multiple times and will be collapsed into a
102
- # single section.
103
-
104
- class Section
105
-
106
- include RDoc::Text
107
-
108
- ##
109
- # Section comment
110
-
111
- attr_reader :comment
112
-
113
- ##
114
- # Context this Section lives in
115
-
116
- attr_reader :parent
117
-
118
- ##
119
- # Section title
120
-
121
- attr_reader :title
122
-
123
- @@sequence = "SEC00000"
124
-
125
- ##
126
- # Creates a new section with +title+ and +comment+
127
-
128
- def initialize parent, title, comment
129
- @parent = parent
130
- @title = title ? title.strip : title
131
-
132
- @@sequence.succ!
133
- @sequence = @@sequence.dup
134
-
135
- @comment = extract_comment comment
136
- end
137
-
138
- ##
139
- # Sections are equal when they have the same #title
140
-
141
- def == other
142
- self.class === other and @title == other.title
143
- end
144
-
145
- ##
146
- # Anchor reference for linking to this section
147
-
148
- def aref
149
- title = @title || '[untitled]'
150
-
151
- CGI.escape(title).gsub('%', '-').sub(/^-/, '')
152
- end
153
-
154
- ##
155
- # Appends +comment+ to the current comment separated by a rule.
156
-
157
- def comment= comment
158
- comment = extract_comment comment
159
-
160
- return if comment.empty?
161
-
162
- if @comment then
163
- @comment += "\n# ---\n#{comment}"
164
- else
165
- @comment = comment
166
- end
167
- end
168
-
169
- ##
170
- # Extracts the comment for this section from the original comment block.
171
- # If the first line contains :section:, strip it and use the rest.
172
- # Otherwise remove lines up to the line containing :section:, and look
173
- # for those lines again at the end and remove them. This lets us write
174
- #
175
- # # :section: The title
176
- # # The body
177
-
178
- def extract_comment comment
179
- if comment =~ /^#[ \t]*:section:.*\n/ then
180
- start = $`
181
- rest = $'
182
-
183
- if start.empty? then
184
- rest
185
- else
186
- rest.sub(/#{start.chomp}\Z/, '')
187
- end
188
- else
189
- comment
190
- end
191
- end
192
-
193
- def inspect # :nodoc:
194
- "#<%s:0x%x %p>" % [self.class, object_id, title]
195
- end
196
-
197
- ##
198
- # Section sequence number (deprecated)
199
-
200
- def sequence
201
- warn "RDoc::Context::Section#sequence is deprecated, use #aref"
202
- @sequence
203
- end
204
-
205
- end
206
-
207
101
  ##
208
102
  # Creates an unnamed empty context with public current visibility
209
103
 
@@ -602,9 +496,9 @@ class RDoc::Context < RDoc::CodeObject
602
496
  #
603
497
  # See also RDoc::Context::Section
604
498
 
605
- def add_section title, comment
499
+ def add_section title, comment = nil
606
500
  if section = @sections[title] then
607
- section.comment = comment
501
+ section.comment = comment if comment
608
502
  else
609
503
  section = Section.new self, title, comment
610
504
  @sections[title] = section
@@ -773,13 +667,15 @@ class RDoc::Context < RDoc::CodeObject
773
667
  # NOTE: Do not edit collections yielded by this method
774
668
 
775
669
  def each_section # :yields: section, constants, attributes
670
+ return enum_for __method__ unless block_given?
671
+
776
672
  constants = @constants.group_by do |constant| constant.section end
777
673
  constants.default = []
778
674
 
779
675
  attributes = @attributes.group_by do |attribute| attribute.section end
780
676
  attributes.default = []
781
677
 
782
- @sections.sort_by { |title, _| title.to_s }.each do |_, section|
678
+ sort_sections.each do |section|
783
679
  yield section, constants[section].sort, attributes[section].sort
784
680
  end
785
681
  end
@@ -1098,15 +994,14 @@ class RDoc::Context < RDoc::CodeObject
1098
994
  ##
1099
995
  # Only called when min_visibility == :public or :private
1100
996
 
1101
- def remove_invisible_in(array, min_visibility) # :nodoc:
1102
- if min_visibility == :public
997
+ def remove_invisible_in array, min_visibility # :nodoc:
998
+ if min_visibility == :public then
1103
999
  array.reject! { |e|
1104
1000
  e.visibility != :public and not e.force_documentation
1105
1001
  }
1106
1002
  else
1107
1003
  array.reject! { |e|
1108
- e.visibility == :private and
1109
- not e.force_documentation
1004
+ e.visibility == :private and not e.force_documentation
1110
1005
  }
1111
1006
  end
1112
1007
  end
@@ -1155,6 +1050,26 @@ class RDoc::Context < RDoc::CodeObject
1155
1050
  end
1156
1051
  end
1157
1052
 
1053
+ ##
1054
+ # Sorts sections alphabetically (default) or in TomDoc fasion (none, Public,
1055
+ # Internal, Deprecated)
1056
+
1057
+ def sort_sections
1058
+ titles = @sections.map { |title, _| title }
1059
+
1060
+ if titles.length > 1 and
1061
+ TOMDOC_TITLES_SORT ==
1062
+ (titles | TOMDOC_TITLES).sort_by { |title| title.to_s } then
1063
+ @sections.values_at(*TOMDOC_TITLES).compact
1064
+ else
1065
+ @sections.sort_by { |title, _|
1066
+ title.to_s
1067
+ }.map { |_, section|
1068
+ section
1069
+ }
1070
+ end
1071
+ end
1072
+
1158
1073
  def to_s # :nodoc:
1159
1074
  "#{self.class.name} #{self.full_name}"
1160
1075
  end
@@ -1187,5 +1102,7 @@ class RDoc::Context < RDoc::CodeObject
1187
1102
  klass
1188
1103
  end
1189
1104
 
1105
+ autoload :Section, 'rdoc/context/section'
1106
+
1190
1107
  end
1191
1108
 
@@ -0,0 +1,114 @@
1
+ ##
2
+ # A section of documentation like:
3
+ #
4
+ # # :section: The title
5
+ # # The body
6
+ #
7
+ # Sections can be referenced multiple times and will be collapsed into a
8
+ # single section.
9
+
10
+ class RDoc::Context::Section
11
+
12
+ include RDoc::Text
13
+
14
+ ##
15
+ # Section comment
16
+
17
+ attr_reader :comment
18
+
19
+ ##
20
+ # Context this Section lives in
21
+
22
+ attr_reader :parent
23
+
24
+ ##
25
+ # Section title
26
+
27
+ attr_reader :title
28
+
29
+ @@sequence = "SEC00000"
30
+
31
+ ##
32
+ # Creates a new section with +title+ and +comment+
33
+
34
+ def initialize parent, title, comment
35
+ @parent = parent
36
+ @title = title ? title.strip : title
37
+
38
+ @@sequence.succ!
39
+ @sequence = @@sequence.dup
40
+
41
+ @comment = nil
42
+ @comment = extract_comment comment if comment
43
+ end
44
+
45
+ ##
46
+ # Sections are equal when they have the same #title
47
+
48
+ def == other
49
+ self.class === other and @title == other.title
50
+ end
51
+
52
+ ##
53
+ # Anchor reference for linking to this section
54
+
55
+ def aref
56
+ title = @title || '[untitled]'
57
+
58
+ CGI.escape(title).gsub('%', '-').sub(/^-/, '')
59
+ end
60
+
61
+ ##
62
+ # Appends +comment+ to the current comment separated by a rule.
63
+
64
+ def comment= comment
65
+ comment = extract_comment comment
66
+
67
+ return if comment.empty?
68
+
69
+ if @comment then
70
+ # HACK should section comments get joined?
71
+ @comment.text += "\n# ---\n#{comment.text}"
72
+ else
73
+ @comment = comment
74
+ end
75
+ end
76
+
77
+ ##
78
+ # Extracts the comment for this section from the original comment block.
79
+ # If the first line contains :section:, strip it and use the rest.
80
+ # Otherwise remove lines up to the line containing :section:, and look
81
+ # for those lines again at the end and remove them. This lets us write
82
+ #
83
+ # # :section: The title
84
+ # # The body
85
+
86
+ def extract_comment comment
87
+ if comment.text =~ /^#[ \t]*:section:.*\n/ then
88
+ start = $`
89
+ rest = $'
90
+
91
+ comment.text = if start.empty? then
92
+ rest
93
+ else
94
+ rest.sub(/#{start.chomp}\Z/, '')
95
+ end
96
+ end
97
+
98
+ comment
99
+ end
100
+
101
+ def inspect # :nodoc:
102
+ "#<%s:0x%x %p>" % [self.class, object_id, title]
103
+ end
104
+
105
+ ##
106
+ # Section sequence number (deprecated)
107
+
108
+ def sequence
109
+ warn "RDoc::Context::Section#sequence is deprecated, use #aref"
110
+ @sequence
111
+ end
112
+
113
+ end
114
+
@@ -18,7 +18,7 @@ class RDoc::CrossReference
18
18
  #
19
19
  # See CLASS_REGEXP_STR
20
20
 
21
- METHOD_REGEXP_STR = '([a-z]\w*[!?=]?)(?:\([\w.+*/=<>-]*\))?'
21
+ METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%)(?:\([\w.+*/=<>-]*\))?'
22
22
 
23
23
  ##
24
24
  # Regular expressions matching text that should potentially have
@@ -51,19 +51,22 @@ class RDoc::CrossReference
51
51
  # after the cross-reference is a space, sentence
52
52
  # punctuation, tag start character, or attribute
53
53
  # marker.
54
- | #{CLASS_REGEXP_STR}(?=[\s\)\.\?\!\,\;<\000]|\z)
54
+ | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
55
55
 
56
56
  # Things that look like filenames
57
57
  # The key thing is that there must be at least
58
58
  # one special character (period, slash, or
59
59
  # underscore).
60
- | (?:\.\.\/)*[-\/\w]+[_\/\.][-\w\/\.]+
60
+ | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
61
61
 
62
62
  # Things that have markup suppressed
63
63
  # Don't process things like '\<' in \<tt>, though.
64
64
  # TODO: including < is a hack, not very satisfying.
65
65
  | \\[^\s<]
66
- )/x
66
+ )
67
+
68
+ # labels for headings
69
+ (?:@[\w+%-]+)?/x
67
70
 
68
71
  ##
69
72
  # Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.
@@ -76,14 +79,20 @@ class RDoc::CrossReference
76
79
  | \\?#{METHOD_REGEXP_STR}
77
80
 
78
81
  # A::B::C
79
- | #{CLASS_REGEXP_STR}(?=[\s\)\.\?\!\,\;<\000]|\z)
82
+ | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
80
83
 
81
84
  # Things that look like filenames
82
- | (?:\.\.\/)*[-\/\w]+[_\/\.][-\w\/\.]+
85
+ | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
83
86
 
84
87
  # Things that have markup suppressed
85
88
  | \\[^\s<]
86
- )/x
89
+ )
90
+
91
+ # labels for headings
92
+ (?:@[\w+%-]+)?/x
93
+
94
+ ##
95
+ # Hash of references that have been looked-up to their replacements
87
96
 
88
97
  attr_accessor :seen
89
98
 
@@ -1,7 +1,5 @@
1
1
  # coding: US-ASCII
2
2
 
3
- require 'rdoc'
4
-
5
3
  ##
6
4
  # This class is a wrapper around File IO and Encoding that helps RDoc load
7
5
  # files and convert them to the correct encoding.
@@ -1,4 +1,4 @@
1
- require 'rdoc/rdoc'
1
+ require 'rdoc'
2
2
  require 'gauntlet'
3
3
  require 'fileutils'
4
4
 
@@ -1,5 +1,3 @@
1
- require 'rdoc'
2
-
3
1
  ##
4
2
  # RDoc uses generators to turn parsed source code in the form of an
5
3
  # RDoc::CodeObject tree into some form of output. RDoc comes with the HTML
@@ -36,5 +34,12 @@ require 'rdoc'
36
34
  # to create your desired output format.
37
35
 
38
36
  module RDoc::Generator
37
+
38
+ autoload :Markup, 'rdoc/generator/markup'
39
+
40
+ autoload :Darkfish, 'rdoc/generator/darkfish'
41
+ autoload :JsonIndex, 'rdoc/generator/json_index'
42
+ autoload :RI, 'rdoc/generator/ri'
43
+
39
44
  end
40
45
 
@@ -1,9 +1,8 @@
1
1
  # -*- mode: ruby; ruby-indent-level: 2; tab-width: 2 -*-
2
2
 
3
- require 'pathname'
3
+ require 'erb'
4
4
  require 'fileutils'
5
- require 'rdoc/erbio'
6
-
5
+ require 'pathname'
7
6
  require 'rdoc/generator/markup'
8
7
 
9
8
  ##
@@ -46,6 +45,11 @@ require 'rdoc/generator/markup'
46
45
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47
46
  # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48
47
  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
+ #
49
+ # == Attributions
50
+ #
51
+ # Darkfish uses the {Silk Icons}[http://www.famfamfam.com/lab/icons/silk/] set
52
+ # by Mark James.
49
53
 
50
54
  class RDoc::Generator::Darkfish
51
55
 
@@ -53,6 +57,7 @@ class RDoc::Generator::Darkfish
53
57
 
54
58
  include ERB::Util
55
59
 
60
+ ##
56
61
  # Path to this file's parent directory. Used to find templates and other
57
62
  # resources.
58
63
 
@@ -61,13 +66,19 @@ class RDoc::Generator::Darkfish
61
66
  ##
62
67
  # Release Version
63
68
 
64
- VERSION = '2'
69
+ VERSION = '3'
65
70
 
66
71
  ##
67
72
  # Description of this generator
68
73
 
69
74
  DESCRIPTION = 'HTML generator, written by Michael Granger'
70
75
 
76
+ ##
77
+ # The path to generate files into, combined with <tt>--op</tt> from the
78
+ # options for a full path.
79
+
80
+ attr_reader :base_dir
81
+
71
82
  ##
72
83
  # Initialize a few instance variables before we start
73
84
 
@@ -80,7 +91,9 @@ class RDoc::Generator::Darkfish
80
91
  @files = nil
81
92
  @classes = nil
82
93
 
83
- @basedir = Pathname.pwd.expand_path
94
+ @base_dir = Pathname.pwd.expand_path
95
+
96
+ @json_index = RDoc::Generator::JsonIndex.new self, options
84
97
  end
85
98
 
86
99
  ##
@@ -149,7 +162,7 @@ class RDoc::Generator::Darkfish
149
162
  # objects containing the extracted information.
150
163
 
151
164
  def generate top_levels
152
- @outputdir = Pathname.new(@options.op_dir).expand_path(@basedir)
165
+ @outputdir = Pathname.new(@options.op_dir).expand_path(@base_dir)
153
166
 
154
167
  @files = top_levels.sort
155
168
  @classes = RDoc::TopLevel.all_classes_and_modules.sort
@@ -161,6 +174,8 @@ class RDoc::Generator::Darkfish
161
174
  generate_index
162
175
  generate_class_files
163
176
  generate_file_files
177
+ generate_table_of_contents
178
+ @json_index.generate top_levels
164
179
 
165
180
  rescue => e
166
181
  debug_msg "%s: %s\n %s" % [
@@ -205,7 +220,10 @@ class RDoc::Generator::Darkfish
205
220
 
206
221
  debug_msg "Rendering the index page..."
207
222
 
208
- out_file = @basedir + @options.op_dir + 'index.html'
223
+ out_file = @base_dir + @options.op_dir + 'index.html'
224
+ # suppress 1.9.3 warning
225
+ rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
226
+ @title = @options.title
209
227
 
210
228
  render_template template_file, out_file do |io| binding end
211
229
  rescue => e
@@ -217,10 +235,12 @@ class RDoc::Generator::Darkfish
217
235
  end
218
236
 
219
237
  ##
220
- # Generate a documentation file for each class
238
+ # Generate a documentation file for each class and module
221
239
 
222
240
  def generate_class_files
223
- template_file = @template_dir + 'classpage.rhtml'
241
+ template_file = @template_dir + 'class.rhtml'
242
+ template_file = @template_dir + 'classpage.rhtml' unless
243
+ template_file.exist?
224
244
  return unless template_file.exist?
225
245
  debug_msg "Generating class documentation in #{@outputdir}"
226
246
 
@@ -233,6 +253,7 @@ class RDoc::Generator::Darkfish
233
253
  # suppress 1.9.3 warning
234
254
  rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
235
255
  svninfo = svninfo = self.get_svninfo(klass)
256
+ @title = "#{klass.type.capitalize}: #{klass.full_name}"
236
257
 
237
258
  debug_msg " rendering #{out_file}"
238
259
  render_template template_file, out_file do |io| binding end
@@ -249,8 +270,13 @@ class RDoc::Generator::Darkfish
249
270
  # Generate a documentation file for each file
250
271
 
251
272
  def generate_file_files
252
- template_file = @template_dir + 'filepage.rhtml'
253
- return unless template_file.exist?
273
+ page_file = @template_dir + 'page.rhtml'
274
+ fileinfo_file = @template_dir + 'fileinfo.rhtml'
275
+ template_file = @template_dir + 'filepage.rhtml' unless
276
+ page_file.exist? or fileinfo_file.exist?
277
+
278
+ return unless
279
+ page_file.exist? or fileinfo_file.exist? or template_file.exist?
254
280
  debug_msg "Generating file documentation in #{@outputdir}"
255
281
 
256
282
  out_file = nil
@@ -259,9 +285,20 @@ class RDoc::Generator::Darkfish
259
285
  out_file = @outputdir + file.path
260
286
  debug_msg " working on %s (%s)" % [file.full_name, out_file]
261
287
  # suppress 1.9.3 warning
262
- rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
288
+ rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
289
+
290
+ unless template_file then
291
+ if file.text? then
292
+ next unless page_file.exist?
293
+ template_file = page_file
294
+ @title = file.page_name
295
+ else
296
+ next unless fileinfo_file.exist?
297
+ template_file = fileinfo_file
298
+ @title = "File: #{file.base_name} [#{@options.title}]"
299
+ end
300
+ end
263
301
 
264
- debug_msg " rendering #{out_file}"
265
302
  render_template template_file, out_file do |io| binding end
266
303
  end
267
304
  rescue => e
@@ -272,6 +309,29 @@ class RDoc::Generator::Darkfish
272
309
  raise error
273
310
  end
274
311
 
312
+ ##
313
+ # Generate an index page which lists all the classes which are documented.
314
+
315
+ def generate_table_of_contents
316
+ template_file = @template_dir + 'table_of_contents.rhtml'
317
+ return unless template_file.exist?
318
+
319
+ debug_msg "Rendering the Table of Contents..."
320
+
321
+ out_file = @base_dir + @options.op_dir + 'table_of_contents.html'
322
+ # suppress 1.9.3 warning
323
+ rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
324
+ @title = "Table of Contents"
325
+
326
+ render_template template_file, out_file do |io| binding end
327
+ rescue => e
328
+ error = RDoc::Error.new \
329
+ "error generating table_of_contents.html: #{e.message} (#{e.class})"
330
+ error.set_backtrace e.backtrace
331
+
332
+ raise error
333
+ end
334
+
275
335
  ##
276
336
  # Return a string describing the amount of time in the given number of
277
337
  # seconds in terms a human can understand easily.
@@ -324,6 +384,46 @@ class RDoc::Generator::Darkfish
324
384
  }
325
385
  end
326
386
 
387
+ ##
388
+ # Creates a template from its components and the +body_file+.
389
+ #
390
+ # For backwards compatibility, if +body_file+ contains "<html" the body is
391
+ # used directly.
392
+
393
+ def assemble_template body_file
394
+ body = body_file.read
395
+ return body if body =~ /<html/
396
+
397
+ head_file = @template_dir + '_head.rhtml'
398
+ footer_file = @template_dir + '_footer.rhtml'
399
+
400
+ <<-TEMPLATE
401
+ <!DOCTYPE html>
402
+
403
+ <html>
404
+ <head>
405
+ #{head_file.read}
406
+
407
+ #{body}
408
+
409
+ #{footer_file.read}
410
+ TEMPLATE
411
+ end
412
+
413
+ ##
414
+ # Renders the ERb contained in +file_name+ relative to the template
415
+ # directory and returns the result based on the current context.
416
+
417
+ def render file_name
418
+ template_file = @template_dir + file_name
419
+
420
+ template = template_for template_file, false, ERB
421
+
422
+ template.filename = template_file.to_s
423
+
424
+ template.result @context
425
+ end
426
+
327
427
  ##
328
428
  # Load and render the erb template in the given +template_file+ and write
329
429
  # it out to +out_file+.
@@ -342,14 +442,14 @@ class RDoc::Generator::Darkfish
342
442
  out_file.open 'w', 0644 do |io|
343
443
  io.set_encoding @options.encoding if Object.const_defined? :Encoding
344
444
 
345
- context = yield io
445
+ @context = yield io
346
446
 
347
- template_result template, context, template_file
447
+ template_result template, @context, template_file
348
448
  end
349
449
  else
350
- context = yield nil
450
+ @context = yield nil
351
451
 
352
- output = template_result template, context, template_file
452
+ output = template_result template, @context, template_file
353
453
 
354
454
  debug_msg " would have written %d characters to %s" % [
355
455
  output.length, out_file.expand_path
@@ -374,14 +474,20 @@ class RDoc::Generator::Darkfish
374
474
  ##
375
475
  # Retrieves a cache template for +file+, if present, or fills the cache.
376
476
 
377
- def template_for file
477
+ def template_for file, page = true, klass = nil
378
478
  template = @template_cache[file]
379
479
 
380
480
  return template if template
381
481
 
382
- klass = @options.dry_run ? ERB : RDoc::ERBIO
482
+ klass = @options.dry_run ? ERB : RDoc::ERBIO unless klass
483
+
484
+ template = if page then
485
+ assemble_template file
486
+ else
487
+ file.read
488
+ end
383
489
 
384
- template = klass.new file.read, nil, '<>'
490
+ template = klass.new template, nil, '<>'
385
491
  @template_cache[file] = template
386
492
  template
387
493
  end