rdoc 7.2.0 → 8.1.0
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 +4 -7
- data/LICENSE.rdoc +4 -0
- data/README.md +43 -2
- data/RI.md +75 -75
- data/doc/markup_reference/markdown.md +104 -3
- data/exe/rdoc +2 -2
- data/lib/rdoc/code_object/alias.rb +70 -74
- data/lib/rdoc/code_object/any_method.rb +305 -298
- data/lib/rdoc/code_object/attr.rb +150 -143
- data/lib/rdoc/code_object/class_module.rb +801 -765
- data/lib/rdoc/code_object/constant.rb +178 -150
- data/lib/rdoc/code_object/context/section.rb +133 -160
- data/lib/rdoc/code_object/context.rb +925 -952
- data/lib/rdoc/code_object/extend.rb +7 -5
- data/lib/rdoc/code_object/include.rb +7 -5
- data/lib/rdoc/code_object/method_attr.rb +325 -324
- data/lib/rdoc/code_object/mixin.rb +97 -95
- data/lib/rdoc/code_object/normal_class.rb +77 -78
- data/lib/rdoc/code_object/normal_module.rb +61 -59
- data/lib/rdoc/code_object/require.rb +23 -39
- data/lib/rdoc/code_object/single_class.rb +21 -19
- data/lib/rdoc/code_object/top_level.rb +212 -213
- data/lib/rdoc/code_object.rb +305 -305
- data/lib/rdoc/comment.rb +274 -337
- data/lib/rdoc/cross_reference.rb +194 -212
- data/lib/rdoc/encoding.rb +105 -103
- data/lib/rdoc/erb_partial.rb +13 -11
- data/lib/rdoc/erbio.rb +29 -27
- data/lib/rdoc/generator/aliki.rb +165 -140
- data/lib/rdoc/generator/darkfish.rb +647 -631
- data/lib/rdoc/generator/json_index.rb +233 -229
- data/lib/rdoc/generator/markup.rb +165 -122
- data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
- data/lib/rdoc/generator/pot/po.rb +52 -51
- data/lib/rdoc/generator/pot/po_entry.rb +138 -132
- data/lib/rdoc/generator/pot.rb +85 -81
- data/lib/rdoc/generator/ri.rb +23 -19
- data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
- data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_head.rhtml +11 -11
- data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
- data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
- data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
- data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +2 -2
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
- data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/class.rhtml +56 -46
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +538 -283
- data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/js/aliki.js +80 -102
- data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/class.rhtml +18 -21
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +0 -1
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
- data/lib/rdoc/generator.rb +48 -46
- data/lib/rdoc/i18n/locale.rb +99 -95
- data/lib/rdoc/i18n/text.rb +109 -105
- data/lib/rdoc/i18n.rb +7 -5
- data/lib/rdoc/markdown/byte_runtime.rb +80 -0
- data/lib/rdoc/markdown.kpeg +30 -21
- data/lib/rdoc/markdown.rb +329 -151
- data/lib/rdoc/markup/block_quote.rb +12 -8
- data/lib/rdoc/markup/document.rb +127 -123
- data/lib/rdoc/markup/formatter.rb +215 -221
- data/lib/rdoc/markup/heading.rb +1 -4
- data/lib/rdoc/markup/include.rb +33 -29
- data/lib/rdoc/markup/indented_paragraph.rb +37 -33
- data/lib/rdoc/markup/inline_parser.rb +281 -277
- data/lib/rdoc/markup/list.rb +80 -88
- data/lib/rdoc/markup/list_item.rb +73 -85
- data/lib/rdoc/markup/paragraph.rb +23 -19
- data/lib/rdoc/markup/parser.rb +501 -497
- data/lib/rdoc/markup/pre_process.rb +284 -305
- data/lib/rdoc/markup/raw.rb +2 -2
- data/lib/rdoc/markup/rule.rb +16 -12
- data/lib/rdoc/markup/to_ansi.rb +143 -139
- data/lib/rdoc/markup/to_bs.rb +72 -68
- data/lib/rdoc/markup/to_html.rb +600 -493
- data/lib/rdoc/markup/to_html_crossref.rb +221 -191
- data/lib/rdoc/markup/to_html_snippet.rb +232 -227
- data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
- data/lib/rdoc/markup/to_label.rb +63 -59
- data/lib/rdoc/markup/to_markdown.rb +212 -208
- data/lib/rdoc/markup/to_rdoc.rb +336 -332
- data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
- data/lib/rdoc/markup/to_test.rb +60 -56
- data/lib/rdoc/markup/to_tt_only.rb +83 -86
- data/lib/rdoc/markup/verbatim.rb +62 -58
- data/lib/rdoc/markup.rb +198 -196
- data/lib/rdoc/options.rb +1063 -1076
- data/lib/rdoc/parser/c.rb +1039 -1036
- data/lib/rdoc/parser/changelog.rb +319 -315
- data/lib/rdoc/parser/markdown.rb +17 -13
- data/lib/rdoc/parser/rbs.rb +279 -0
- data/lib/rdoc/parser/rd.rb +17 -13
- data/lib/rdoc/parser/ruby.rb +1231 -2222
- data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
- data/lib/rdoc/parser/simple.rb +31 -27
- data/lib/rdoc/parser/text.rb +12 -8
- data/lib/rdoc/parser.rb +230 -221
- data/lib/rdoc/rbs_helper.rb +186 -0
- data/lib/rdoc/rd/inline.rb +57 -53
- data/lib/rdoc/rd.rb +90 -88
- data/lib/rdoc/rdoc.rb +547 -366
- data/lib/rdoc/ri/driver.rb +1141 -1130
- data/lib/rdoc/ri/formatter.rb +7 -3
- data/lib/rdoc/ri/paths.rb +140 -136
- data/lib/rdoc/ri/servlet.rb +456 -0
- data/lib/rdoc/ri/store.rb +4 -2
- data/lib/rdoc/ri/task.rb +55 -51
- data/lib/rdoc/ri.rb +14 -11
- data/lib/rdoc/rubygems_hook.rb +194 -192
- data/lib/rdoc/server.rb +462 -0
- data/lib/rdoc/stats/normal.rb +46 -42
- data/lib/rdoc/stats/quiet.rb +39 -35
- data/lib/rdoc/stats/verbose.rb +35 -31
- data/lib/rdoc/stats.rb +363 -338
- data/lib/rdoc/store.rb +919 -725
- data/lib/rdoc/task.rb +260 -255
- data/lib/rdoc/text.rb +130 -245
- data/lib/rdoc/token_stream.rb +101 -115
- data/lib/rdoc/tom_doc.rb +203 -201
- data/lib/rdoc/version.rb +1 -1
- data/lib/rdoc.rb +35 -7
- data/lib/rubygems_plugin.rb +2 -11
- data/rdoc-logo.svg +43 -0
- data/rdoc.gemspec +6 -4
- metadata +36 -20
- data/lib/rdoc/code_object/anon_class.rb +0 -10
- data/lib/rdoc/code_object/ghost_method.rb +0 -6
- data/lib/rdoc/code_object/meta_method.rb +0 -6
- data/lib/rdoc/markdown/literals.kpeg +0 -21
- data/lib/rdoc/markdown/literals.rb +0 -454
- data/lib/rdoc/parser/prism_ruby.rb +0 -1112
- data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
- data/lib/rdoc/parser/ruby_tools.rb +0 -163
- data/lib/rdoc/servlet.rb +0 -452
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'erb'
|
|
4
|
+
require 'pathname'
|
|
5
|
+
require 'rbs'
|
|
6
|
+
require 'rdoc/markup/formatter'
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
# RBS type signature support.
|
|
10
|
+
# Loads type information from .rbs files, validates inline annotations,
|
|
11
|
+
# and converts type signatures to HTML with linked type names.
|
|
12
|
+
|
|
13
|
+
module RDoc
|
|
14
|
+
module RbsHelper
|
|
15
|
+
class << self
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
# Returns true if +sig+ is a valid RBS method type signature.
|
|
19
|
+
|
|
20
|
+
def valid_method_type?(sig)
|
|
21
|
+
RBS::Parser.parse_method_type(sig, require_eof: true)
|
|
22
|
+
true
|
|
23
|
+
rescue RBS::ParsingError
|
|
24
|
+
false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
# Returns true if +sig+ is a valid RBS type signature.
|
|
29
|
+
|
|
30
|
+
def valid_type?(sig)
|
|
31
|
+
RBS::Parser.parse_type(sig, require_eof: true)
|
|
32
|
+
true
|
|
33
|
+
rescue RBS::ParsingError
|
|
34
|
+
false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
##
|
|
38
|
+
# Loads RBS signatures from the given directories.
|
|
39
|
+
# Returns a Hash mapping "ClassName#method_name" => ["type sig string", ...].
|
|
40
|
+
|
|
41
|
+
def load_signatures(*dirs)
|
|
42
|
+
loader = RBS::EnvironmentLoader.new
|
|
43
|
+
dirs.each { |dir| loader.add(path: Pathname(dir)) }
|
|
44
|
+
|
|
45
|
+
env = RBS::Environment.new
|
|
46
|
+
loader.load(env: env)
|
|
47
|
+
|
|
48
|
+
signatures = {}
|
|
49
|
+
|
|
50
|
+
env.class_decls.each do |type_name, entry|
|
|
51
|
+
class_name = type_name.to_s.delete_prefix('::')
|
|
52
|
+
|
|
53
|
+
entry.each_decl do |decl|
|
|
54
|
+
decl.members.each do |member|
|
|
55
|
+
case member
|
|
56
|
+
when RBS::AST::Members::MethodDefinition
|
|
57
|
+
sigs = member.overloads.map { |o| o.method_type.to_s }
|
|
58
|
+
method_keys_for(class_name, member).each do |key|
|
|
59
|
+
signatures[key] ||= sigs
|
|
60
|
+
end
|
|
61
|
+
when RBS::AST::Members::AttrReader, RBS::AST::Members::AttrWriter, RBS::AST::Members::AttrAccessor
|
|
62
|
+
key = member.kind == :singleton ? "#{class_name}.#{member.name}" : "#{class_name}##{member.name}"
|
|
63
|
+
signatures[key] ||= [member.type.to_s]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
signatures
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
##
|
|
73
|
+
# Converts type signature lines to HTML with type names linked to
|
|
74
|
+
# their documentation pages. Uses the RBS parser to extract type
|
|
75
|
+
# name locations precisely.
|
|
76
|
+
#
|
|
77
|
+
# +lines+ is an Array of signature line strings.
|
|
78
|
+
# +lookup+ is a Hash mapping type names to their doc paths.
|
|
79
|
+
# +from_path+ is the current page path for generating relative URLs.
|
|
80
|
+
#
|
|
81
|
+
# Returns escaped HTML with +->+ replaced by +→+.
|
|
82
|
+
|
|
83
|
+
def signature_to_html(lines, lookup:, from_path:)
|
|
84
|
+
lines.map { |line|
|
|
85
|
+
link_type_names_in_line(line, lookup, from_path).gsub('->', '→')
|
|
86
|
+
}.join("\n")
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
|
|
91
|
+
# `def self?.foo: ...` produces a member whose kind is :singleton_instance —
|
|
92
|
+
# it defines both Class.foo (singleton) and a private Class#foo (instance),
|
|
93
|
+
# so we need to register the signature under both keys.
|
|
94
|
+
def method_keys_for(class_name, member)
|
|
95
|
+
case member.kind
|
|
96
|
+
when :singleton
|
|
97
|
+
["#{class_name}.#{member.name}"]
|
|
98
|
+
when :singleton_instance
|
|
99
|
+
["#{class_name}.#{member.name}", "#{class_name}##{member.name}"]
|
|
100
|
+
else
|
|
101
|
+
["#{class_name}##{member.name}"]
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def link_type_names_in_line(line, lookup, from_path)
|
|
106
|
+
escaped = ERB::Util.html_escape(line)
|
|
107
|
+
|
|
108
|
+
locs = collect_type_name_locations(line)
|
|
109
|
+
return escaped if locs.empty?
|
|
110
|
+
|
|
111
|
+
result = escaped.dup
|
|
112
|
+
|
|
113
|
+
# Replace type names with links, working backwards to preserve positions.
|
|
114
|
+
# HTML escaping (e.g. -> becomes ->) shifts positions, so we
|
|
115
|
+
# re-escape the prefix to find the correct offset in the result.
|
|
116
|
+
locs.sort_by { |l| -l[:start] }.each do |loc|
|
|
117
|
+
name = loc[:name]
|
|
118
|
+
next unless (target_path = lookup[name])
|
|
119
|
+
|
|
120
|
+
prefix = ERB::Util.html_escape(line[0...loc[:start]])
|
|
121
|
+
escaped_name = ERB::Util.html_escape(name)
|
|
122
|
+
start_in_escaped = prefix.length
|
|
123
|
+
end_in_escaped = start_in_escaped + escaped_name.length
|
|
124
|
+
|
|
125
|
+
href = ERB::Util.html_escape(Markup::Formatter.gen_relative_url(from_path, target_path))
|
|
126
|
+
result[start_in_escaped...end_in_escaped] =
|
|
127
|
+
"<a href=\"#{href}\" class=\"rbs-type\">#{escaped_name}</a>"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
result
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
##
|
|
134
|
+
# Extracts type name locations from a signature line using the RBS parser.
|
|
135
|
+
|
|
136
|
+
def collect_type_name_locations(line)
|
|
137
|
+
locs = []
|
|
138
|
+
|
|
139
|
+
begin
|
|
140
|
+
mt = RBS::Parser.parse_method_type(line, require_eof: true)
|
|
141
|
+
rescue RBS::ParsingError
|
|
142
|
+
begin
|
|
143
|
+
type = RBS::Parser.parse_type(line, require_eof: true)
|
|
144
|
+
collect_from_type(type, locs)
|
|
145
|
+
return locs
|
|
146
|
+
rescue RBS::ParsingError
|
|
147
|
+
return locs
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
mt.type.each_param { |p| collect_from_type(p.type, locs) }
|
|
152
|
+
if mt.block
|
|
153
|
+
mt.block.type.each_param { |p| collect_from_type(p.type, locs) }
|
|
154
|
+
collect_from_type(mt.block.type.return_type, locs)
|
|
155
|
+
end
|
|
156
|
+
collect_from_type(mt.type.return_type, locs)
|
|
157
|
+
|
|
158
|
+
locs
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
##
|
|
162
|
+
# Recursively collects type name locations from an RBS type AST node.
|
|
163
|
+
|
|
164
|
+
def collect_from_type(type, locs)
|
|
165
|
+
case type
|
|
166
|
+
when RBS::Types::ClassInstance
|
|
167
|
+
name = type.name.to_s.delete_prefix('::')
|
|
168
|
+
if type.location
|
|
169
|
+
name_loc = type.location[:name] || type.location
|
|
170
|
+
locs << { name: name, start: name_loc.end_pos - name.length }
|
|
171
|
+
end
|
|
172
|
+
type.args.each { |a| collect_from_type(a, locs) }
|
|
173
|
+
when RBS::Types::Union, RBS::Types::Intersection, RBS::Types::Tuple
|
|
174
|
+
type.types.each { |t| collect_from_type(t, locs) }
|
|
175
|
+
when RBS::Types::Optional
|
|
176
|
+
collect_from_type(type.type, locs)
|
|
177
|
+
when RBS::Types::Record
|
|
178
|
+
type.all_fields.each_value { |t| collect_from_type(t, locs) }
|
|
179
|
+
when RBS::Types::Proc
|
|
180
|
+
type.type.each_param { |p| collect_from_type(p.type, locs) }
|
|
181
|
+
collect_from_type(type.type.return_type, locs)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
data/lib/rdoc/rd/inline.rb
CHANGED
|
@@ -1,71 +1,75 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
module RDoc
|
|
3
|
+
class RD
|
|
4
|
+
##
|
|
5
|
+
# Inline keeps track of markup and labels to create proper links.
|
|
4
6
|
|
|
5
|
-
class
|
|
7
|
+
class Inline
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
##
|
|
10
|
+
# The text of the reference
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
attr_reader :reference
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
##
|
|
15
|
+
# The markup of this reference in RDoc format
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
attr_reader :rdoc
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
##
|
|
20
|
+
# Creates a new Inline for +rdoc+ and +reference+.
|
|
21
|
+
#
|
|
22
|
+
# +rdoc+ may be another Inline or a String. If +reference+ is not given it
|
|
23
|
+
# will use the text from +rdoc+.
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
def self.new(rdoc, reference = rdoc)
|
|
26
|
+
if self === rdoc and reference.equal? rdoc
|
|
27
|
+
rdoc
|
|
28
|
+
else
|
|
29
|
+
super
|
|
30
|
+
end
|
|
31
|
+
end
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
##
|
|
34
|
+
# Initializes the Inline with +rdoc+ and +inline+
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
def initialize(rdoc, reference) # :not-new:
|
|
37
|
+
@reference = reference.equal?(rdoc) ? reference.dup : reference
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
# unpack
|
|
40
|
+
@reference = @reference.reference if self.class === @reference
|
|
41
|
+
@rdoc = rdoc
|
|
42
|
+
end
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
def ==(other) # :nodoc:
|
|
45
|
+
self.class === other and
|
|
46
|
+
@reference == other.reference and @rdoc == other.rdoc
|
|
47
|
+
end
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def append(more)
|
|
51
|
-
case more
|
|
52
|
-
when String then
|
|
53
|
-
@reference += more
|
|
54
|
-
@rdoc += more
|
|
55
|
-
when RDoc::RD::Inline then
|
|
56
|
-
@reference += more.reference
|
|
57
|
-
@rdoc += more.rdoc
|
|
58
|
-
else
|
|
59
|
-
raise "unknown thingy #{more}"
|
|
60
|
-
end
|
|
49
|
+
##
|
|
50
|
+
# Appends +more+ to this inline. +more+ may be a String or another Inline.
|
|
61
51
|
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
def append(more)
|
|
53
|
+
case more
|
|
54
|
+
when String
|
|
55
|
+
@reference += more
|
|
56
|
+
@rdoc += more
|
|
57
|
+
when RD::Inline
|
|
58
|
+
@reference += more.reference
|
|
59
|
+
@rdoc += more.rdoc
|
|
60
|
+
else
|
|
61
|
+
raise "unknown thingy #{more}"
|
|
62
|
+
end
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
self
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def inspect # :nodoc:
|
|
68
|
+
"(inline: #{self})"
|
|
69
|
+
end
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
alias to_s rdoc # :nodoc:
|
|
70
72
|
|
|
73
|
+
end
|
|
74
|
+
end
|
|
71
75
|
end
|
data/lib/rdoc/rd.rb
CHANGED
|
@@ -1,99 +1,101 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
#
|
|
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
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
# WARRANTIES
|
|
70
|
-
#
|
|
2
|
+
module RDoc
|
|
3
|
+
##
|
|
4
|
+
# RDoc::RD implements the RD format from the rdtool gem.
|
|
5
|
+
#
|
|
6
|
+
# To choose RD as your only default format see
|
|
7
|
+
# RDoc::Options@Saved+Options for instructions on setting up a
|
|
8
|
+
# <code>.doc_options</code> file to store your project default.
|
|
9
|
+
#
|
|
10
|
+
# == LICENSE
|
|
11
|
+
#
|
|
12
|
+
# The grammar that produces RDoc::RD::BlockParser and RDoc::RD::InlineParser
|
|
13
|
+
# is included in RDoc under the Ruby License.
|
|
14
|
+
#
|
|
15
|
+
# You can find the original source for rdtool at
|
|
16
|
+
# https://github.com/uwabami/rdtool/
|
|
17
|
+
#
|
|
18
|
+
# You can use, re-distribute or change these files under Ruby's License or GPL.
|
|
19
|
+
#
|
|
20
|
+
# 1. You may make and give away verbatim copies of the source form of the
|
|
21
|
+
# software without restriction, provided that you duplicate all of the
|
|
22
|
+
# original copyright notices and associated disclaimers.
|
|
23
|
+
#
|
|
24
|
+
# 2. You may modify your copy of the software in any way, provided that
|
|
25
|
+
# you do at least ONE of the following:
|
|
26
|
+
#
|
|
27
|
+
# a. place your modifications in the Public Domain or otherwise
|
|
28
|
+
# make them Freely Available, such as by posting said
|
|
29
|
+
# modifications to Usenet or an equivalent medium, or by allowing
|
|
30
|
+
# the author to include your modifications in the software.
|
|
31
|
+
#
|
|
32
|
+
# b. use the modified software only within your corporation or
|
|
33
|
+
# organization.
|
|
34
|
+
#
|
|
35
|
+
# c. give non-standard binaries non-standard names, with
|
|
36
|
+
# instructions on where to get the original software distribution.
|
|
37
|
+
#
|
|
38
|
+
# d. make other distribution arrangements with the author.
|
|
39
|
+
#
|
|
40
|
+
# 3. You may distribute the software in object code or binary form,
|
|
41
|
+
# provided that you do at least ONE of the following:
|
|
42
|
+
#
|
|
43
|
+
# a. distribute the binaries and library files of the software,
|
|
44
|
+
# together with instructions (in the manual page or equivalent)
|
|
45
|
+
# on where to get the original distribution.
|
|
46
|
+
#
|
|
47
|
+
# b. accompany the distribution with the machine-readable source of
|
|
48
|
+
# the software.
|
|
49
|
+
#
|
|
50
|
+
# c. give non-standard binaries non-standard names, with
|
|
51
|
+
# instructions on where to get the original software distribution.
|
|
52
|
+
#
|
|
53
|
+
# d. make other distribution arrangements with the author.
|
|
54
|
+
#
|
|
55
|
+
# 4. You may modify and include the part of the software into any other
|
|
56
|
+
# software (possibly commercial). But some files in the distribution
|
|
57
|
+
# are not written by the author, so that they are not under these terms.
|
|
58
|
+
#
|
|
59
|
+
# For the list of those files and their copying conditions, see the
|
|
60
|
+
# file LEGAL.
|
|
61
|
+
#
|
|
62
|
+
# 5. The scripts and library files supplied as input to or produced as
|
|
63
|
+
# output from the software do not automatically fall under the
|
|
64
|
+
# copyright of the software, but belong to whomever generated them,
|
|
65
|
+
# and may be sold commercially, and may be aggregated with this
|
|
66
|
+
# software.
|
|
67
|
+
#
|
|
68
|
+
# 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
|
69
|
+
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
70
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
71
|
+
# PURPOSE.
|
|
71
72
|
|
|
72
|
-
class
|
|
73
|
+
class RD
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
##
|
|
76
|
+
# Parses +rd+ source and returns an RDoc::Markup::Document. If the
|
|
77
|
+
# <tt>=begin</tt> or <tt>=end</tt> lines are missing they will be added.
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
def self.parse(rd)
|
|
80
|
+
rd = rd.lines.to_a
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
if rd.find { |i| /\S/ === i } and !rd.find{|i| /^=begin\b/ === i }
|
|
83
|
+
rd.unshift("=begin\n").push("=end\n")
|
|
84
|
+
end
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
parser = RD::BlockParser.new
|
|
87
|
+
document = parser.parse rd
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
# isn't this always true?
|
|
90
|
+
document.parts.shift if Markup::BlankLine === document.parts.first
|
|
91
|
+
document.parts.pop if Markup::BlankLine === document.parts.last
|
|
91
92
|
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
document
|
|
94
|
+
end
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
autoload :BlockParser, "#{__dir__}/rd/block_parser"
|
|
97
|
+
autoload :InlineParser, "#{__dir__}/rd/inline_parser"
|
|
98
|
+
autoload :Inline, "#{__dir__}/rd/inline"
|
|
98
99
|
|
|
100
|
+
end
|
|
99
101
|
end
|