gitlab-rdoc 6.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.rdoc +220 -0
  3. data/CVE-2013-0256.rdoc +49 -0
  4. data/ExampleMarkdown.md +37 -0
  5. data/ExampleRDoc.rdoc +208 -0
  6. data/Gemfile +12 -0
  7. data/History.rdoc +1666 -0
  8. data/LEGAL.rdoc +50 -0
  9. data/LICENSE.rdoc +57 -0
  10. data/README.rdoc +133 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +101 -0
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/exe/rdoc +44 -0
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +112 -0
  19. data/lib/rdoc/anon_class.rb +11 -0
  20. data/lib/rdoc/any_method.rb +361 -0
  21. data/lib/rdoc/attr.rb +176 -0
  22. data/lib/rdoc/class_module.rb +802 -0
  23. data/lib/rdoc/code_object.rb +421 -0
  24. data/lib/rdoc/code_objects.rb +6 -0
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +187 -0
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +1266 -0
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +136 -0
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +42 -0
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +790 -0
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +160 -0
  37. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  38. data/lib/rdoc/generator/pot/po.rb +84 -0
  39. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  40. data/lib/rdoc/generator/pot.rb +98 -0
  41. data/lib/rdoc/generator/ri.rb +31 -0
  42. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  44. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  58. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  59. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  72. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  73. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  74. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  75. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  76. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  77. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  78. data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  79. data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  80. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  81. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  82. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  83. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  84. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  85. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  86. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  87. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  88. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  89. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  90. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  91. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  92. data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -0
  93. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +84 -0
  94. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  95. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  96. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  97. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  98. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  99. data/lib/rdoc/generator/template/json_index/.document +1 -0
  100. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  101. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  102. data/lib/rdoc/generator.rb +51 -0
  103. data/lib/rdoc/ghost_method.rb +7 -0
  104. data/lib/rdoc/i18n/locale.rb +102 -0
  105. data/lib/rdoc/i18n/text.rb +126 -0
  106. data/lib/rdoc/i18n.rb +10 -0
  107. data/lib/rdoc/include.rb +10 -0
  108. data/lib/rdoc/known_classes.rb +73 -0
  109. data/lib/rdoc/markdown/entities.rb +2132 -0
  110. data/lib/rdoc/markdown/literals.kpeg +23 -0
  111. data/lib/rdoc/markdown/literals.rb +417 -0
  112. data/lib/rdoc/markdown.kpeg +1237 -0
  113. data/lib/rdoc/markdown.rb +16685 -0
  114. data/lib/rdoc/markup/attr_changer.rb +23 -0
  115. data/lib/rdoc/markup/attr_span.rb +36 -0
  116. data/lib/rdoc/markup/attribute_manager.rb +409 -0
  117. data/lib/rdoc/markup/attributes.rb +71 -0
  118. data/lib/rdoc/markup/blank_line.rb +28 -0
  119. data/lib/rdoc/markup/block_quote.rb +15 -0
  120. data/lib/rdoc/markup/document.rb +165 -0
  121. data/lib/rdoc/markup/formatter.rb +266 -0
  122. data/lib/rdoc/markup/hard_break.rb +32 -0
  123. data/lib/rdoc/markup/heading.rb +79 -0
  124. data/lib/rdoc/markup/include.rb +43 -0
  125. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  126. data/lib/rdoc/markup/list.rb +102 -0
  127. data/lib/rdoc/markup/list_item.rb +100 -0
  128. data/lib/rdoc/markup/paragraph.rb +29 -0
  129. data/lib/rdoc/markup/parser.rb +575 -0
  130. data/lib/rdoc/markup/pre_process.rb +296 -0
  131. data/lib/rdoc/markup/raw.rb +70 -0
  132. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  133. data/lib/rdoc/markup/rule.rb +21 -0
  134. data/lib/rdoc/markup/table.rb +47 -0
  135. data/lib/rdoc/markup/to_ansi.rb +94 -0
  136. data/lib/rdoc/markup/to_bs.rb +77 -0
  137. data/lib/rdoc/markup/to_html.rb +444 -0
  138. data/lib/rdoc/markup/to_html_crossref.rb +176 -0
  139. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  140. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  141. data/lib/rdoc/markup/to_label.rb +75 -0
  142. data/lib/rdoc/markup/to_markdown.rb +192 -0
  143. data/lib/rdoc/markup/to_rdoc.rb +362 -0
  144. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  145. data/lib/rdoc/markup/to_test.rb +70 -0
  146. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  147. data/lib/rdoc/markup/verbatim.rb +84 -0
  148. data/lib/rdoc/markup.rb +867 -0
  149. data/lib/rdoc/meta_method.rb +7 -0
  150. data/lib/rdoc/method_attr.rb +419 -0
  151. data/lib/rdoc/mixin.rb +121 -0
  152. data/lib/rdoc/normal_class.rb +93 -0
  153. data/lib/rdoc/normal_module.rb +74 -0
  154. data/lib/rdoc/options.rb +1285 -0
  155. data/lib/rdoc/parser/c.rb +1225 -0
  156. data/lib/rdoc/parser/changelog.rb +335 -0
  157. data/lib/rdoc/parser/markdown.rb +24 -0
  158. data/lib/rdoc/parser/rd.rb +23 -0
  159. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  160. data/lib/rdoc/parser/ruby.rb +2327 -0
  161. data/lib/rdoc/parser/ruby_tools.rb +167 -0
  162. data/lib/rdoc/parser/simple.rb +61 -0
  163. data/lib/rdoc/parser/text.rb +12 -0
  164. data/lib/rdoc/parser.rb +277 -0
  165. data/lib/rdoc/rd/block_parser.rb +1056 -0
  166. data/lib/rdoc/rd/block_parser.ry +639 -0
  167. data/lib/rdoc/rd/inline.rb +72 -0
  168. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  169. data/lib/rdoc/rd/inline_parser.ry +593 -0
  170. data/lib/rdoc/rd.rb +100 -0
  171. data/lib/rdoc/rdoc.rb +579 -0
  172. data/lib/rdoc/require.rb +52 -0
  173. data/lib/rdoc/ri/driver.rb +1572 -0
  174. data/lib/rdoc/ri/formatter.rb +6 -0
  175. data/lib/rdoc/ri/paths.rb +171 -0
  176. data/lib/rdoc/ri/store.rb +7 -0
  177. data/lib/rdoc/ri/task.rb +71 -0
  178. data/lib/rdoc/ri.rb +21 -0
  179. data/lib/rdoc/rubygems_hook.rb +246 -0
  180. data/lib/rdoc/servlet.rb +451 -0
  181. data/lib/rdoc/single_class.rb +26 -0
  182. data/lib/rdoc/stats/normal.rb +58 -0
  183. data/lib/rdoc/stats/quiet.rb +60 -0
  184. data/lib/rdoc/stats/verbose.rb +46 -0
  185. data/lib/rdoc/stats.rb +462 -0
  186. data/lib/rdoc/store.rb +979 -0
  187. data/lib/rdoc/task.rb +329 -0
  188. data/lib/rdoc/text.rb +304 -0
  189. data/lib/rdoc/token_stream.rb +119 -0
  190. data/lib/rdoc/tom_doc.rb +263 -0
  191. data/lib/rdoc/top_level.rb +289 -0
  192. data/lib/rdoc/version.rb +8 -0
  193. data/lib/rdoc.rb +201 -0
  194. data/man/ri.1 +247 -0
  195. data/rdoc.gemspec +249 -0
  196. metadata +279 -0
@@ -0,0 +1,202 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # RDoc::CrossReference is a reusable way to create cross references for names.
4
+
5
+ class RDoc::CrossReference
6
+
7
+ ##
8
+ # Regular expression to match class references
9
+ #
10
+ # 1. There can be a '\\' in front of text to suppress the cross-reference
11
+ # 2. There can be a '::' in front of class names to reference from the
12
+ # top-level namespace.
13
+ # 3. The method can be followed by parenthesis (not recommended)
14
+
15
+ CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'
16
+
17
+ ##
18
+ # Regular expression to match method references.
19
+ #
20
+ # See CLASS_REGEXP_STR
21
+
22
+ METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===|\[\]=?|<<|>>|\+@|-@|-|\+|\*)(?:\([\w.+*/=<>-]*\))?'
23
+
24
+ ##
25
+ # Regular expressions matching text that should potentially have
26
+ # cross-reference links generated are passed to add_regexp_handling. Note
27
+ # that these expressions are meant to pick up text for which cross-references
28
+ # have been suppressed, since the suppression characters are removed by the
29
+ # code that is triggered.
30
+
31
+ CROSSREF_REGEXP = /(?:^|[\s()])
32
+ (
33
+ (?:
34
+ # A::B::C.meth
35
+ #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
36
+
37
+ # Stand-alone method (preceded by a #)
38
+ | \\?\##{METHOD_REGEXP_STR}
39
+
40
+ # Stand-alone method (preceded by ::)
41
+ | ::#{METHOD_REGEXP_STR}
42
+
43
+ # A::B::C
44
+ # The stuff after CLASS_REGEXP_STR is a
45
+ # nasty hack. CLASS_REGEXP_STR unfortunately matches
46
+ # words like dog and cat (these are legal "class"
47
+ # names in Fortran 95). When a word is flagged as a
48
+ # potential cross-reference, limitations in the markup
49
+ # engine suppress other processing, such as typesetting.
50
+ # This is particularly noticeable for contractions.
51
+ # In order that words like "can't" not
52
+ # be flagged as potential cross-references, only
53
+ # flag potential class cross-references if the character
54
+ # after the cross-reference is a space, sentence
55
+ # punctuation, tag start character, or attribute
56
+ # marker.
57
+ | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
58
+
59
+ # Things that look like filenames
60
+ # The key thing is that there must be at least
61
+ # one special character (period, slash, or
62
+ # underscore).
63
+ | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
64
+
65
+ # Things that have markup suppressed
66
+ # Don't process things like '\<' in \<tt>, though.
67
+ # TODO: including < is a hack, not very satisfying.
68
+ | \\[^\s<]
69
+ )
70
+
71
+ # labels for headings
72
+ (?:@[\w+%-]+(?:\.[\w|%-]+)?)?
73
+ )/x
74
+
75
+ ##
76
+ # Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.
77
+
78
+ ALL_CROSSREF_REGEXP = /
79
+ (?:^|[\s()])
80
+ (
81
+ (?:
82
+ # A::B::C.meth
83
+ #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
84
+
85
+ # Stand-alone method
86
+ | \\?#{METHOD_REGEXP_STR}
87
+
88
+ # A::B::C
89
+ | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
90
+
91
+ # Things that look like filenames
92
+ | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
93
+
94
+ # Things that have markup suppressed
95
+ | \\[^\s<]
96
+ )
97
+
98
+ # labels for headings
99
+ (?:@[\w+%-]+)?
100
+ )/x
101
+
102
+ ##
103
+ # Hash of references that have been looked-up to their replacements
104
+
105
+ attr_accessor :seen
106
+
107
+ ##
108
+ # Allows cross-references to be created based on the given +context+
109
+ # (RDoc::Context).
110
+
111
+ def initialize context
112
+ @context = context
113
+ @store = context.store
114
+
115
+ @seen = {}
116
+ end
117
+
118
+ ##
119
+ # Returns a reference to +name+.
120
+ #
121
+ # If the reference is found and +name+ is not documented +text+ will be
122
+ # returned. If +name+ is escaped +name+ is returned. If +name+ is not
123
+ # found +text+ is returned.
124
+
125
+ def resolve name, text
126
+ return @seen[name] if @seen.include? name
127
+
128
+ if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
129
+ type = $2
130
+ if '.' == type # will find either #method or ::method
131
+ method = $3
132
+ else
133
+ method = "#{type}#{$3}"
134
+ end
135
+ container = @context.find_symbol_module($1)
136
+ elsif /^([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
137
+ type = $1
138
+ if '.' == type
139
+ method = $2
140
+ else
141
+ method = "#{type}#{$2}"
142
+ end
143
+ container = @context
144
+ else
145
+ type = nil
146
+ container = nil
147
+ end
148
+
149
+ if container then
150
+ unless RDoc::TopLevel === container then
151
+ if '.' == type then
152
+ if 'new' == method then # AnyClassName.new will be class method
153
+ ref = container.find_local_symbol method
154
+ ref = container.find_ancestor_local_symbol method unless ref
155
+ else
156
+ ref = container.find_local_symbol "::#{method}"
157
+ ref = container.find_ancestor_local_symbol "::#{method}" unless ref
158
+ ref = container.find_local_symbol "##{method}" unless ref
159
+ ref = container.find_ancestor_local_symbol "##{method}" unless ref
160
+ end
161
+ else
162
+ ref = container.find_local_symbol method
163
+ ref = container.find_ancestor_local_symbol method unless ref
164
+ end
165
+ end
166
+ end
167
+
168
+ ref = case name
169
+ when /^\\(#{CLASS_REGEXP_STR})$/o then
170
+ @context.find_symbol $1
171
+ else
172
+ @context.find_symbol name
173
+ end unless ref
174
+
175
+ # Try a page name
176
+ ref = @store.page name if not ref and name =~ /^[\w.]+$/
177
+
178
+ ref = nil if RDoc::Alias === ref # external alias, can't link to it
179
+
180
+ out = if name == '\\' then
181
+ name
182
+ elsif name =~ /^\\/ then
183
+ # we remove the \ only in front of what we know:
184
+ # other backslashes are treated later, only outside of <tt>
185
+ ref ? $' : name
186
+ elsif ref then
187
+ if ref.display? then
188
+ ref
189
+ else
190
+ text
191
+ end
192
+ else
193
+ text
194
+ end
195
+
196
+ @seen[name] = out
197
+
198
+ out
199
+ end
200
+
201
+ end
202
+
@@ -0,0 +1,136 @@
1
+ # coding: US-ASCII
2
+ # frozen_string_literal: true
3
+
4
+ ##
5
+ # This class is a wrapper around File IO and Encoding that helps RDoc load
6
+ # files and convert them to the correct encoding.
7
+
8
+ module RDoc::Encoding
9
+
10
+ HEADER_REGEXP = /^
11
+ (?:
12
+ \A\#!.*\n
13
+ |
14
+ ^\#\s+frozen[-_]string[-_]literal[=:].+\n
15
+ |
16
+ ^\#[^\n]+\b(?:en)?coding[=:]\s*(?<name>[^\s;]+).*\n
17
+ |
18
+ <\?xml[^?]*encoding=(?<quote>["'])(?<name>.*?)\k<quote>.*\n
19
+ )+
20
+ /xi # :nodoc:
21
+
22
+ ##
23
+ # Reads the contents of +filename+ and handles any encoding directives in
24
+ # the file.
25
+ #
26
+ # The content will be converted to the +encoding+. If the file cannot be
27
+ # converted a warning will be printed and nil will be returned.
28
+ #
29
+ # If +force_transcode+ is true the document will be transcoded and any
30
+ # unknown character in the target encoding will be replaced with '?'
31
+
32
+ def self.read_file filename, encoding, force_transcode = false
33
+ content = File.open filename, "rb" do |f| f.read end
34
+ content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/
35
+
36
+ utf8 = content.sub!(/\A\xef\xbb\xbf/, '')
37
+
38
+ enc = RDoc::Encoding.detect_encoding content
39
+ content = RDoc::Encoding.change_encoding content, enc if enc
40
+
41
+ begin
42
+ encoding ||= Encoding.default_external
43
+ orig_encoding = content.encoding
44
+
45
+ if not orig_encoding.ascii_compatible? then
46
+ content = content.encode encoding
47
+ elsif utf8 then
48
+ content = RDoc::Encoding.change_encoding content, Encoding::UTF_8
49
+ content = content.encode encoding
50
+ else
51
+ # assume the content is in our output encoding
52
+ content = RDoc::Encoding.change_encoding content, encoding
53
+ end
54
+
55
+ unless content.valid_encoding? then
56
+ # revert and try to transcode
57
+ content = RDoc::Encoding.change_encoding content, orig_encoding
58
+ content = content.encode encoding
59
+ end
60
+
61
+ unless content.valid_encoding? then
62
+ warn "unable to convert #{filename} to #{encoding}, skipping"
63
+ content = nil
64
+ end
65
+ rescue Encoding::InvalidByteSequenceError,
66
+ Encoding::UndefinedConversionError => e
67
+ if force_transcode then
68
+ content = RDoc::Encoding.change_encoding content, orig_encoding
69
+ content = content.encode(encoding,
70
+ :invalid => :replace,
71
+ :undef => :replace,
72
+ :replace => '?')
73
+ return content
74
+ else
75
+ warn "unable to convert #{e.message} for #{filename}, skipping"
76
+ return nil
77
+ end
78
+ end
79
+
80
+ content
81
+ rescue ArgumentError => e
82
+ raise unless e.message =~ /unknown encoding name - (.*)/
83
+ warn "unknown encoding name \"#{$1}\" for #{filename}, skipping"
84
+ nil
85
+ rescue Errno::EISDIR, Errno::ENOENT
86
+ nil
87
+ end
88
+
89
+ def self.remove_frozen_string_literal string
90
+ string =~ /\A(?:#!.*\n)?(.*\n)/
91
+ first_line = $1
92
+
93
+ if first_line =~ /\A# +frozen[-_]string[-_]literal[=:].+$/i
94
+ string = string.sub first_line, ''
95
+ end
96
+
97
+ string
98
+ end
99
+
100
+ ##
101
+ # Detects the encoding of +string+ based on the magic comment
102
+
103
+ def self.detect_encoding string
104
+ result = HEADER_REGEXP.match string
105
+ name = result && result[:name]
106
+
107
+ name ? Encoding.find(name) : nil
108
+ end
109
+
110
+ ##
111
+ # Removes magic comments and shebang
112
+
113
+ def self.remove_magic_comment string
114
+ string.sub HEADER_REGEXP do |s|
115
+ s.gsub(/[^\n]/, '')
116
+ end
117
+ end
118
+
119
+ ##
120
+ # Changes encoding based on +encoding+ without converting and returns new
121
+ # string
122
+
123
+ def self.change_encoding text, encoding
124
+ if text.kind_of? RDoc::Comment
125
+ text.encode! encoding
126
+ else
127
+ # TODO: Remove this condition after Ruby 2.2 EOL
128
+ if RUBY_VERSION < '2.3.0'
129
+ text.force_encoding encoding
130
+ else
131
+ String.new text, encoding: encoding
132
+ end
133
+ end
134
+ end
135
+
136
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # Allows an ERB template to be rendered in the context (binding) of an
4
+ # existing ERB template evaluation.
5
+
6
+ class RDoc::ERBPartial < ERB
7
+
8
+ ##
9
+ # Overrides +compiler+ startup to set the +eoutvar+ to an empty string only
10
+ # if it isn't already set.
11
+
12
+ def set_eoutvar compiler, eoutvar = '_erbout'
13
+ super
14
+
15
+ compiler.pre_cmd = ["#{eoutvar} ||= +''"]
16
+ end
17
+
18
+ end
19
+
data/lib/rdoc/erbio.rb ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ require 'erb'
3
+
4
+ ##
5
+ # A subclass of ERB that writes directly to an IO. Credit to Aaron Patterson
6
+ # and Masatoshi SEKI.
7
+ #
8
+ # To use:
9
+ #
10
+ # erbio = RDoc::ERBIO.new '<%= "hello world" %>', nil, nil
11
+ #
12
+ # File.open 'hello.txt', 'w' do |io|
13
+ # erbio.result binding
14
+ # end
15
+ #
16
+ # Note that binding must enclose the io you wish to output on.
17
+
18
+ class RDoc::ERBIO < ERB
19
+
20
+ ##
21
+ # Defaults +eoutvar+ to 'io', otherwise is identical to ERB's initialize
22
+
23
+ def initialize str, safe_level = nil, legacy_trim_mode = nil, legacy_eoutvar = 'io', trim_mode: nil, eoutvar: 'io'
24
+ if RUBY_VERSION >= '2.6'
25
+ super(str, trim_mode: trim_mode, eoutvar: eoutvar)
26
+ else
27
+ super(str, safe_level, legacy_trim_mode, legacy_eoutvar)
28
+ end
29
+ end
30
+
31
+ ##
32
+ # Instructs +compiler+ how to write to +io_variable+
33
+
34
+ def set_eoutvar compiler, io_variable
35
+ compiler.put_cmd = "#{io_variable}.write"
36
+ compiler.insert_cmd = "#{io_variable}.write"
37
+ compiler.pre_cmd = []
38
+ compiler.post_cmd = []
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # A Module extension to a class with \#extend
4
+ #
5
+ # RDoc::Extend.new 'Enumerable', 'comment ...'
6
+
7
+ class RDoc::Extend < RDoc::Mixin
8
+
9
+ end
10
+
@@ -0,0 +1,790 @@
1
+ # frozen_string_literal: true
2
+ # -*- mode: ruby; ruby-indent-level: 2; tab-width: 2 -*-
3
+
4
+ require 'erb'
5
+ require 'fileutils'
6
+ require 'pathname'
7
+ require_relative 'markup'
8
+
9
+ ##
10
+ # Darkfish RDoc HTML Generator
11
+ #
12
+ # $Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
13
+ #
14
+ # == Author/s
15
+ # * Michael Granger (ged@FaerieMUD.org)
16
+ #
17
+ # == Contributors
18
+ # * Mahlon E. Smith (mahlon@martini.nu)
19
+ # * Eric Hodel (drbrain@segment7.net)
20
+ #
21
+ # == License
22
+ #
23
+ # Copyright (c) 2007, 2008, Michael Granger. All rights reserved.
24
+ #
25
+ # Redistribution and use in source and binary forms, with or without
26
+ # modification, are permitted provided that the following conditions are met:
27
+ #
28
+ # * Redistributions of source code must retain the above copyright notice,
29
+ # this list of conditions and the following disclaimer.
30
+ #
31
+ # * Redistributions in binary form must reproduce the above copyright notice,
32
+ # this list of conditions and the following disclaimer in the documentation
33
+ # and/or other materials provided with the distribution.
34
+ #
35
+ # * Neither the name of the author/s, nor the names of the project's
36
+ # contributors may be used to endorse or promote products derived from this
37
+ # software without specific prior written permission.
38
+ #
39
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
43
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
+ #
50
+ # == Attributions
51
+ #
52
+ # Darkfish uses the {Silk Icons}[http://www.famfamfam.com/lab/icons/silk/] set
53
+ # by Mark James.
54
+
55
+ class RDoc::Generator::Darkfish
56
+
57
+ RDoc::RDoc.add_generator self
58
+
59
+ include ERB::Util
60
+
61
+ ##
62
+ # Stylesheets, fonts, etc. that are included in RDoc.
63
+
64
+ BUILTIN_STYLE_ITEMS = # :nodoc:
65
+ %w[
66
+ css/fonts.css
67
+ fonts/Lato-Light.ttf
68
+ fonts/Lato-LightItalic.ttf
69
+ fonts/Lato-Regular.ttf
70
+ fonts/Lato-RegularItalic.ttf
71
+ fonts/SourceCodePro-Bold.ttf
72
+ fonts/SourceCodePro-Regular.ttf
73
+ css/rdoc.css
74
+ ]
75
+
76
+ ##
77
+ # Path to this file's parent directory. Used to find templates and other
78
+ # resources.
79
+
80
+ GENERATOR_DIR = File.join 'rdoc', 'generator'
81
+
82
+ ##
83
+ # Release Version
84
+
85
+ VERSION = '3'
86
+
87
+ ##
88
+ # Description of this generator
89
+
90
+ DESCRIPTION = 'HTML generator, written by Michael Granger'
91
+
92
+ ##
93
+ # The relative path to style sheets and javascript. By default this is set
94
+ # the same as the rel_prefix.
95
+
96
+ attr_accessor :asset_rel_path
97
+
98
+ ##
99
+ # The path to generate files into, combined with <tt>--op</tt> from the
100
+ # options for a full path.
101
+
102
+ attr_reader :base_dir
103
+
104
+ ##
105
+ # Classes and modules to be used by this generator, not necessarily
106
+ # displayed. See also #modsort
107
+
108
+ attr_reader :classes
109
+
110
+ ##
111
+ # No files will be written when dry_run is true.
112
+
113
+ attr_accessor :dry_run
114
+
115
+ ##
116
+ # When false the generate methods return a String instead of writing to a
117
+ # file. The default is true.
118
+
119
+ attr_accessor :file_output
120
+
121
+ ##
122
+ # Files to be displayed by this generator
123
+
124
+ attr_reader :files
125
+
126
+ ##
127
+ # The JSON index generator for this Darkfish generator
128
+
129
+ attr_reader :json_index
130
+
131
+ ##
132
+ # Methods to be displayed by this generator
133
+
134
+ attr_reader :methods
135
+
136
+ ##
137
+ # Sorted list of classes and modules to be displayed by this generator
138
+
139
+ attr_reader :modsort
140
+
141
+ ##
142
+ # The RDoc::Store that is the source of the generated content
143
+
144
+ attr_reader :store
145
+
146
+ ##
147
+ # The directory where the template files live
148
+
149
+ attr_reader :template_dir # :nodoc:
150
+
151
+ ##
152
+ # The output directory
153
+
154
+ attr_reader :outputdir
155
+
156
+ ##
157
+ # Initialize a few instance variables before we start
158
+
159
+ def initialize store, options
160
+ @store = store
161
+ @options = options
162
+
163
+ @asset_rel_path = ''
164
+ @base_dir = Pathname.pwd.expand_path
165
+ @dry_run = @options.dry_run
166
+ @file_output = true
167
+ @template_dir = Pathname.new options.template_dir
168
+ @template_cache = {}
169
+
170
+ @classes = nil
171
+ @context = nil
172
+ @files = nil
173
+ @methods = nil
174
+ @modsort = nil
175
+
176
+ @json_index = RDoc::Generator::JsonIndex.new self, options
177
+ end
178
+
179
+ ##
180
+ # Output progress information if debugging is enabled
181
+
182
+ def debug_msg *msg
183
+ return unless $DEBUG_RDOC
184
+ $stderr.puts(*msg)
185
+ end
186
+
187
+ ##
188
+ # Directory where generated class HTML files live relative to the output
189
+ # dir.
190
+
191
+ def class_dir
192
+ nil
193
+ end
194
+
195
+ ##
196
+ # Directory where generated class HTML files live relative to the output
197
+ # dir.
198
+
199
+ def file_dir
200
+ nil
201
+ end
202
+
203
+ ##
204
+ # Create the directories the generated docs will live in if they don't
205
+ # already exist.
206
+
207
+ def gen_sub_directories
208
+ @outputdir.mkpath
209
+ end
210
+
211
+ ##
212
+ # Copy over the stylesheet into the appropriate place in the output
213
+ # directory.
214
+
215
+ def write_style_sheet
216
+ debug_msg "Copying static files"
217
+ options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
218
+
219
+ BUILTIN_STYLE_ITEMS.each do |item|
220
+ install_rdoc_static_file @template_dir + item, "./#{item}", options
221
+ end
222
+
223
+ @options.template_stylesheets.each do |stylesheet|
224
+ FileUtils.cp stylesheet, '.', options
225
+ end
226
+
227
+ Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
228
+ next if File.directory? path
229
+ next if File.basename(path) =~ /^\./
230
+
231
+ dst = Pathname.new(path).relative_path_from @template_dir
232
+
233
+ install_rdoc_static_file @template_dir + path, dst, options
234
+ end
235
+ end
236
+
237
+ ##
238
+ # Build the initial indices and output objects based on an array of TopLevel
239
+ # objects containing the extracted information.
240
+
241
+ def generate
242
+ setup
243
+
244
+ write_style_sheet
245
+ generate_index
246
+ generate_class_files
247
+ generate_file_files
248
+ generate_table_of_contents
249
+ @json_index.generate
250
+ @json_index.generate_gzipped
251
+
252
+ copy_static
253
+
254
+ rescue => e
255
+ debug_msg "%s: %s\n %s" % [
256
+ e.class.name, e.message, e.backtrace.join("\n ")
257
+ ]
258
+
259
+ raise
260
+ end
261
+
262
+ ##
263
+ # Copies static files from the static_path into the output directory
264
+
265
+ def copy_static
266
+ return if @options.static_path.empty?
267
+
268
+ fu_options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
269
+
270
+ @options.static_path.each do |path|
271
+ unless File.directory? path then
272
+ FileUtils.install path, @outputdir, **fu_options.merge(:mode => 0644)
273
+ next
274
+ end
275
+
276
+ Dir.chdir path do
277
+ Dir[File.join('**', '*')].each do |entry|
278
+ dest_file = @outputdir + entry
279
+
280
+ if File.directory? entry then
281
+ FileUtils.mkdir_p entry, **fu_options
282
+ else
283
+ FileUtils.install entry, dest_file, **fu_options.merge(:mode => 0644)
284
+ end
285
+ end
286
+ end
287
+ end
288
+ end
289
+
290
+ ##
291
+ # Return a list of the documented modules sorted by salience first, then
292
+ # by name.
293
+
294
+ def get_sorted_module_list classes
295
+ classes.select do |klass|
296
+ klass.display?
297
+ end.sort
298
+ end
299
+
300
+ ##
301
+ # Generate an index page which lists all the classes which are documented.
302
+
303
+ def generate_index
304
+ setup
305
+
306
+ template_file = @template_dir + 'index.rhtml'
307
+ return unless template_file.exist?
308
+
309
+ debug_msg "Rendering the index page..."
310
+
311
+ out_file = @base_dir + @options.op_dir + 'index.html'
312
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
313
+ search_index_rel_prefix = rel_prefix
314
+ search_index_rel_prefix += @asset_rel_path if @file_output
315
+
316
+ asset_rel_prefix = rel_prefix + @asset_rel_path
317
+
318
+ @title = @options.title
319
+
320
+ render_template template_file, out_file do |io|
321
+ here = binding
322
+ # suppress 1.9.3 warning
323
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
324
+ here
325
+ end
326
+ rescue => e
327
+ error = RDoc::Error.new \
328
+ "error generating index.html: #{e.message} (#{e.class})"
329
+ error.set_backtrace e.backtrace
330
+
331
+ raise error
332
+ end
333
+
334
+ ##
335
+ # Generates a class file for +klass+
336
+
337
+ def generate_class klass, template_file = nil
338
+ setup
339
+
340
+ current = klass
341
+
342
+ template_file ||= @template_dir + 'class.rhtml'
343
+
344
+ debug_msg " working on %s (%s)" % [klass.full_name, klass.path]
345
+ out_file = @outputdir + klass.path
346
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
347
+ search_index_rel_prefix = rel_prefix
348
+ search_index_rel_prefix += @asset_rel_path if @file_output
349
+
350
+ asset_rel_prefix = rel_prefix + @asset_rel_path
351
+ svninfo = get_svninfo(current)
352
+
353
+ @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
354
+
355
+ debug_msg " rendering #{out_file}"
356
+ render_template template_file, out_file do |io|
357
+ here = binding
358
+ # suppress 1.9.3 warning
359
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
360
+ here.local_variable_set(:svninfo, svninfo)
361
+ here
362
+ end
363
+ end
364
+
365
+ ##
366
+ # Generate a documentation file for each class and module
367
+
368
+ def generate_class_files
369
+ setup
370
+
371
+ template_file = @template_dir + 'class.rhtml'
372
+ template_file = @template_dir + 'classpage.rhtml' unless
373
+ template_file.exist?
374
+ return unless template_file.exist?
375
+ debug_msg "Generating class documentation in #{@outputdir}"
376
+
377
+ current = nil
378
+
379
+ @classes.each do |klass|
380
+ current = klass
381
+
382
+ generate_class klass, template_file
383
+ end
384
+ rescue => e
385
+ error = RDoc::Error.new \
386
+ "error generating #{current.path}: #{e.message} (#{e.class})"
387
+ error.set_backtrace e.backtrace
388
+
389
+ raise error
390
+ end
391
+
392
+ ##
393
+ # Generate a documentation file for each file
394
+
395
+ def generate_file_files
396
+ setup
397
+
398
+ page_file = @template_dir + 'page.rhtml'
399
+ fileinfo_file = @template_dir + 'fileinfo.rhtml'
400
+
401
+ # for legacy templates
402
+ filepage_file = @template_dir + 'filepage.rhtml' unless
403
+ page_file.exist? or fileinfo_file.exist?
404
+
405
+ return unless
406
+ page_file.exist? or fileinfo_file.exist? or filepage_file.exist?
407
+
408
+ debug_msg "Generating file documentation in #{@outputdir}"
409
+
410
+ out_file = nil
411
+ current = nil
412
+
413
+ @files.each do |file|
414
+ current = file
415
+
416
+ if file.text? and page_file.exist? then
417
+ generate_page file
418
+ next
419
+ end
420
+
421
+ template_file = nil
422
+ out_file = @outputdir + file.path
423
+ debug_msg " working on %s (%s)" % [file.full_name, out_file]
424
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
425
+ search_index_rel_prefix = rel_prefix
426
+ search_index_rel_prefix += @asset_rel_path if @file_output
427
+
428
+ asset_rel_prefix = rel_prefix + @asset_rel_path
429
+
430
+ unless filepage_file then
431
+ if file.text? then
432
+ next unless page_file.exist?
433
+ template_file = page_file
434
+ @title = file.page_name
435
+ else
436
+ next unless fileinfo_file.exist?
437
+ template_file = fileinfo_file
438
+ @title = "File: #{file.base_name}"
439
+ end
440
+ end
441
+
442
+ @title += " - #{@options.title}"
443
+ template_file ||= filepage_file
444
+
445
+ render_template template_file, out_file do |io|
446
+ here = binding
447
+ # suppress 1.9.3 warning
448
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
449
+ here.local_variable_set(:current, current)
450
+ here
451
+ end
452
+ end
453
+ rescue => e
454
+ error =
455
+ RDoc::Error.new "error generating #{out_file}: #{e.message} (#{e.class})"
456
+ error.set_backtrace e.backtrace
457
+
458
+ raise error
459
+ end
460
+
461
+ ##
462
+ # Generate a page file for +file+
463
+
464
+ def generate_page file
465
+ setup
466
+
467
+ template_file = @template_dir + 'page.rhtml'
468
+
469
+ out_file = @outputdir + file.path
470
+ debug_msg " working on %s (%s)" % [file.full_name, out_file]
471
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
472
+ search_index_rel_prefix = rel_prefix
473
+ search_index_rel_prefix += @asset_rel_path if @file_output
474
+
475
+ current = file
476
+ asset_rel_prefix = rel_prefix + @asset_rel_path
477
+
478
+ @title = "#{file.page_name} - #{@options.title}"
479
+
480
+ debug_msg " rendering #{out_file}"
481
+ render_template template_file, out_file do |io|
482
+ here = binding
483
+ # suppress 1.9.3 warning
484
+ here.local_variable_set(:current, current)
485
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
486
+ here
487
+ end
488
+ end
489
+
490
+ ##
491
+ # Generates the 404 page for the RDoc servlet
492
+
493
+ def generate_servlet_not_found message
494
+ setup
495
+
496
+ template_file = @template_dir + 'servlet_not_found.rhtml'
497
+ return unless template_file.exist?
498
+
499
+ debug_msg "Rendering the servlet 404 Not Found page..."
500
+
501
+ rel_prefix = rel_prefix = ''
502
+ search_index_rel_prefix = rel_prefix
503
+ search_index_rel_prefix += @asset_rel_path if @file_output
504
+
505
+ asset_rel_prefix = ''
506
+
507
+ @title = 'Not Found'
508
+
509
+ render_template template_file do |io|
510
+ here = binding
511
+ # suppress 1.9.3 warning
512
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
513
+ here
514
+ end
515
+ rescue => e
516
+ error = RDoc::Error.new \
517
+ "error generating servlet_not_found: #{e.message} (#{e.class})"
518
+ error.set_backtrace e.backtrace
519
+
520
+ raise error
521
+ end
522
+
523
+ ##
524
+ # Generates the servlet root page for the RDoc servlet
525
+
526
+ def generate_servlet_root installed
527
+ setup
528
+
529
+ template_file = @template_dir + 'servlet_root.rhtml'
530
+ return unless template_file.exist?
531
+
532
+ debug_msg 'Rendering the servlet root page...'
533
+
534
+ rel_prefix = '.'
535
+ asset_rel_prefix = rel_prefix
536
+ search_index_rel_prefix = asset_rel_prefix
537
+ search_index_rel_prefix += @asset_rel_path if @file_output
538
+
539
+ @title = 'Local RDoc Documentation'
540
+
541
+ render_template template_file do |io| binding end
542
+ rescue => e
543
+ error = RDoc::Error.new \
544
+ "error generating servlet_root: #{e.message} (#{e.class})"
545
+ error.set_backtrace e.backtrace
546
+
547
+ raise error
548
+ end
549
+
550
+ ##
551
+ # Generate an index page which lists all the classes which are documented.
552
+
553
+ def generate_table_of_contents
554
+ setup
555
+
556
+ template_file = @template_dir + 'table_of_contents.rhtml'
557
+ return unless template_file.exist?
558
+
559
+ debug_msg "Rendering the Table of Contents..."
560
+
561
+ out_file = @outputdir + 'table_of_contents.html'
562
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
563
+ search_index_rel_prefix = rel_prefix
564
+ search_index_rel_prefix += @asset_rel_path if @file_output
565
+
566
+ asset_rel_prefix = rel_prefix + @asset_rel_path
567
+
568
+ @title = "Table of Contents - #{@options.title}"
569
+
570
+ render_template template_file, out_file do |io|
571
+ here = binding
572
+ # suppress 1.9.3 warning
573
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
574
+ here
575
+ end
576
+ rescue => e
577
+ error = RDoc::Error.new \
578
+ "error generating table_of_contents.html: #{e.message} (#{e.class})"
579
+ error.set_backtrace e.backtrace
580
+
581
+ raise error
582
+ end
583
+
584
+ def install_rdoc_static_file source, destination, options # :nodoc:
585
+ return unless source.exist?
586
+
587
+ begin
588
+ FileUtils.mkdir_p File.dirname(destination), **options
589
+
590
+ begin
591
+ FileUtils.ln source, destination, **options
592
+ rescue Errno::EEXIST
593
+ FileUtils.rm destination
594
+ retry
595
+ end
596
+ rescue
597
+ FileUtils.cp source, destination, **options
598
+ end
599
+ end
600
+
601
+ ##
602
+ # Prepares for generation of output from the current directory
603
+
604
+ def setup
605
+ return if instance_variable_defined? :@outputdir
606
+
607
+ @outputdir = Pathname.new(@options.op_dir).expand_path @base_dir
608
+
609
+ return unless @store
610
+
611
+ @classes = @store.all_classes_and_modules.sort
612
+ @files = @store.all_files.sort
613
+ @methods = @classes.map { |m| m.method_list }.flatten.sort
614
+ @modsort = get_sorted_module_list @classes
615
+ end
616
+
617
+ ##
618
+ # Return a string describing the amount of time in the given number of
619
+ # seconds in terms a human can understand easily.
620
+
621
+ def time_delta_string seconds
622
+ return 'less than a minute' if seconds < 60
623
+ return "#{seconds / 60} minute#{seconds / 60 == 1 ? '' : 's'}" if
624
+ seconds < 3000 # 50 minutes
625
+ return 'about one hour' if seconds < 5400 # 90 minutes
626
+ return "#{seconds / 3600} hours" if seconds < 64800 # 18 hours
627
+ return 'one day' if seconds < 86400 # 1 day
628
+ return 'about one day' if seconds < 172800 # 2 days
629
+ return "#{seconds / 86400} days" if seconds < 604800 # 1 week
630
+ return 'about one week' if seconds < 1209600 # 2 week
631
+ return "#{seconds / 604800} weeks" if seconds < 7257600 # 3 months
632
+ return "#{seconds / 2419200} months" if seconds < 31536000 # 1 year
633
+ return "#{seconds / 31536000} years"
634
+ end
635
+
636
+ # %q$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $"
637
+ SVNID_PATTERN = /
638
+ \$Id:\s
639
+ (\S+)\s # filename
640
+ (\d+)\s # rev
641
+ (\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD)
642
+ (\d{2}:\d{2}:\d{2}Z)\s # Time (HH:MM:SSZ)
643
+ (\w+)\s # committer
644
+ \$$
645
+ /x
646
+
647
+ ##
648
+ # Try to extract Subversion information out of the first constant whose
649
+ # value looks like a subversion Id tag. If no matching constant is found,
650
+ # and empty hash is returned.
651
+
652
+ def get_svninfo klass
653
+ constants = klass.constants or return {}
654
+
655
+ constants.find { |c| c.value =~ SVNID_PATTERN } or return {}
656
+
657
+ filename, rev, date, time, committer = $~.captures
658
+ commitdate = Time.parse "#{date} #{time}"
659
+
660
+ return {
661
+ :filename => filename,
662
+ :rev => Integer(rev),
663
+ :commitdate => commitdate,
664
+ :commitdelta => time_delta_string(Time.now - commitdate),
665
+ :committer => committer,
666
+ }
667
+ end
668
+
669
+ ##
670
+ # Creates a template from its components and the +body_file+.
671
+ #
672
+ # For backwards compatibility, if +body_file+ contains "<html" the body is
673
+ # used directly.
674
+
675
+ def assemble_template body_file
676
+ body = body_file.read
677
+ return body if body =~ /<html/
678
+
679
+ head_file = @template_dir + '_head.rhtml'
680
+ footer_file = @template_dir + '_footer.rhtml'
681
+
682
+ <<-TEMPLATE
683
+ <!DOCTYPE html>
684
+
685
+ <html>
686
+ <head>
687
+ #{head_file.read}
688
+
689
+ #{body}
690
+
691
+ #{footer_file.read}
692
+ TEMPLATE
693
+ end
694
+
695
+ ##
696
+ # Renders the ERb contained in +file_name+ relative to the template
697
+ # directory and returns the result based on the current context.
698
+
699
+ def render file_name
700
+ template_file = @template_dir + file_name
701
+
702
+ template = template_for template_file, false, RDoc::ERBPartial
703
+
704
+ template.filename = template_file.to_s
705
+
706
+ template.result @context
707
+ end
708
+
709
+ ##
710
+ # Load and render the erb template in the given +template_file+ and write
711
+ # it out to +out_file+.
712
+ #
713
+ # Both +template_file+ and +out_file+ should be Pathname-like objects.
714
+ #
715
+ # An io will be yielded which must be captured by binding in the caller.
716
+
717
+ def render_template template_file, out_file = nil # :yield: io
718
+ io_output = out_file && !@dry_run && @file_output
719
+ erb_klass = io_output ? RDoc::ERBIO : ERB
720
+
721
+ template = template_for template_file, true, erb_klass
722
+
723
+ if io_output then
724
+ debug_msg "Outputting to %s" % [out_file.expand_path]
725
+
726
+ out_file.dirname.mkpath
727
+ out_file.open 'w', 0644 do |io|
728
+ io.set_encoding @options.encoding
729
+
730
+ @context = yield io
731
+
732
+ template_result template, @context, template_file
733
+ end
734
+ else
735
+ @context = yield nil
736
+
737
+ output = template_result template, @context, template_file
738
+
739
+ debug_msg " would have written %d characters to %s" % [
740
+ output.length, out_file.expand_path
741
+ ] if @dry_run
742
+
743
+ output
744
+ end
745
+ end
746
+
747
+ ##
748
+ # Creates the result for +template+ with +context+. If an error is raised a
749
+ # Pathname +template_file+ will indicate the file where the error occurred.
750
+
751
+ def template_result template, context, template_file
752
+ template.filename = template_file.to_s
753
+ template.result context
754
+ rescue NoMethodError => e
755
+ raise RDoc::Error, "Error while evaluating %s: %s" % [
756
+ template_file.expand_path,
757
+ e.message,
758
+ ], e.backtrace
759
+ end
760
+
761
+ ##
762
+ # Retrieves a cache template for +file+, if present, or fills the cache.
763
+
764
+ def template_for file, page = true, klass = ERB
765
+ template = @template_cache[file]
766
+
767
+ return template if template
768
+
769
+ if page then
770
+ template = assemble_template file
771
+ erbout = 'io'
772
+ else
773
+ template = file.read
774
+ template = template.encode @options.encoding
775
+
776
+ file_var = File.basename(file).sub(/\..*/, '')
777
+
778
+ erbout = "_erbout_#{file_var}"
779
+ end
780
+
781
+ if RUBY_VERSION >= '2.6'
782
+ template = klass.new template, trim_mode: '-', eoutvar: erbout
783
+ else
784
+ template = klass.new template, nil, '-', erbout
785
+ end
786
+ @template_cache[file] = template
787
+ template
788
+ end
789
+
790
+ end