rdoc 6.15.1 → 7.0.3
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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +196 -0
- data/History.rdoc +1 -1
- data/LEGAL.rdoc +6 -0
- data/README.md +20 -3
- data/lib/rdoc/code_object/any_method.rb +15 -7
- data/lib/rdoc/code_object/class_module.rb +38 -8
- data/lib/rdoc/code_object/constant.rb +9 -0
- data/lib/rdoc/code_object/method_attr.rb +13 -1
- data/lib/rdoc/code_object/top_level.rb +31 -18
- data/lib/rdoc/comment.rb +190 -8
- data/lib/rdoc/generator/aliki.rb +183 -0
- data/lib/rdoc/generator/darkfish.rb +8 -2
- data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
- data/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
- data/lib/rdoc/generator/template/aliki/_head.rhtml +158 -0
- data/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
- data/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +25 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +25 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
- data/lib/rdoc/generator/template/aliki/class.rhtml +218 -0
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +1943 -0
- data/lib/rdoc/generator/template/aliki/index.rhtml +22 -0
- data/lib/rdoc/generator/template/aliki/js/aliki.js +505 -0
- data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
- data/lib/rdoc/generator/template/aliki/js/search_controller.js +129 -0
- data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
- data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
- data/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
- data/lib/rdoc/generator/template/aliki/page.rhtml +18 -0
- data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
- data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +2 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +1 -0
- data/lib/rdoc/generator/template/darkfish/class.rhtml +9 -11
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +1 -1
- data/lib/rdoc/generator/template/json_index/js/searcher.js +5 -1
- data/lib/rdoc/generator.rb +1 -0
- data/lib/rdoc/markup/blank_line.rb +25 -23
- data/lib/rdoc/markup/element.rb +21 -0
- data/lib/rdoc/markup/hard_break.rb +30 -27
- data/lib/rdoc/markup/heading.rb +96 -79
- data/lib/rdoc/markup/pre_process.rb +34 -10
- data/lib/rdoc/markup/raw.rb +52 -55
- data/lib/rdoc/markup/table.rb +48 -40
- data/lib/rdoc/markup/to_ansi.rb +4 -0
- data/lib/rdoc/markup/to_bs.rb +4 -0
- data/lib/rdoc/markup/to_html.rb +6 -4
- data/lib/rdoc/markup/to_rdoc.rb +11 -3
- data/lib/rdoc/markup.rb +1 -0
- data/lib/rdoc/options.rb +21 -10
- data/lib/rdoc/parser/c.rb +15 -46
- data/lib/rdoc/parser/prism_ruby.rb +121 -113
- data/lib/rdoc/parser/ruby.rb +8 -8
- data/lib/rdoc/parser/ruby_tools.rb +5 -7
- data/lib/rdoc/parser/simple.rb +4 -21
- data/lib/rdoc/rdoc.rb +1 -0
- data/lib/rdoc/rubygems_hook.rb +3 -3
- data/lib/rdoc/text.rb +1 -1
- data/lib/rdoc/token_stream.rb +13 -1
- data/lib/rdoc/tom_doc.rb +1 -1
- data/lib/rdoc/version.rb +1 -1
- data/rdoc.gemspec +1 -1
- metadata +34 -5
- data/CONTRIBUTING.rdoc +0 -219
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# A hard-break in the middle of a paragraph.
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
module RDoc
|
|
4
|
+
class Markup
|
|
5
|
+
# A hard-break in the middle of a paragraph.
|
|
6
|
+
class HardBreak < Element
|
|
7
|
+
@instance = new
|
|
8
|
+
|
|
9
|
+
# RDoc::Markup::HardBreak is a singleton
|
|
10
|
+
#: () -> HardBreak
|
|
11
|
+
def self.new
|
|
12
|
+
@instance
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Calls #accept_hard_break on +visitor+
|
|
16
|
+
# @override
|
|
17
|
+
#: (untyped) -> void
|
|
18
|
+
def accept(visitor)
|
|
19
|
+
visitor.accept_hard_break(self)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
#: (top) -> bool
|
|
23
|
+
def ==(other) # :nodoc:
|
|
24
|
+
self.class === other
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @override
|
|
28
|
+
#: (PP) -> void
|
|
29
|
+
def pretty_print(q) # :nodoc:
|
|
30
|
+
q.text("[break]")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
21
33
|
end
|
|
22
|
-
|
|
23
|
-
def ==(other) # :nodoc:
|
|
24
|
-
self.class === other
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def pretty_print(q) # :nodoc:
|
|
28
|
-
q.text "[break]"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
34
|
end
|
data/lib/rdoc/markup/heading.rb
CHANGED
|
@@ -1,84 +1,101 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# A heading with a level (1-6) and text
|
|
4
2
|
|
|
5
|
-
RDoc
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
3
|
+
module RDoc
|
|
4
|
+
class Markup
|
|
5
|
+
# A heading with a level (1-6) and text
|
|
6
|
+
#
|
|
7
|
+
# RDoc syntax:
|
|
8
|
+
# = Heading 1
|
|
9
|
+
# == Heading 2
|
|
10
|
+
# === Heading 3
|
|
11
|
+
#
|
|
12
|
+
# Markdown syntax:
|
|
13
|
+
# # Heading 1
|
|
14
|
+
# ## Heading 2
|
|
15
|
+
# ### Heading 3
|
|
16
|
+
class Heading < Element
|
|
17
|
+
#: String
|
|
18
|
+
attr_reader :text
|
|
19
|
+
|
|
20
|
+
#: Integer
|
|
21
|
+
attr_accessor :level
|
|
22
|
+
|
|
23
|
+
# A singleton RDoc::Markup::ToLabel formatter for headings.
|
|
24
|
+
#: () -> RDoc::Markup::ToLabel
|
|
25
|
+
def self.to_label
|
|
26
|
+
@to_label ||= Markup::ToLabel.new
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# A singleton plain HTML formatter for headings. Used for creating labels for the Table of Contents
|
|
30
|
+
#: () -> RDoc::Markup::ToHtml
|
|
31
|
+
def self.to_html
|
|
32
|
+
@to_html ||= begin
|
|
33
|
+
markup = Markup.new
|
|
34
|
+
markup.add_regexp_handling CrossReference::CROSSREF_REGEXP, :CROSSREF
|
|
35
|
+
|
|
36
|
+
to_html = Markup::ToHtml.new nil
|
|
37
|
+
|
|
38
|
+
def to_html.handle_regexp_CROSSREF(target)
|
|
39
|
+
target.text.sub(/^\\/, '')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
to_html
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#: (Integer, String) -> void
|
|
47
|
+
def initialize(level, text)
|
|
48
|
+
super()
|
|
49
|
+
|
|
50
|
+
@level = level
|
|
51
|
+
@text = text
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
#: (Object) -> bool
|
|
55
|
+
def ==(other)
|
|
56
|
+
other.is_a?(Heading) && other.level == @level && other.text == @text
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @override
|
|
60
|
+
#: (untyped) -> void
|
|
61
|
+
def accept(visitor)
|
|
62
|
+
visitor.accept_heading(self)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# An HTML-safe anchor reference for this header.
|
|
66
|
+
#: () -> String
|
|
67
|
+
def aref
|
|
68
|
+
"label-#{self.class.to_label.convert text.dup}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Creates a fully-qualified label which will include the label from +context+. This helps keep ids unique in HTML.
|
|
72
|
+
#: (RDoc::Context?) -> String
|
|
73
|
+
def label(context = nil)
|
|
74
|
+
label = +""
|
|
75
|
+
label << "#{context.aref}-" if context&.respond_to?(:aref)
|
|
76
|
+
label << aref
|
|
77
|
+
label
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# HTML markup of the text of this label without the surrounding header element.
|
|
81
|
+
#: () -> String
|
|
82
|
+
def plain_html
|
|
83
|
+
no_image_text = text
|
|
84
|
+
|
|
85
|
+
if matched = no_image_text.match(/rdoc-image:[^:]+:(.*)/)
|
|
86
|
+
no_image_text = matched[1]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
self.class.to_html.to_html(no_image_text)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# @override
|
|
93
|
+
#: (PP) -> void
|
|
94
|
+
def pretty_print(q)
|
|
95
|
+
q.group 2, "[head: #{level} ", ']' do
|
|
96
|
+
q.pp text
|
|
97
|
+
end
|
|
98
|
+
end
|
|
32
99
|
end
|
|
33
|
-
|
|
34
|
-
@to_html
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
##
|
|
38
|
-
# Calls #accept_heading on +visitor+
|
|
39
|
-
|
|
40
|
-
def accept(visitor)
|
|
41
|
-
visitor.accept_heading self
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
##
|
|
45
|
-
# An HTML-safe anchor reference for this header.
|
|
46
|
-
|
|
47
|
-
def aref
|
|
48
|
-
"label-#{self.class.to_label.convert text.dup}"
|
|
49
100
|
end
|
|
50
|
-
|
|
51
|
-
##
|
|
52
|
-
# Creates a fully-qualified label which will include the label from
|
|
53
|
-
# +context+. This helps keep ids unique in HTML.
|
|
54
|
-
|
|
55
|
-
def label(context = nil)
|
|
56
|
-
label = aref
|
|
57
|
-
|
|
58
|
-
label = [context.aref, label].compact.join '-' if
|
|
59
|
-
context and context.respond_to? :aref
|
|
60
|
-
|
|
61
|
-
label
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
##
|
|
65
|
-
# HTML markup of the text of this label without the surrounding header
|
|
66
|
-
# element.
|
|
67
|
-
|
|
68
|
-
def plain_html
|
|
69
|
-
text = self.text.dup
|
|
70
|
-
|
|
71
|
-
if matched = text.match(/rdoc-image:[^:]+:(.*)/)
|
|
72
|
-
text = matched[1]
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
self.class.to_html.to_html(text)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def pretty_print(q) # :nodoc:
|
|
79
|
-
q.group 2, "[head: #{level} ", ']' do
|
|
80
|
-
q.pp text
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
101
|
end
|
|
@@ -97,18 +97,15 @@ class RDoc::Markup::PreProcess
|
|
|
97
97
|
# RDoc::CodeObject#metadata for details.
|
|
98
98
|
|
|
99
99
|
def handle(text, code_object = nil, &block)
|
|
100
|
-
first_line = 1
|
|
101
100
|
if RDoc::Comment === text then
|
|
102
101
|
comment = text
|
|
103
102
|
text = text.text
|
|
104
|
-
first_line = comment.line || 1
|
|
105
103
|
end
|
|
106
104
|
|
|
107
105
|
# regexp helper (square brackets for optional)
|
|
108
106
|
# $1 $2 $3 $4 $5
|
|
109
107
|
# [prefix][\]:directive:[spaces][param]newline
|
|
110
|
-
text = text.
|
|
111
|
-
next line unless line =~ /\A([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):([\w-]+):([ \t]*)(.+)?(\r?\n|$)/
|
|
108
|
+
text = text.gsub(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):([\w-]+):([ \t]*)(.+)?(\r?\n|$)/) do
|
|
112
109
|
# skip something like ':toto::'
|
|
113
110
|
next $& if $4.empty? and $5 and $5[0, 1] == ':'
|
|
114
111
|
|
|
@@ -122,9 +119,8 @@ class RDoc::Markup::PreProcess
|
|
|
122
119
|
comment.format = $5.downcase
|
|
123
120
|
next "#{$1.strip}\n"
|
|
124
121
|
end
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
end.join
|
|
122
|
+
handle_directive $1, $3, $5, code_object, text.encoding, &block
|
|
123
|
+
end
|
|
128
124
|
|
|
129
125
|
if comment then
|
|
130
126
|
comment.text = text
|
|
@@ -132,11 +128,39 @@ class RDoc::Markup::PreProcess
|
|
|
132
128
|
comment = text
|
|
133
129
|
end
|
|
134
130
|
|
|
131
|
+
run_post_processes(comment, code_object)
|
|
132
|
+
|
|
133
|
+
text
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Apply directives to a code object
|
|
137
|
+
|
|
138
|
+
def run_pre_processes(comment_text, code_object, start_line_no, type)
|
|
139
|
+
comment_text, directives = parse_comment(comment_text, start_line_no, type)
|
|
140
|
+
directives.each do |directive, (param, line_no)|
|
|
141
|
+
handle_directive('', directive, param, code_object)
|
|
142
|
+
end
|
|
143
|
+
if code_object.is_a?(RDoc::AnyMethod) && (call_seq, = directives['call-seq']) && call_seq
|
|
144
|
+
code_object.call_seq = call_seq.lines.map(&:chomp).reject(&:empty?).join("\n")
|
|
145
|
+
end
|
|
146
|
+
format, = directives['markup']
|
|
147
|
+
[comment_text, format]
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Perform post preocesses to a code object
|
|
151
|
+
|
|
152
|
+
def run_post_processes(comment, code_object)
|
|
135
153
|
self.class.post_processors.each do |handler|
|
|
136
154
|
handler.call comment, code_object
|
|
137
155
|
end
|
|
156
|
+
end
|
|
138
157
|
|
|
139
|
-
|
|
158
|
+
# Parse comment and return [normalized_comment_text, directives_hash]
|
|
159
|
+
|
|
160
|
+
def parse_comment(text, line_no, type)
|
|
161
|
+
RDoc::Comment.parse(text, @input_file_name, line_no, type) do |filename, prefix_indent|
|
|
162
|
+
include_file(filename, prefix_indent, text.encoding)
|
|
163
|
+
end
|
|
140
164
|
end
|
|
141
165
|
|
|
142
166
|
##
|
|
@@ -151,7 +175,7 @@ class RDoc::Markup::PreProcess
|
|
|
151
175
|
# When 1.8.7 support is ditched prefix can be defaulted to ''
|
|
152
176
|
|
|
153
177
|
def handle_directive(prefix, directive, param, code_object = nil,
|
|
154
|
-
encoding = nil
|
|
178
|
+
encoding = nil)
|
|
155
179
|
blankline = "#{prefix.strip}\n"
|
|
156
180
|
directive = directive.downcase
|
|
157
181
|
|
|
@@ -244,7 +268,7 @@ class RDoc::Markup::PreProcess
|
|
|
244
268
|
|
|
245
269
|
blankline
|
|
246
270
|
else
|
|
247
|
-
result = yield directive, param
|
|
271
|
+
result = yield directive, param if block_given?
|
|
248
272
|
|
|
249
273
|
case result
|
|
250
274
|
when nil then
|
data/lib/rdoc/markup/raw.rb
CHANGED
|
@@ -1,69 +1,66 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# A section of text that is added to the output document as-is
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
##
|
|
21
|
-
# Appends +text+
|
|
3
|
+
module RDoc
|
|
4
|
+
class Markup
|
|
5
|
+
# A section of text that is added to the output document as-is
|
|
6
|
+
class Raw
|
|
7
|
+
# The component parts of the list
|
|
8
|
+
#: Array[String]
|
|
9
|
+
attr_reader :parts
|
|
10
|
+
|
|
11
|
+
# Creates a new Raw containing +parts+
|
|
12
|
+
#: (*String) -> void
|
|
13
|
+
def initialize(*parts)
|
|
14
|
+
@parts = parts
|
|
15
|
+
end
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
# Appends +text+
|
|
18
|
+
#: (String) -> void
|
|
19
|
+
def <<(text)
|
|
20
|
+
@parts << text
|
|
21
|
+
end
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
#: (top) -> bool
|
|
24
|
+
def ==(other) # :nodoc:
|
|
25
|
+
self.class == other.class && @parts == other.parts
|
|
26
|
+
end
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
# Calls #accept_raw+ on +visitor+
|
|
29
|
+
# @override
|
|
30
|
+
#: (untyped) -> void
|
|
31
|
+
def accept(visitor)
|
|
32
|
+
visitor.accept_raw(self)
|
|
33
|
+
end
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# Appends +other+'s parts
|
|
36
|
+
#: (Raw) -> void
|
|
37
|
+
def merge(other)
|
|
38
|
+
@parts.concat(other.parts)
|
|
39
|
+
end
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
# @override
|
|
42
|
+
#: (PP) -> void
|
|
43
|
+
def pretty_print(q) # :nodoc:
|
|
44
|
+
self.class.name =~ /.*::(\w{1,4})/i
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
q.group(2, "[#{$1.downcase}: ", ']') do
|
|
47
|
+
q.seplist(@parts) do |part|
|
|
48
|
+
q.pp(part)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
# Appends +texts+ onto this Paragraph
|
|
54
|
+
#: (*String) -> void
|
|
55
|
+
def push(*texts)
|
|
56
|
+
self.parts.concat(texts)
|
|
57
|
+
end
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
# The raw text
|
|
60
|
+
#: () -> String
|
|
61
|
+
def text
|
|
62
|
+
@parts.join(" ")
|
|
51
63
|
end
|
|
52
64
|
end
|
|
53
65
|
end
|
|
54
|
-
|
|
55
|
-
##
|
|
56
|
-
# Appends +texts+ onto this Paragraph
|
|
57
|
-
|
|
58
|
-
def push *texts
|
|
59
|
-
self.parts.concat texts
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
##
|
|
63
|
-
# The raw text
|
|
64
|
-
|
|
65
|
-
def text
|
|
66
|
-
@parts.join ' '
|
|
67
|
-
end
|
|
68
|
-
|
|
69
66
|
end
|
data/lib/rdoc/markup/table.rb
CHANGED
|
@@ -1,52 +1,60 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# A section of table
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
module RDoc
|
|
4
|
+
class Markup
|
|
5
|
+
# A section of table
|
|
6
|
+
class Table < Element
|
|
7
|
+
# Headers of each column
|
|
8
|
+
#: Array[String]
|
|
9
|
+
attr_accessor :header
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
# Alignments of each column
|
|
12
|
+
#: Array[Symbol?]
|
|
13
|
+
attr_accessor :align
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
# Body texts of each column
|
|
16
|
+
#: Array[String]
|
|
17
|
+
attr_accessor :body
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# :stopdoc:
|
|
21
|
-
def ==(other)
|
|
22
|
-
self.class == other.class and
|
|
23
|
-
@header == other.header and
|
|
24
|
-
@align == other.align and
|
|
25
|
-
@body == other.body
|
|
26
|
-
end
|
|
19
|
+
#: (Array[String], Array[Symbol?], Array[String]) -> void
|
|
20
|
+
def initialize(header, align, body)
|
|
21
|
+
@header, @align, @body = header, align, body
|
|
22
|
+
end
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
#: (Object) -> bool
|
|
25
|
+
def ==(other)
|
|
26
|
+
self.class == other.class && @header == other.header &&
|
|
27
|
+
@align == other.align && @body == other.body
|
|
28
|
+
end
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
q.pp text
|
|
37
|
-
if align
|
|
38
|
-
q.text ":"
|
|
39
|
-
q.breakable
|
|
40
|
-
q.text align.to_s
|
|
41
|
-
end
|
|
42
|
-
end
|
|
30
|
+
# @override
|
|
31
|
+
#: (untyped) -> void
|
|
32
|
+
def accept(visitor)
|
|
33
|
+
visitor.accept_table(@header, @body, @align)
|
|
43
34
|
end
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
|
|
36
|
+
# @override
|
|
37
|
+
#: (untyped) -> String
|
|
38
|
+
def pretty_print(q)
|
|
39
|
+
q.group 2, '[Table: ', ']' do
|
|
40
|
+
q.group 2, '[Head: ', ']' do
|
|
41
|
+
q.seplist @header.zip(@align) do |text, align|
|
|
49
42
|
q.pp text
|
|
43
|
+
if align
|
|
44
|
+
q.text ":"
|
|
45
|
+
q.breakable
|
|
46
|
+
q.text align.to_s
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
q.breakable
|
|
51
|
+
q.group 2, '[Body: ', ']' do
|
|
52
|
+
q.seplist @body do |body|
|
|
53
|
+
q.group 2, '[', ']' do
|
|
54
|
+
q.seplist body do |text|
|
|
55
|
+
q.pp text
|
|
56
|
+
end
|
|
57
|
+
end
|
|
50
58
|
end
|
|
51
59
|
end
|
|
52
60
|
end
|
data/lib/rdoc/markup/to_ansi.rb
CHANGED
data/lib/rdoc/markup/to_bs.rb
CHANGED
data/lib/rdoc/markup/to_html.rb
CHANGED
|
@@ -312,11 +312,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
312
312
|
else
|
|
313
313
|
"\n<h#{level}>"
|
|
314
314
|
end
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
@res <<
|
|
318
|
-
|
|
315
|
+
|
|
316
|
+
if @options.pipe
|
|
317
|
+
@res << to_html(heading.text)
|
|
318
|
+
else
|
|
319
|
+
@res << "<a href=\"##{label}\">#{to_html(heading.text)}</a>"
|
|
319
320
|
end
|
|
321
|
+
|
|
320
322
|
@res << "</h#{level}>\n"
|
|
321
323
|
end
|
|
322
324
|
|
data/lib/rdoc/markup/to_rdoc.rb
CHANGED
|
@@ -250,8 +250,10 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|
|
250
250
|
# Adds +table+ to the output
|
|
251
251
|
|
|
252
252
|
def accept_table(header, body, aligns)
|
|
253
|
+
header = header.map { |h| attributes h }
|
|
254
|
+
body = body.map { |row| row.map { |t| attributes t } }
|
|
253
255
|
widths = header.zip(*body).map do |cols|
|
|
254
|
-
cols.map(
|
|
256
|
+
cols.map { |col| calculate_text_width(col) }.max
|
|
255
257
|
end
|
|
256
258
|
aligns = aligns.map do |a|
|
|
257
259
|
case a
|
|
@@ -264,16 +266,22 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|
|
264
266
|
end
|
|
265
267
|
end
|
|
266
268
|
@res << header.zip(widths, aligns).map do |h, w, a|
|
|
267
|
-
h.
|
|
269
|
+
extra_width = h.size - calculate_text_width(h)
|
|
270
|
+
h.__send__(a, w + extra_width)
|
|
268
271
|
end.join("|").rstrip << "\n"
|
|
269
272
|
@res << widths.map {|w| "-" * w }.join("|") << "\n"
|
|
270
273
|
body.each do |row|
|
|
271
274
|
@res << row.zip(widths, aligns).map do |t, w, a|
|
|
272
|
-
t.
|
|
275
|
+
extra_width = t.size - calculate_text_width(t)
|
|
276
|
+
t.__send__(a, w + extra_width)
|
|
273
277
|
end.join("|").rstrip << "\n"
|
|
274
278
|
end
|
|
275
279
|
end
|
|
276
280
|
|
|
281
|
+
def calculate_text_width(text)
|
|
282
|
+
text.size
|
|
283
|
+
end
|
|
284
|
+
|
|
277
285
|
##
|
|
278
286
|
# Applies attribute-specific markup to +text+ using RDoc::AttributeManager
|
|
279
287
|
|
data/lib/rdoc/markup.rb
CHANGED
|
@@ -210,6 +210,7 @@ https://github.com/ruby/rdoc/issues
|
|
|
210
210
|
autoload :BlankLine, "#{__dir__}/markup/blank_line"
|
|
211
211
|
autoload :BlockQuote, "#{__dir__}/markup/block_quote"
|
|
212
212
|
autoload :Document, "#{__dir__}/markup/document"
|
|
213
|
+
autoload :Element, "#{__dir__}/markup/element"
|
|
213
214
|
autoload :HardBreak, "#{__dir__}/markup/hard_break"
|
|
214
215
|
autoload :Heading, "#{__dir__}/markup/heading"
|
|
215
216
|
autoload :Include, "#{__dir__}/markup/include"
|