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.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +4 -7
  3. data/LICENSE.rdoc +4 -0
  4. data/README.md +43 -2
  5. data/RI.md +75 -75
  6. data/doc/markup_reference/markdown.md +104 -3
  7. data/exe/rdoc +2 -2
  8. data/lib/rdoc/code_object/alias.rb +70 -74
  9. data/lib/rdoc/code_object/any_method.rb +305 -298
  10. data/lib/rdoc/code_object/attr.rb +150 -143
  11. data/lib/rdoc/code_object/class_module.rb +801 -765
  12. data/lib/rdoc/code_object/constant.rb +178 -150
  13. data/lib/rdoc/code_object/context/section.rb +133 -160
  14. data/lib/rdoc/code_object/context.rb +925 -952
  15. data/lib/rdoc/code_object/extend.rb +7 -5
  16. data/lib/rdoc/code_object/include.rb +7 -5
  17. data/lib/rdoc/code_object/method_attr.rb +325 -324
  18. data/lib/rdoc/code_object/mixin.rb +97 -95
  19. data/lib/rdoc/code_object/normal_class.rb +77 -78
  20. data/lib/rdoc/code_object/normal_module.rb +61 -59
  21. data/lib/rdoc/code_object/require.rb +23 -39
  22. data/lib/rdoc/code_object/single_class.rb +21 -19
  23. data/lib/rdoc/code_object/top_level.rb +212 -213
  24. data/lib/rdoc/code_object.rb +305 -305
  25. data/lib/rdoc/comment.rb +274 -337
  26. data/lib/rdoc/cross_reference.rb +194 -212
  27. data/lib/rdoc/encoding.rb +105 -103
  28. data/lib/rdoc/erb_partial.rb +13 -11
  29. data/lib/rdoc/erbio.rb +29 -27
  30. data/lib/rdoc/generator/aliki.rb +165 -140
  31. data/lib/rdoc/generator/darkfish.rb +647 -631
  32. data/lib/rdoc/generator/json_index.rb +233 -229
  33. data/lib/rdoc/generator/markup.rb +165 -122
  34. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  35. data/lib/rdoc/generator/pot/po.rb +52 -51
  36. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  37. data/lib/rdoc/generator/pot.rb +85 -81
  38. data/lib/rdoc/generator/ri.rb +23 -19
  39. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  40. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  41. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  42. data/lib/rdoc/generator/template/aliki/_head.rhtml +11 -11
  43. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  44. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  45. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  46. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  47. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +2 -2
  48. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  49. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  50. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  51. data/lib/rdoc/generator/template/aliki/class.rhtml +56 -46
  52. data/lib/rdoc/generator/template/aliki/css/rdoc.css +538 -283
  53. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  54. data/lib/rdoc/generator/template/aliki/js/aliki.js +80 -102
  55. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  57. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  58. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  59. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  60. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  61. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  62. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
  63. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  64. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  65. data/lib/rdoc/generator/template/darkfish/class.rhtml +18 -21
  66. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +0 -1
  67. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  68. data/lib/rdoc/generator.rb +48 -46
  69. data/lib/rdoc/i18n/locale.rb +99 -95
  70. data/lib/rdoc/i18n/text.rb +109 -105
  71. data/lib/rdoc/i18n.rb +7 -5
  72. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  73. data/lib/rdoc/markdown.kpeg +30 -21
  74. data/lib/rdoc/markdown.rb +329 -151
  75. data/lib/rdoc/markup/block_quote.rb +12 -8
  76. data/lib/rdoc/markup/document.rb +127 -123
  77. data/lib/rdoc/markup/formatter.rb +215 -221
  78. data/lib/rdoc/markup/heading.rb +1 -4
  79. data/lib/rdoc/markup/include.rb +33 -29
  80. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  81. data/lib/rdoc/markup/inline_parser.rb +281 -277
  82. data/lib/rdoc/markup/list.rb +80 -88
  83. data/lib/rdoc/markup/list_item.rb +73 -85
  84. data/lib/rdoc/markup/paragraph.rb +23 -19
  85. data/lib/rdoc/markup/parser.rb +501 -497
  86. data/lib/rdoc/markup/pre_process.rb +284 -305
  87. data/lib/rdoc/markup/raw.rb +2 -2
  88. data/lib/rdoc/markup/rule.rb +16 -12
  89. data/lib/rdoc/markup/to_ansi.rb +143 -139
  90. data/lib/rdoc/markup/to_bs.rb +72 -68
  91. data/lib/rdoc/markup/to_html.rb +600 -493
  92. data/lib/rdoc/markup/to_html_crossref.rb +221 -191
  93. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  94. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  95. data/lib/rdoc/markup/to_label.rb +63 -59
  96. data/lib/rdoc/markup/to_markdown.rb +212 -208
  97. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  98. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  99. data/lib/rdoc/markup/to_test.rb +60 -56
  100. data/lib/rdoc/markup/to_tt_only.rb +83 -86
  101. data/lib/rdoc/markup/verbatim.rb +62 -58
  102. data/lib/rdoc/markup.rb +198 -196
  103. data/lib/rdoc/options.rb +1063 -1076
  104. data/lib/rdoc/parser/c.rb +1039 -1036
  105. data/lib/rdoc/parser/changelog.rb +319 -315
  106. data/lib/rdoc/parser/markdown.rb +17 -13
  107. data/lib/rdoc/parser/rbs.rb +279 -0
  108. data/lib/rdoc/parser/rd.rb +17 -13
  109. data/lib/rdoc/parser/ruby.rb +1231 -2222
  110. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  111. data/lib/rdoc/parser/simple.rb +31 -27
  112. data/lib/rdoc/parser/text.rb +12 -8
  113. data/lib/rdoc/parser.rb +230 -221
  114. data/lib/rdoc/rbs_helper.rb +186 -0
  115. data/lib/rdoc/rd/inline.rb +57 -53
  116. data/lib/rdoc/rd.rb +90 -88
  117. data/lib/rdoc/rdoc.rb +547 -366
  118. data/lib/rdoc/ri/driver.rb +1141 -1130
  119. data/lib/rdoc/ri/formatter.rb +7 -3
  120. data/lib/rdoc/ri/paths.rb +140 -136
  121. data/lib/rdoc/ri/servlet.rb +456 -0
  122. data/lib/rdoc/ri/store.rb +4 -2
  123. data/lib/rdoc/ri/task.rb +55 -51
  124. data/lib/rdoc/ri.rb +14 -11
  125. data/lib/rdoc/rubygems_hook.rb +194 -192
  126. data/lib/rdoc/server.rb +462 -0
  127. data/lib/rdoc/stats/normal.rb +46 -42
  128. data/lib/rdoc/stats/quiet.rb +39 -35
  129. data/lib/rdoc/stats/verbose.rb +35 -31
  130. data/lib/rdoc/stats.rb +363 -338
  131. data/lib/rdoc/store.rb +919 -725
  132. data/lib/rdoc/task.rb +260 -255
  133. data/lib/rdoc/text.rb +130 -245
  134. data/lib/rdoc/token_stream.rb +101 -115
  135. data/lib/rdoc/tom_doc.rb +203 -201
  136. data/lib/rdoc/version.rb +1 -1
  137. data/lib/rdoc.rb +35 -7
  138. data/lib/rubygems_plugin.rb +2 -11
  139. data/rdoc-logo.svg +43 -0
  140. data/rdoc.gemspec +6 -4
  141. metadata +36 -20
  142. data/lib/rdoc/code_object/anon_class.rb +0 -10
  143. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  144. data/lib/rdoc/code_object/meta_method.rb +0 -6
  145. data/lib/rdoc/markdown/literals.kpeg +0 -21
  146. data/lib/rdoc/markdown/literals.rb +0 -454
  147. data/lib/rdoc/parser/prism_ruby.rb +0 -1112
  148. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  149. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  150. data/lib/rdoc/servlet.rb +0 -452
@@ -1,171 +1,214 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Handle common RDoc::Markup tasks for various CodeObjects
4
- #
5
- # This module is loaded by generators. It allows RDoc's CodeObject tree to
6
- # avoid loading generator code to improve startup time for +ri+.
2
+ module RDoc
3
+ module Generator
4
+ ##
5
+ # Handle common RDoc::Markup tasks for various CodeObjects
6
+ #
7
+ # This module is loaded by generators. It allows RDoc's CodeObject tree to
8
+ # avoid loading generator code to improve startup time for +ri+.
7
9
 
8
- module RDoc::Generator::Markup
10
+ module Markup
9
11
 
10
- ##
11
- # Generates a relative URL from this object's path to +target_path+
12
+ ##
13
+ # Generates a relative URL from this object's path to +target_path+
12
14
 
13
- def aref_to(target_path)
14
- RDoc::Markup::ToHtml.gen_relative_url path, target_path
15
- end
15
+ def aref_to(target_path)
16
+ ::RDoc::Markup::ToHtml.gen_relative_url path, target_path
17
+ end
16
18
 
17
- ##
18
- # Generates a relative URL from +from_path+ to this object's path
19
+ ##
20
+ # Generates a relative URL from +from_path+ to this object's path
19
21
 
20
- def as_href(from_path)
21
- RDoc::Markup::ToHtml.gen_relative_url from_path, path
22
- end
22
+ def as_href(from_path)
23
+ ::RDoc::Markup::ToHtml.gen_relative_url from_path, path
24
+ end
23
25
 
24
- ##
25
- # Handy wrapper for marking up this object's comment
26
+ ##
27
+ # Handy wrapper for marking up this object's comment
26
28
 
27
- def description
28
- markup @comment
29
- end
29
+ def description
30
+ markup @comment
31
+ end
30
32
 
31
- ##
32
- # Creates an RDoc::Markup::ToHtmlCrossref formatter
33
+ ##
34
+ # Creates an RDoc::Markup::ToHtmlCrossref formatter
35
+
36
+ def formatter
37
+ return @formatter if defined? @formatter
38
+
39
+ options = @store.options
40
+ this = Context === self ? self : @parent
41
+
42
+ @formatter = ::RDoc::Markup::ToHtmlCrossref.new(
43
+ this.path, this,
44
+ pipe: options.pipe,
45
+ output_decoration: options.output_decoration,
46
+ hyperlink_all: options.hyperlink_all,
47
+ show_hash: options.show_hash,
48
+ autolink_excluded_words: options.autolink_excluded_words || [],
49
+ warn_missing_rdoc_ref: options.warn_missing_rdoc_ref
50
+ )
51
+ @formatter.code_object = self
52
+ @formatter
53
+ end
33
54
 
34
- def formatter
35
- return @formatter if defined? @formatter
55
+ ##
56
+ # Build a webcvs URL starting for the given +url+ with +full_path+ appended
57
+ # as the destination path. If +url+ contains '%s' +full_path+ will be
58
+ # will replace the %s using sprintf on the +url+.
59
+
60
+ def cvs_url(url, full_path)
61
+ if /%s/ =~ url
62
+ sprintf url, full_path
63
+ else
64
+ url + full_path
65
+ end
66
+ end
36
67
 
37
- options = @store.options
38
- this = RDoc::Context === self ? self : @parent
68
+ ##
69
+ # The preferred URL for this object.
39
70
 
40
- @formatter = RDoc::Markup::ToHtmlCrossref.new options, this.path, this
41
- @formatter.code_object = self
42
- @formatter
71
+ def canonical_url
72
+ options = @store.options
73
+ if path
74
+ File.join(options.canonical_root, path.to_s)
75
+ else
76
+ options.canonical_root
77
+ end
78
+ end
79
+
80
+ end
43
81
  end
82
+ end
44
83
 
45
- ##
46
- # Build a webcvs URL starting for the given +url+ with +full_path+ appended
47
- # as the destination path. If +url+ contains '%s' +full_path+ will be
48
- # will replace the %s using sprintf on the +url+.
84
+ module RDoc
85
+ class CodeObject
86
+
87
+ include Generator::Markup
49
88
 
50
- def cvs_url(url, full_path)
51
- if /%s/ =~ url then
52
- sprintf url, full_path
53
- else
54
- url + full_path
55
- end
56
89
  end
90
+ end
91
+
92
+ module RDoc
93
+ class AnyMethod
57
94
 
58
- ##
59
- # The preferred URL for this object.
95
+ ##
96
+ # Creates an HTML link to the superclass method called by this method.
60
97
 
61
- def canonical_url
62
- options = @store.options
63
- if path
64
- File.join(options.canonical_root, path.to_s)
65
- else
66
- options.canonical_root
98
+ def superclass_method_link
99
+ target = superclass_method
100
+ return unless target
101
+
102
+ html_formatter = formatter
103
+ name = target.full_name
104
+
105
+ html_formatter.link name, html_formatter.convert_string(name)
67
106
  end
68
- end
69
107
 
108
+ end
70
109
  end
71
110
 
72
- class RDoc::CodeObject
111
+ module RDoc
112
+ class MethodAttr
73
113
 
74
- include RDoc::Generator::Markup
114
+ ##
115
+ # Prepend +src+ with line numbers.
75
116
 
76
- end
117
+ def add_line_numbers(src)
118
+ return if src.empty? || !line
119
+ start_line = line
120
+ end_line = start_line + src.count("\n")
121
+ number_digits = end_line.to_s.length
77
122
 
78
- class RDoc::MethodAttr
79
-
80
- ##
81
- # Prepend +src+ with line numbers. Relies on the first line of a source
82
- # code listing having:
83
- #
84
- # # File xxxxx, line dddd
85
- #
86
- # If it has this comment then line numbers are added to +src+ and the <tt>,
87
- # line dddd</tt> portion of the comment is removed.
88
-
89
- def add_line_numbers(src)
90
- return unless src.sub!(/\A(.*)(, line (\d+))/, '\1')
91
- first = $3.to_i - 1
92
- last = first + src.count("\n")
93
- size = last.to_s.length
94
-
95
- line = first
96
- src.gsub!(/^/) do
97
- res = if line == first then
98
- " " * (size + 1)
99
- else
100
- "<span class=\"line-num\">%2$*1$d</span> " % [size, line]
101
- end
102
-
103
- line += 1
104
- res
123
+ current_line = start_line
124
+ src.gsub!(/^/) do
125
+ res = "<span class=\"line-num\">#{current_line.to_s.rjust(number_digits)}</span> "
126
+
127
+ current_line += 1
128
+ res
129
+ end
105
130
  end
106
- end
107
131
 
108
- ##
109
- # Turns the method's token stream into HTML.
110
- #
111
- # Prepends line numbers if +options.line_numbers+ is true.
112
-
113
- def markup_code
114
- return '' unless @token_stream
115
-
116
- src = RDoc::TokenStream.to_html @token_stream
117
-
118
- # dedent the source
119
- indent = src.length
120
- lines = src.lines.to_a
121
- lines.shift if src =~ /\A.*#\ *File/i # remove '# File' comment
122
- lines.each do |line|
123
- if line =~ /^ *(?=\S)/
124
- n = $~.end(0)
125
- indent = n if n < indent
126
- break if n == 0
132
+ ##
133
+ # Prepend +src+ with a comment that declares its location in the source.
134
+
135
+ def add_location_comment(src)
136
+ path = CGI.escapeHTML(file.relative_name)
137
+ if options.line_numbers && !src.empty?
138
+ src.prepend("<span class=\"ruby-comment\"># File #{path}</span>\n")
139
+ else
140
+ src.prepend("<span class=\"ruby-comment\"># File #{path}, line #{line}</span>\n")
127
141
  end
128
142
  end
129
- src.gsub!(/^#{' ' * indent}/, '') if indent > 0
130
143
 
131
- add_line_numbers(src) if options.line_numbers
144
+ ##
145
+ # Turns the method's token stream into HTML.
146
+ #
147
+ # Prepends line numbers if +options.line_numbers+ is true.
132
148
 
133
- src
134
- end
149
+ def markup_code
150
+ return '' unless token_stream
135
151
 
136
- end
152
+ src = TokenStream.to_html token_stream
137
153
 
138
- class RDoc::ClassModule
154
+ # dedent the source
155
+ common_indent = src.length
156
+ src.scan(/^ *(?=\S)/) do |whitespace|
157
+ common_indent = whitespace.length if whitespace.length < common_indent
158
+ break if common_indent == 0
159
+ end
160
+ src.gsub!(/^#{' ' * common_indent}/, '') if common_indent > 0
139
161
 
140
- ##
141
- # Handy wrapper for marking up this class or module's comment
162
+ if source_language == 'ruby'
163
+ add_line_numbers(src) if options.line_numbers
164
+ add_location_comment(src)
165
+ end
166
+
167
+ src
168
+ end
142
169
 
143
- def description
144
- markup @comment_location
145
170
  end
171
+ end
146
172
 
173
+ module RDoc
174
+ class ClassModule
175
+
176
+ ##
177
+ # Handy wrapper for marking up this class or module's comment
178
+
179
+ def description
180
+ markup @comment_location
181
+ end
182
+
183
+ end
147
184
  end
148
185
 
149
- class RDoc::Context::Section
186
+ module RDoc
187
+ class Context
188
+ class Section
150
189
 
151
- include RDoc::Generator::Markup
190
+ include Generator::Markup
152
191
 
192
+ end
193
+ end
153
194
  end
154
195
 
155
- class RDoc::TopLevel
196
+ module RDoc
197
+ class TopLevel
156
198
 
157
- ##
158
- # Returns a URL for this source file on some web repository. Use the -W
159
- # command line option to set.
199
+ ##
200
+ # Returns a URL for this source file on some web repository. Use the -W
201
+ # command line option to set.
160
202
 
161
- def cvs_url
162
- url = @store.options.webcvs
203
+ def cvs_url
204
+ url = @store.options.webcvs
163
205
 
164
- if /%s/ =~ url then
165
- url % @relative_name
166
- else
167
- url + @relative_name
206
+ if /%s/ =~ url
207
+ url % @relative_name
208
+ else
209
+ url + @relative_name
210
+ end
168
211
  end
169
- end
170
212
 
213
+ end
171
214
  end
@@ -1,68 +1,74 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Extracts message from RDoc::Store
2
+ module RDoc
3
+ module Generator
4
+ class POT
5
+ ##
6
+ # Extracts message from RDoc::Store
4
7
 
5
- class RDoc::Generator::POT::MessageExtractor
8
+ class MessageExtractor
6
9
 
7
- ##
8
- # Creates a message extractor for +store+.
10
+ ##
11
+ # Creates a message extractor for +store+.
9
12
 
10
- def initialize(store)
11
- @store = store
12
- @po = RDoc::Generator::POT::PO.new
13
- end
13
+ def initialize(store)
14
+ @store = store
15
+ @po = Generator::POT::PO.new
16
+ end
14
17
 
15
- ##
16
- # Extracts messages from +store+, stores them into
17
- # RDoc::Generator::POT::PO and returns it.
18
+ ##
19
+ # Extracts messages from +store+, stores them into
20
+ # RDoc::Generator::POT::PO and returns it.
18
21
 
19
- def extract
20
- @store.all_classes_and_modules.each do |klass|
21
- extract_from_klass(klass)
22
- end
23
- @po
24
- end
22
+ def extract
23
+ @store.all_classes_and_modules.each do |klass|
24
+ extract_from_klass(klass)
25
+ end
26
+ @po
27
+ end
25
28
 
26
- private
29
+ private
27
30
 
28
- def extract_from_klass(klass)
29
- extract_text(klass.comment_location, klass.full_name)
31
+ def extract_from_klass(klass)
32
+ extract_text(klass.comment_location, klass.full_name)
30
33
 
31
- klass.each_section do |section, constants, attributes|
32
- extract_text(section.title, "#{klass.full_name}: section title")
33
- section.comments.each do |comment|
34
- extract_text(comment, "#{klass.full_name}: #{section.title}")
35
- end
36
- end
34
+ klass.each_section do |section, constants, attributes|
35
+ extract_text(section.title, "#{klass.full_name}: section title")
36
+ section.comments.each do |comment|
37
+ extract_text(comment, "#{klass.full_name}: #{section.title}")
38
+ end
39
+ end
37
40
 
38
- klass.constants.each do |constant|
39
- extract_text(constant.comment, constant.full_name)
40
- end
41
+ klass.constants.each do |constant|
42
+ extract_text(constant.comment, constant.full_name)
43
+ end
41
44
 
42
- klass.attributes.each do |attribute|
43
- extract_text(attribute.comment, attribute.full_name)
44
- end
45
+ klass.attributes.each do |attribute|
46
+ extract_text(attribute.comment, attribute.full_name)
47
+ end
45
48
 
46
- klass.each_method do |method|
47
- extract_text(method.comment, method.full_name)
48
- end
49
- end
49
+ klass.each_method do |method|
50
+ extract_text(method.comment, method.full_name)
51
+ end
52
+ end
50
53
 
51
- def extract_text(text, comment, location = nil)
52
- return if text.nil?
54
+ def extract_text(text, comment, location = nil)
55
+ return if text.nil?
53
56
 
54
- options = {
55
- :extracted_comment => comment,
56
- :references => [location].compact,
57
- }
58
- i18n_text = RDoc::I18n::Text.new(text)
59
- i18n_text.extract_messages do |part|
60
- @po.add(entry(part[:paragraph], options))
61
- end
62
- end
57
+ options = {
58
+ :extracted_comment => comment,
59
+ :references => [location].compact,
60
+ }
61
+ i18n_text = I18n::Text.new(text)
62
+ i18n_text.extract_messages do |part|
63
+ @po.add(entry(part[:paragraph], options))
64
+ end
65
+ end
63
66
 
64
- def entry(msgid, options)
65
- RDoc::Generator::POT::POEntry.new(msgid, options)
66
- end
67
+ def entry(msgid, options)
68
+ Generator::POT::POEntry.new(msgid, options)
69
+ end
67
70
 
71
+ end
72
+ end
73
+ end
68
74
  end
@@ -1,55 +1,53 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Generates a PO format text
2
+ module RDoc
3
+ module Generator
4
+ class POT
5
+ ##
6
+ # Generates a PO format text
4
7
 
5
- class RDoc::Generator::POT::PO
8
+ class PO
6
9
 
7
- ##
8
- # Creates an object that represents PO format.
10
+ ##
11
+ # Creates an object that represents PO format.
9
12
 
10
- def initialize
11
- @entries = {}
12
- add_header
13
- end
13
+ def initialize
14
+ @entries = {}
15
+ add_header
16
+ end
14
17
 
15
- ##
16
- # Adds a PO entry to the PO.
18
+ ##
19
+ # Adds a PO entry to the PO.
17
20
 
18
- def add(entry)
19
- existing_entry = @entries[entry.msgid]
20
- if existing_entry
21
- entry = existing_entry.merge(entry)
22
- end
23
- @entries[entry.msgid] = entry
24
- end
21
+ def add(entry)
22
+ existing_entry = @entries[entry.msgid]
23
+ if existing_entry
24
+ entry = existing_entry.merge(entry)
25
+ end
26
+ @entries[entry.msgid] = entry
27
+ end
25
28
 
26
- ##
27
- # Returns PO format text for the PO.
29
+ ##
30
+ # Returns PO format text for the PO.
28
31
 
29
- def to_s
30
- po = ''
31
- sort_entries.each do |entry|
32
- po += "\n" unless po.empty?
33
- po += entry.to_s
34
- end
35
- po
36
- end
32
+ def to_s
33
+ sort_entries.map(&:to_s).join("\n")
34
+ end
37
35
 
38
- private
36
+ private
39
37
 
40
- def add_header
41
- add(header_entry)
42
- end
38
+ def add_header
39
+ add(header_entry)
40
+ end
43
41
 
44
- def header_entry
45
- comment = <<-COMMENT
42
+ def header_entry
43
+ comment = <<-COMMENT
46
44
  SOME DESCRIPTIVE TITLE.
47
45
  Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
48
46
  This file is distributed under the same license as the PACKAGE package.
49
47
  FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
50
48
  COMMENT
51
49
 
52
- content = <<-CONTENT
50
+ content = <<-CONTENT
53
51
  Project-Id-Version: PACKAGE VERSEION
54
52
  Report-Msgid-Bugs-To:
55
53
  PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE
@@ -62,23 +60,26 @@ Content-Transfer-Encoding: 8bit
62
60
  Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;
63
61
  CONTENT
64
62
 
65
- options = {
66
- :msgstr => content,
67
- :translator_comment => comment,
68
- :flags => ['fuzzy'],
69
- }
70
- RDoc::Generator::POT::POEntry.new('', options)
71
- end
63
+ options = {
64
+ :msgstr => content,
65
+ :translator_comment => comment,
66
+ :flags => ['fuzzy'],
67
+ }
68
+ Generator::POT::POEntry.new('', options)
69
+ end
72
70
 
73
- def sort_entries
74
- headers, messages = @entries.values.partition do |entry|
75
- entry.msgid.empty?
76
- end
77
- # TODO: sort by location
78
- sorted_messages = messages.sort_by do |entry|
79
- entry.msgid
71
+ def sort_entries
72
+ headers, messages = @entries.values.partition do |entry|
73
+ entry.msgid.empty?
74
+ end
75
+ # TODO: sort by location
76
+ sorted_messages = messages.sort_by do |entry|
77
+ entry.msgid
78
+ end
79
+ headers + sorted_messages
80
+ end
81
+
82
+ end
80
83
  end
81
- headers + sorted_messages
82
84
  end
83
-
84
85
  end