rdoc 6.17.0 → 7.2.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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +196 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/README.md +90 -7
  5. data/doc/markup_reference/markdown.md +558 -0
  6. data/doc/markup_reference/rdoc.rdoc +1169 -0
  7. data/lib/rdoc/code_object/any_method.rb +15 -7
  8. data/lib/rdoc/code_object/attr.rb +2 -1
  9. data/lib/rdoc/code_object/class_module.rb +62 -11
  10. data/lib/rdoc/code_object/constant.rb +9 -0
  11. data/lib/rdoc/code_object/context/section.rb +46 -9
  12. data/lib/rdoc/code_object/context.rb +15 -4
  13. data/lib/rdoc/code_object/method_attr.rb +13 -1
  14. data/lib/rdoc/code_object/mixin.rb +3 -0
  15. data/lib/rdoc/code_object/top_level.rb +15 -1
  16. data/lib/rdoc/comment.rb +1 -1
  17. data/lib/rdoc/cross_reference.rb +31 -24
  18. data/lib/rdoc/generator/aliki.rb +141 -0
  19. data/lib/rdoc/generator/darkfish.rb +3 -1
  20. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  21. data/lib/rdoc/generator/template/aliki/_head.rhtml +9 -4
  22. data/lib/rdoc/generator/template/aliki/_header.rhtml +4 -4
  23. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +1 -1
  24. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  25. data/lib/rdoc/generator/template/aliki/class.rhtml +17 -17
  26. data/lib/rdoc/generator/template/aliki/css/rdoc.css +278 -60
  27. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  28. data/lib/rdoc/generator/template/aliki/js/aliki.js +51 -23
  29. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  30. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  31. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  32. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  33. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  34. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  35. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  36. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +11 -11
  39. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -0
  40. data/lib/rdoc/markdown.kpeg +22 -12
  41. data/lib/rdoc/markdown.rb +36 -26
  42. data/lib/rdoc/markup/blank_line.rb +25 -23
  43. data/lib/rdoc/markup/element.rb +21 -0
  44. data/lib/rdoc/markup/formatter.rb +129 -106
  45. data/lib/rdoc/markup/hard_break.rb +30 -27
  46. data/lib/rdoc/markup/heading.rb +166 -77
  47. data/lib/rdoc/markup/inline_parser.rb +312 -0
  48. data/lib/rdoc/markup/parser.rb +1 -1
  49. data/lib/rdoc/markup/raw.rb +52 -55
  50. data/lib/rdoc/markup/table.rb +48 -40
  51. data/lib/rdoc/markup/to_ansi.rb +51 -4
  52. data/lib/rdoc/markup/to_bs.rb +22 -42
  53. data/lib/rdoc/markup/to_html.rb +178 -183
  54. data/lib/rdoc/markup/to_html_crossref.rb +58 -79
  55. data/lib/rdoc/markup/to_html_snippet.rb +62 -62
  56. data/lib/rdoc/markup/to_label.rb +29 -20
  57. data/lib/rdoc/markup/to_markdown.rb +61 -37
  58. data/lib/rdoc/markup/to_rdoc.rb +86 -26
  59. data/lib/rdoc/markup/to_test.rb +9 -1
  60. data/lib/rdoc/markup/to_tt_only.rb +10 -16
  61. data/lib/rdoc/markup/verbatim.rb +1 -1
  62. data/lib/rdoc/markup.rb +11 -32
  63. data/lib/rdoc/options.rb +1 -1
  64. data/lib/rdoc/parser/changelog.rb +29 -0
  65. data/lib/rdoc/parser/prism_ruby.rb +44 -32
  66. data/lib/rdoc/parser/ruby.rb +1 -1
  67. data/lib/rdoc/rubygems_hook.rb +3 -3
  68. data/lib/rdoc/text.rb +44 -5
  69. data/lib/rdoc/token_stream.rb +4 -8
  70. data/lib/rdoc/version.rb +1 -1
  71. data/rdoc.gemspec +3 -3
  72. metadata +13 -15
  73. data/CONTRIBUTING.rdoc +0 -219
  74. data/ExampleMarkdown.md +0 -39
  75. data/ExampleRDoc.rdoc +0 -210
  76. data/lib/rdoc/markup/attr_changer.rb +0 -22
  77. data/lib/rdoc/markup/attr_span.rb +0 -35
  78. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  79. data/lib/rdoc/markup/attributes.rb +0 -70
  80. data/lib/rdoc/markup/regexp_handling.rb +0 -40
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'uri'
4
+
3
5
  ##
4
6
  # Aliki theme for RDoc documentation
5
7
  #
@@ -15,6 +17,30 @@ class RDoc::Generator::Aliki < RDoc::Generator::Darkfish
15
17
  @template_dir = Pathname.new(aliki_template_dir)
16
18
  end
17
19
 
20
+ ##
21
+ # Generate documentation. Overrides Darkfish to use Aliki's own search index
22
+ # instead of the JsonIndex generator.
23
+
24
+ def generate
25
+ setup
26
+
27
+ write_style_sheet
28
+ generate_index
29
+ generate_class_files
30
+ generate_file_files
31
+ generate_table_of_contents
32
+ write_search_index
33
+
34
+ copy_static
35
+
36
+ rescue => e
37
+ debug_msg "%s: %s\n %s" % [
38
+ e.class.name, e.message, e.backtrace.join("\n ")
39
+ ]
40
+
41
+ raise
42
+ end
43
+
18
44
  ##
19
45
  # Copy only the static assets required by the Aliki theme. Unlike Darkfish we
20
46
  # don't ship embedded fonts or image sprites, so limit the asset list to keep
@@ -39,4 +65,119 @@ class RDoc::Generator::Aliki < RDoc::Generator::Darkfish
39
65
  install_rdoc_static_file @template_dir + path, dst, options
40
66
  end
41
67
  end
68
+
69
+ ##
70
+ # Build a search index array for Aliki's searcher.
71
+
72
+ def build_search_index
73
+ setup
74
+
75
+ index = []
76
+
77
+ @classes.each do |klass|
78
+ next unless klass.display?
79
+
80
+ index << build_class_module_entry(klass)
81
+
82
+ klass.constants.each do |const|
83
+ next unless const.display?
84
+
85
+ index << build_constant_entry(const, klass)
86
+ end
87
+ end
88
+
89
+ @methods.each do |method|
90
+ next unless method.display?
91
+
92
+ index << build_method_entry(method)
93
+ end
94
+
95
+ index
96
+ end
97
+
98
+ ##
99
+ # Write the search index as a JavaScript file
100
+ # Format: var search_data = { index: [...] }
101
+ #
102
+ # We still write to a .js instead of a .json because loading a JSON file triggers CORS check in browsers.
103
+ # And if we simply inspect the generated pages using file://, which is often the case due to lack of the server mode,
104
+ # the JSON file will be blocked by the browser.
105
+
106
+ def write_search_index
107
+ debug_msg "Writing Aliki search index"
108
+
109
+ index = build_search_index
110
+
111
+ FileUtils.mkdir_p 'js' unless @dry_run
112
+
113
+ search_index_path = 'js/search_data.js'
114
+ return if @dry_run
115
+
116
+ data = { index: index }
117
+ File.write search_index_path, "var search_data = #{JSON.generate(data)};"
118
+ end
119
+
120
+ ##
121
+ # Resolves a URL for use in templates. Absolute URLs are returned unchanged.
122
+ # Relative URLs are prefixed with rel_prefix to ensure they resolve correctly from any page.
123
+
124
+ def resolve_url(rel_prefix, url)
125
+ uri = URI.parse(url)
126
+ if uri.absolute?
127
+ url
128
+ else
129
+ "#{rel_prefix}/#{url}"
130
+ end
131
+ rescue URI::InvalidURIError
132
+ "#{rel_prefix}/#{url}"
133
+ end
134
+
135
+ private
136
+
137
+ def build_class_module_entry(klass)
138
+ type = case klass
139
+ when RDoc::NormalClass then 'class'
140
+ when RDoc::NormalModule then 'module'
141
+ else 'class'
142
+ end
143
+
144
+ entry = {
145
+ name: klass.name,
146
+ full_name: klass.full_name,
147
+ type: type,
148
+ path: klass.path
149
+ }
150
+
151
+ snippet = klass.search_snippet
152
+ entry[:snippet] = snippet unless snippet.empty?
153
+ entry
154
+ end
155
+
156
+ def build_method_entry(method)
157
+ type = method.singleton ? 'class_method' : 'instance_method'
158
+
159
+ entry = {
160
+ name: method.name,
161
+ full_name: method.full_name,
162
+ type: type,
163
+ path: method.path
164
+ }
165
+
166
+ snippet = method.search_snippet
167
+ entry[:snippet] = snippet unless snippet.empty?
168
+ entry
169
+ end
170
+
171
+ def build_constant_entry(const, parent)
172
+ entry = {
173
+ name: const.name,
174
+ full_name: "#{parent.full_name}::#{const.name}",
175
+ type: 'constant',
176
+ path: parent.path
177
+ }
178
+
179
+ snippet = const.search_snippet
180
+ entry[:snippet] = snippet unless snippet.empty?
181
+ entry
182
+ end
42
183
  end
@@ -356,7 +356,9 @@ class RDoc::Generator::Darkfish
356
356
 
357
357
  current = nil
358
358
 
359
- @classes.each do |klass|
359
+ # Document files are generated only for non-alias classes/modules
360
+ @classes.reject(&:is_alias_for).each do |klass|
361
+
360
362
  current = klass
361
363
 
362
364
  generate_class klass, template_file
@@ -6,7 +6,7 @@
6
6
  <h3><%= h column_title %></h3>
7
7
  <ul>
8
8
  <% links.each do |text, url| %>
9
- <li><a href="<%= h url %>"><%= h text %></a></li>
9
+ <li><a href="<%= h resolve_url(rel_prefix, url) %>"><%= h text %></a></li>
10
10
  <% end %>
11
11
  </ul>
12
12
  </div>
@@ -116,22 +116,22 @@
116
116
  ></script>
117
117
 
118
118
  <script
119
- src="<%= h asset_rel_prefix %>/js/navigation.js?v=<%= h RDoc::VERSION %>"
119
+ src="<%= h asset_rel_prefix %>/js/search_navigation.js?v=<%= h RDoc::VERSION %>"
120
120
  defer
121
121
  ></script>
122
122
 
123
123
  <script
124
- src="<%= h asset_rel_prefix %>/js/search.js?v=<%= h RDoc::VERSION %>"
124
+ src="<%= h asset_rel_prefix %>/js/search_data.js?v=<%= h RDoc::VERSION %>"
125
125
  defer
126
126
  ></script>
127
127
 
128
128
  <script
129
- src="<%= h asset_rel_prefix %>/js/search_index.js?v=<%= h RDoc::VERSION %>"
129
+ src="<%= h asset_rel_prefix %>/js/search_ranker.js?v=<%= h RDoc::VERSION %>"
130
130
  defer
131
131
  ></script>
132
132
 
133
133
  <script
134
- src="<%= h asset_rel_prefix %>/js/searcher.js?v=<%= h RDoc::VERSION %>"
134
+ src="<%= h asset_rel_prefix %>/js/search_controller.js?v=<%= h RDoc::VERSION %>"
135
135
  defer
136
136
  ></script>
137
137
 
@@ -140,6 +140,11 @@
140
140
  defer
141
141
  ></script>
142
142
 
143
+ <script
144
+ src="<%= h asset_rel_prefix %>/js/bash_highlighter.js?v=<%= h RDoc::VERSION %>"
145
+ defer
146
+ ></script>
147
+
143
148
  <script
144
149
  src="<%= h asset_rel_prefix %>/js/aliki.js?v=<%= h RDoc::VERSION %>"
145
150
  defer
@@ -7,13 +7,13 @@
7
7
  <div class="navbar-search navbar-search-desktop" role="search">
8
8
  <form action="#" method="get" accept-charset="utf-8">
9
9
  <input id="search-field" role="combobox" aria-label="Search"
10
- aria-autocomplete="list" aria-controls="search-results"
10
+ aria-autocomplete="list" aria-controls="search-results-desktop"
11
11
  type="text" name="search" placeholder="Search (/) for a class, method..."
12
12
  spellcheck="false" autocomplete="off"
13
13
  title="Type to search, Up and Down to navigate, Enter to load">
14
- <ul id="search-results" aria-label="Search Results"
14
+ <ul id="search-results-desktop" aria-label="Search Results"
15
15
  aria-busy="false" aria-expanded="false"
16
- aria-atomic="false" class="initially-hidden"></ul>
16
+ aria-atomic="false" class="initially-hidden search-results"></ul>
17
17
  </form>
18
18
  </div>
19
19
 
@@ -47,7 +47,7 @@
47
47
  <div class="search-modal-body">
48
48
  <ul id="search-results-mobile" aria-label="Search Results"
49
49
  aria-busy="false" aria-expanded="false"
50
- aria-atomic="false" class="search-modal-results initially-hidden"></ul>
50
+ aria-atomic="false" class="search-results search-modal-results initially-hidden"></ul>
51
51
  <div class="search-modal-empty">
52
52
  <p>No recent searches</p>
53
53
  </div>
@@ -35,7 +35,7 @@
35
35
  <%= h f.page_name %>
36
36
  </a>
37
37
  </li>
38
- <%- next %>
38
+ <%- next -%>
39
39
  <%- end %>
40
40
 
41
41
  <li>
@@ -2,14 +2,14 @@
2
2
  <form action="#" method="get" accept-charset="utf-8">
3
3
  <div id="search-field-wrapper">
4
4
  <input id="search-field" role="combobox" aria-label="Search"
5
- aria-autocomplete="list" aria-controls="search-results"
5
+ aria-autocomplete="list" aria-controls="search-results-desktop"
6
6
  type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
7
7
  autocomplete="off"
8
8
  title="Type to search, Up and Down to navigate, Enter to load">
9
9
  </div>
10
10
 
11
- <ul id="search-results" aria-label="Search Results"
11
+ <ul id="search-results-desktop" aria-label="Search Results"
12
12
  aria-busy="false" aria-expanded="false"
13
- aria-atomic="false" class="initially-hidden"></ul>
13
+ aria-atomic="false" class="initially-hidden search-results"></ul>
14
14
  </form>
15
15
  </div>
@@ -3,7 +3,7 @@
3
3
  <%= render '_header.rhtml' %>
4
4
  <%= render '_sidebar_toggle.rhtml' %>
5
5
 
6
- <nav id="navigation" role="navigation">
6
+ <nav id="navigation" role="navigation" hidden>
7
7
  <%= render '_sidebar_pages.rhtml' %>
8
8
  <%= render '_sidebar_sections.rhtml' %>
9
9
  <%= render '_sidebar_ancestors.rhtml' %>
@@ -29,6 +29,7 @@
29
29
  </ol>
30
30
  <% end %>
31
31
 
32
+ <span id="<%= h klass.legacy_aref %>" class="legacy-anchor"></span>
32
33
  <h1 id="<%= h klass.aref %>" class="anchor-link <%= klass.type %>">
33
34
  <%= klass.type %> <%= klass.full_name %>
34
35
  </h1>
@@ -38,10 +39,11 @@
38
39
  </section>
39
40
 
40
41
  <%- klass.each_section do |section, constants, attributes| %>
41
- <section id="<%= section.aref %>" class="documentation-section anchor-link">
42
+ <span id="<%= section.legacy_aref %>" class="legacy-anchor"></span>
43
+ <section class="documentation-section anchor-link">
42
44
  <%- if section.title then %>
43
45
  <header class="documentation-section-title">
44
- <h2>
46
+ <h2 id="<%= section.aref %>">
45
47
  <a href="#<%= section.aref %>"><%= section.title %></a>
46
48
  </h2>
47
49
  </header>
@@ -56,7 +58,7 @@
56
58
  <%- unless constants.empty? then %>
57
59
  <section class="constants-list">
58
60
  <header>
59
- <h3 id="constants"><a href="#constants">Constants</a></h3>
61
+ <h3 id="<%= section.aref %>-constants"><a href="#<%= section.aref %>-constants">Constants</a></h3>
60
62
  </header>
61
63
  <dl>
62
64
  <%- constants.each do |const| %>
@@ -81,7 +83,7 @@
81
83
  <%- unless attributes.empty? then %>
82
84
  <section class="attribute-method-details method-section">
83
85
  <header>
84
- <h3 id="attributes"><a href="#attributes">Attributes</a></h3>
86
+ <h3 id="<%= section.aref %>-attributes"><a href="#<%= section.aref %>-attributes">Attributes</a></h3>
85
87
  </header>
86
88
 
87
89
  <%- attributes.each do |attrib| %>
@@ -110,13 +112,13 @@
110
112
  </section>
111
113
  <%- end %>
112
114
 
113
- <%- klass.methods_by_type(section).each do |type, visibilities|
114
- next if visibilities.empty?
115
- visibilities.each do |visibility, methods|
116
- next if methods.empty? %>
115
+ <%- klass.methods_by_type(section).each do |type, visibilities| %>
116
+ <%- next if visibilities.empty? %>
117
+ <%- visibilities.each do |visibility, methods| %>
118
+ <%- next if methods.empty? %>
117
119
  <section id="<%= visibility %>-<%= type %>-<%= section.aref %>-method-details" class="method-section anchor-link">
118
120
  <header>
119
- <h3 id="<%= visibility %>-<%= type %>-methods"><a href="#<%= visibility %>-<%= type %>-methods"><%= visibility.to_s.capitalize %> <%= type.capitalize %> Methods</a></h3>
121
+ <h3 id="<%= visibility %>-<%= type %>-<%= section.aref %>-methods"><a href="#<%= visibility %>-<%= type %>-<%= section.aref %>-methods"><%= visibility.to_s.capitalize %> <%= type.capitalize %> Methods</a></h3>
120
122
  </header>
121
123
 
122
124
  <%- methods.each do |method| %>
@@ -156,15 +158,13 @@
156
158
  <summary>Source</summary>
157
159
  </details>
158
160
  </div>
161
+ <div class="method-source-code" id="<%= method.html_name %>-source">
162
+ <pre class="<%= method.source_language %>"><%= method.markup_code %></pre>
163
+ </div>
159
164
  <%- end %>
160
165
 
161
166
  <%- unless method.skip_description? then %>
162
167
  <div class="method-description">
163
- <%- if method.token_stream then %>
164
- <div class="method-source-code" id="<%= method.html_name %>-source">
165
- <pre class="<%= method.source_language %>" data-language="<%= method.source_language %>"><%= method.markup_code %></pre>
166
- </div>
167
- <%- end %>
168
168
  <%- if method.mixin_from then %>
169
169
  <div class="mixin-from">
170
170
  <%= method.singleton ? "Extended" : "Included" %> from <a href="<%= klass.aref_to(method.mixin_from.path) %>"><%= method.mixin_from.full_name %></a>
@@ -208,8 +208,8 @@
208
208
 
209
209
  <%- end %>
210
210
  </section>
211
- <%- end
212
- end %>
211
+ <%- end %>
212
+ <%- end %>
213
213
  </section>
214
214
  <%- end %>
215
215
  </main>