yard 0.8.2.1 → 0.8.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.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/ChangeLog +246 -0
- data/README.md +12 -2
- data/Rakefile +19 -51
- data/benchmarks/format_args.rb +3 -3
- data/benchmarks/pathname_vs_string.rb +4 -4
- data/benchmarks/template_format.rb +1 -1
- data/docs/Templates.md +21 -21
- data/docs/WhatsNew.md +16 -2
- data/lib/yard.rb +23 -3
- data/lib/yard/autoload.rb +14 -13
- data/lib/yard/cli/command.rb +11 -3
- data/lib/yard/cli/command_parser.rb +4 -4
- data/lib/yard/cli/config.rb +2 -2
- data/lib/yard/cli/diff.rb +60 -16
- data/lib/yard/cli/graph.rb +5 -2
- data/lib/yard/cli/help.rb +1 -1
- data/lib/yard/cli/list.rb +2 -2
- data/lib/yard/cli/server.rb +80 -13
- data/lib/yard/cli/stats.rb +8 -8
- data/lib/yard/cli/yardoc.rb +32 -78
- data/lib/yard/cli/yardopts_command.rb +109 -0
- data/lib/yard/cli/yri.rb +2 -2
- data/lib/yard/code_objects/base.rb +3 -1
- data/lib/yard/code_objects/extra_file_object.rb +45 -6
- data/lib/yard/core_ext/file.rb +1 -1
- data/lib/yard/docstring.rb +10 -1
- data/lib/yard/i18n/locale.rb +11 -3
- data/lib/yard/i18n/message.rb +1 -1
- data/lib/yard/logging.rb +32 -7
- data/lib/yard/parser/ruby/ruby_parser.rb +8 -3
- data/lib/yard/parser/source_parser.rb +1 -2
- data/lib/yard/rake/yardoc_task.rb +1 -2
- data/lib/yard/registry.rb +20 -1
- data/lib/yard/registry_store.rb +15 -1
- data/lib/yard/rubygems/backports/gem.rb +6 -5
- data/lib/yard/rubygems/backports/source_index.rb +17 -0
- data/lib/yard/rubygems/doc_manager.rb +1 -1
- data/lib/yard/server/commands/static_file_command.rb +17 -10
- data/lib/yard/server/library_version.rb +2 -2
- data/lib/yard/server/rack_adapter.rb +3 -3
- data/lib/yard/server/templates/default/layout/html/setup.rb +1 -1
- data/lib/yard/tags/directives.rb +1 -1
- data/lib/yard/templates/helpers/html_helper.rb +6 -4
- data/lib/yard/templates/template.rb +13 -1
- data/lib/yard/version.rb +3 -0
- data/spec/cli/config_spec.rb +2 -2
- data/spec/cli/diff_spec.rb +110 -23
- data/spec/cli/graph_spec.rb +12 -5
- data/spec/cli/help_spec.rb +1 -1
- data/spec/cli/server_spec.rb +243 -153
- data/spec/cli/stats_spec.rb +1 -1
- data/spec/cli/yardoc_spec.rb +36 -0
- data/spec/code_objects/base_spec.rb +15 -0
- data/spec/code_objects/constants_spec.rb +1 -1
- data/spec/code_objects/extra_file_object_spec.rb +15 -3
- data/spec/docstring_parser_spec.rb +4 -0
- data/spec/docstring_spec.rb +18 -0
- data/spec/handlers/module_function_handler_spec.rb +23 -0
- data/spec/i18n/locale_spec.rb +7 -1
- data/spec/parser/ruby/ruby_parser_spec.rb +26 -0
- data/spec/parser/source_parser_spec.rb +18 -6
- data/spec/rake/yardoc_task_spec.rb +28 -19
- data/spec/registry_spec.rb +34 -0
- data/spec/registry_store_spec.rb +10 -0
- data/spec/rubygems/doc_manager_spec.rb +1 -1
- data/spec/server/commands/static_file_command_spec.rb +3 -3
- data/spec/spec_helper.rb +22 -3
- data/spec/templates/helpers/html_helper_spec.rb +10 -8
- data/templates/default/fulldoc/html/frames.erb +1 -1
- data/templates/default/fulldoc/html/setup.rb +1 -1
- data/yard.gemspec +24 -0
- metadata +7 -5
data/lib/yard/cli/stats.rb
CHANGED
@@ -64,30 +64,30 @@ module YARD
|
|
64
64
|
else
|
65
65
|
total = (@total - @undocumented).to_f / @total.to_f * 100
|
66
66
|
end
|
67
|
-
puts("% 3.2f%% documented" % total)
|
67
|
+
log.puts("% 3.2f%% documented" % total)
|
68
68
|
end
|
69
69
|
|
70
70
|
# Prints list of undocumented objects
|
71
71
|
def print_undocumented_objects
|
72
72
|
return if !@undoc_list || @undoc_list.empty?
|
73
|
-
puts
|
74
|
-
puts "Undocumented Objects:"
|
73
|
+
log.puts
|
74
|
+
log.puts "Undocumented Objects:"
|
75
75
|
|
76
76
|
objects = @undoc_list.sort_by {|o| o.file }
|
77
77
|
max = objects.sort_by {|o| o.path.length }.last.path.length
|
78
78
|
if @compact
|
79
79
|
objects.each do |object|
|
80
|
-
puts("%-#{max}s (%s)" % [object.path,
|
80
|
+
log.puts("%-#{max}s (%s)" % [object.path,
|
81
81
|
[object.file, object.line].compact.join(":")])
|
82
82
|
end
|
83
83
|
else
|
84
84
|
last_file = nil
|
85
85
|
objects.each do |object|
|
86
86
|
if object.file != last_file
|
87
|
-
puts
|
88
|
-
puts "(in file: #{object.file})"
|
87
|
+
log.puts
|
88
|
+
log.puts "(in file: #{object.file})"
|
89
89
|
end
|
90
|
-
puts object.path
|
90
|
+
log.puts object.path
|
91
91
|
last_file = object.file
|
92
92
|
end
|
93
93
|
end
|
@@ -148,7 +148,7 @@ module YARD
|
|
148
148
|
else
|
149
149
|
data = "%5s" % data
|
150
150
|
end
|
151
|
-
puts("%-12s %s" % [name + ":", data])
|
151
|
+
log.puts("%-12s %s" % [name + ":", data])
|
152
152
|
end
|
153
153
|
|
154
154
|
private
|
data/lib/yard/cli/yardoc.rb
CHANGED
@@ -138,10 +138,7 @@ module YARD
|
|
138
138
|
#
|
139
139
|
# @since 0.2.1
|
140
140
|
# @see Verifier
|
141
|
-
class Yardoc <
|
142
|
-
# The configuration filename to load extra options from
|
143
|
-
DEFAULT_YARDOPTS_FILE = ".yardopts"
|
144
|
-
|
141
|
+
class Yardoc < YardoptsCommand
|
145
142
|
# @return [Hash] the hash of options passed to the template.
|
146
143
|
# @see Templates::Engine#render
|
147
144
|
attr_reader :options
|
@@ -158,12 +155,6 @@ module YARD
|
|
158
155
|
# parse only changed files.
|
159
156
|
attr_accessor :use_cache
|
160
157
|
|
161
|
-
# @return [Boolean] whether to parse options from .yardopts
|
162
|
-
attr_accessor :use_yardopts_file
|
163
|
-
|
164
|
-
# @return [Boolean] whether to parse options from .document
|
165
|
-
attr_accessor :use_document_file
|
166
|
-
|
167
158
|
# @return [Boolean] whether objects should be serialized to .yardoc db
|
168
159
|
attr_accessor :save_yardoc
|
169
160
|
|
@@ -174,10 +165,6 @@ module YARD
|
|
174
165
|
# @since 0.5.5
|
175
166
|
attr_accessor :list
|
176
167
|
|
177
|
-
# The options file name (defaults to {DEFAULT_YARDOPTS_FILE})
|
178
|
-
# @return [String] the filename to load extra options from
|
179
|
-
attr_accessor :options_file
|
180
|
-
|
181
168
|
# Keep track of which visibilities are to be shown
|
182
169
|
# @return [Array<Symbol>] a list of visibilities
|
183
170
|
# @since 0.5.6
|
@@ -216,10 +203,7 @@ module YARD
|
|
216
203
|
@files = []
|
217
204
|
@hidden_tags = []
|
218
205
|
@use_cache = false
|
219
|
-
@use_yardopts_file = true
|
220
|
-
@use_document_file = true
|
221
206
|
@generate = true
|
222
|
-
@options_file = DEFAULT_YARDOPTS_FILE
|
223
207
|
@statistics = true
|
224
208
|
@list = false
|
225
209
|
@save_yardoc = true
|
@@ -279,12 +263,7 @@ module YARD
|
|
279
263
|
# @return [Boolean] whether or not arguments are valid
|
280
264
|
# @since 0.5.6
|
281
265
|
def parse_arguments(*args)
|
282
|
-
|
283
|
-
|
284
|
-
# Parse files and then command line arguments
|
285
|
-
optparse(*support_rdoc_document_file!) if use_document_file
|
286
|
-
optparse(*yardopts) if use_yardopts_file
|
287
|
-
optparse(*args)
|
266
|
+
super(*args)
|
288
267
|
|
289
268
|
# Last minute modifications
|
290
269
|
self.files = ['{lib,app}/**/*.rb', 'ext/**/*.c'] if self.files.empty?
|
@@ -298,6 +277,8 @@ module YARD
|
|
298
277
|
add_visibility_verifier
|
299
278
|
add_api_verifier
|
300
279
|
|
280
|
+
apply_locale
|
281
|
+
|
301
282
|
# US-ASCII is invalid encoding for onefile
|
302
283
|
if defined?(::Encoding) && options.onefile
|
303
284
|
if ::Encoding.default_internal == ::Encoding::US_ASCII
|
@@ -322,15 +303,6 @@ module YARD
|
|
322
303
|
Registry.all(:root, :module, :class)
|
323
304
|
end
|
324
305
|
|
325
|
-
# Parses the .yardopts file for default yard options
|
326
|
-
# @return [Array<String>] an array of options parsed from .yardopts
|
327
|
-
def yardopts
|
328
|
-
return [] unless use_yardopts_file
|
329
|
-
File.read_binary(options_file).shell_split
|
330
|
-
rescue Errno::ENOENT
|
331
|
-
[]
|
332
|
-
end
|
333
|
-
|
334
306
|
private
|
335
307
|
|
336
308
|
# Generates output for objects
|
@@ -403,34 +375,10 @@ module YARD
|
|
403
375
|
Registry.load_all
|
404
376
|
run_verifier(Registry.all).
|
405
377
|
sort_by {|item| [item.file || '', item.line || 0] }.each do |item|
|
406
|
-
puts "#{item.file}:#{item.line}: #{item.path}"
|
378
|
+
log.puts "#{item.file}:#{item.line}: #{item.path}"
|
407
379
|
end
|
408
380
|
end
|
409
381
|
|
410
|
-
# Parses out the yardopts/document options
|
411
|
-
def parse_yardopts_options(*args)
|
412
|
-
opts = OptionParser.new
|
413
|
-
opts.base.long.clear # HACK: why are --help and --version defined?
|
414
|
-
yardopts_options(opts)
|
415
|
-
begin
|
416
|
-
opts.parse(args)
|
417
|
-
rescue OptionParser::ParseError => err
|
418
|
-
idx = args.index(err.args.first)
|
419
|
-
args = args[(idx+1)..-1]
|
420
|
-
args.shift while args.first && args.first[0,1] != '-'
|
421
|
-
retry
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
# Reads a .document file in the directory to get source file globs
|
426
|
-
# @return [Array<String>] an array of files parsed from .document
|
427
|
-
def support_rdoc_document_file!
|
428
|
-
return [] unless use_document_file
|
429
|
-
File.read(".document").gsub(/^[ \t]*#.+/m, '').split(/\s+/)
|
430
|
-
rescue Errno::ENOENT
|
431
|
-
[]
|
432
|
-
end
|
433
|
-
|
434
382
|
# Adds a set of extra documentation files to be processed
|
435
383
|
# @param [Array<String>] files the set of documentation files
|
436
384
|
def add_extra_files(*files)
|
@@ -489,6 +437,15 @@ module YARD
|
|
489
437
|
options.verifier.add_expressions(expr)
|
490
438
|
end
|
491
439
|
|
440
|
+
# Applies the specified locale to collected objects
|
441
|
+
# @return [void]
|
442
|
+
# @since 0.8.3
|
443
|
+
def apply_locale
|
444
|
+
options.files.each do |file|
|
445
|
+
file.locale = options.locale
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
492
449
|
# (see Templates::Helpers::BaseHelper#run_verifier)
|
493
450
|
def run_verifier(list)
|
494
451
|
options.verifier ? options.verifier.run(list) : list
|
@@ -569,25 +526,6 @@ module YARD
|
|
569
526
|
end
|
570
527
|
end
|
571
528
|
|
572
|
-
# Adds --[no-]yardopts / --[no-]document
|
573
|
-
def yardopts_options(opts)
|
574
|
-
opts.on('--[no-]yardopts [FILE]',
|
575
|
-
"If arguments should be read from FILE",
|
576
|
-
" (defaults to yes, FILE defaults to .yardopts)") do |use_yardopts|
|
577
|
-
if use_yardopts.is_a?(String)
|
578
|
-
self.options_file = use_yardopts
|
579
|
-
self.use_yardopts_file = true
|
580
|
-
else
|
581
|
-
self.use_yardopts_file = (use_yardopts != false)
|
582
|
-
end
|
583
|
-
end
|
584
|
-
|
585
|
-
opts.on('--[no-]document', "If arguments should be read from .document file. ",
|
586
|
-
" (defaults to yes)") do |use_document|
|
587
|
-
self.use_document_file = use_document
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
529
|
# Adds output options
|
592
530
|
def output_options(opts)
|
593
531
|
opts.separator ""
|
@@ -735,6 +673,18 @@ module YARD
|
|
735
673
|
opts.on('--no-stats', 'Don\'t print statistics') do
|
736
674
|
self.statistics = false
|
737
675
|
end
|
676
|
+
|
677
|
+
opts.on('--locale LOCALE',
|
678
|
+
'The locale for generated documentation.',
|
679
|
+
' (defaults to en)') do |locale|
|
680
|
+
options.locale = locale
|
681
|
+
end
|
682
|
+
|
683
|
+
opts.on('--po-dir DIR',
|
684
|
+
'The directory that has .po files.',
|
685
|
+
' (defaults to #{YARD::Registry.po_dir})') do |dir|
|
686
|
+
YARD::Registry.po_dir = dir
|
687
|
+
end
|
738
688
|
end
|
739
689
|
|
740
690
|
# Adds tag options
|
@@ -767,8 +717,12 @@ module YARD
|
|
767
717
|
self.hidden_tags |= [tag.to_sym]
|
768
718
|
end
|
769
719
|
|
770
|
-
opts.on('--transitive-tag TAG', '
|
771
|
-
Tags::Library.transitive_tags
|
720
|
+
opts.on('--transitive-tag TAG', 'Marks a tag as transitive') do |tag|
|
721
|
+
Tags::Library.transitive_tags |= [tag.to_sym]
|
722
|
+
end
|
723
|
+
|
724
|
+
opts.on('--non-transitive-tag TAG', 'Marks a tag as not transitive') do |tag|
|
725
|
+
Tags::Library.transitive_tags -= [tag.to_sym]
|
772
726
|
end
|
773
727
|
end
|
774
728
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module CLI
|
5
|
+
# Abstract base class for command that reads .yardopts file
|
6
|
+
#
|
7
|
+
# @abstract
|
8
|
+
# @since 0.8.3
|
9
|
+
class YardoptsCommand < Command
|
10
|
+
# The configuration filename to load extra options from
|
11
|
+
DEFAULT_YARDOPTS_FILE = ".yardopts"
|
12
|
+
|
13
|
+
# @return [Boolean] whether to parse options from .yardopts
|
14
|
+
attr_accessor :use_yardopts_file
|
15
|
+
|
16
|
+
# @return [Boolean] whether to parse options from .document
|
17
|
+
attr_accessor :use_document_file
|
18
|
+
|
19
|
+
# The options file name (defaults to {DEFAULT_YARDOPTS_FILE})
|
20
|
+
# @return [String] the filename to load extra options from
|
21
|
+
attr_accessor :options_file
|
22
|
+
|
23
|
+
# Creates a new command that reads .yardopts
|
24
|
+
def initialize
|
25
|
+
super
|
26
|
+
@options_file = DEFAULT_YARDOPTS_FILE
|
27
|
+
@use_yardopts_file = true
|
28
|
+
@use_document_file = true
|
29
|
+
end
|
30
|
+
|
31
|
+
# Parses commandline arguments
|
32
|
+
# @param [Array<String>] args the list of arguments
|
33
|
+
# @return [Boolean] whether or not arguments are valid
|
34
|
+
# @since 0.5.6
|
35
|
+
def parse_arguments(*args)
|
36
|
+
parse_yardopts_options(*args)
|
37
|
+
|
38
|
+
# Parse files and then command line arguments
|
39
|
+
parse_rdoc_document_file
|
40
|
+
parse_yardopts
|
41
|
+
optparse(*args)
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
# Adds --[no-]yardopts / --[no-]document
|
47
|
+
def yardopts_options(opts)
|
48
|
+
opts.on('--[no-]yardopts [FILE]',
|
49
|
+
"If arguments should be read from FILE",
|
50
|
+
" (defaults to yes, FILE defaults to .yardopts)") do |use_yardopts|
|
51
|
+
if use_yardopts.is_a?(String)
|
52
|
+
self.options_file = use_yardopts
|
53
|
+
self.use_yardopts_file = true
|
54
|
+
else
|
55
|
+
self.use_yardopts_file = (use_yardopts != false)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on('--[no-]document', "If arguments should be read from .document file. ",
|
60
|
+
" (defaults to yes)") do |use_document|
|
61
|
+
self.use_document_file = use_document
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# Parses the .yardopts file for default yard options
|
68
|
+
# @return [Array<String>] an array of options parsed from .yardopts
|
69
|
+
def yardopts(file = options_file)
|
70
|
+
return [] unless use_yardopts_file
|
71
|
+
File.read_binary(file).shell_split
|
72
|
+
rescue Errno::ENOENT
|
73
|
+
[]
|
74
|
+
end
|
75
|
+
|
76
|
+
# Parses out the yardopts/document options
|
77
|
+
def parse_yardopts_options(*args)
|
78
|
+
opts = OptionParser.new
|
79
|
+
opts.base.long.clear # HACK: why are --help and --version defined?
|
80
|
+
yardopts_options(opts)
|
81
|
+
begin
|
82
|
+
opts.parse(args)
|
83
|
+
rescue OptionParser::ParseError => err
|
84
|
+
idx = args.index(err.args.first)
|
85
|
+
args = args[(idx+1)..-1]
|
86
|
+
args.shift while args.first && args.first[0,1] != '-'
|
87
|
+
retry
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def parse_rdoc_document_file(file = '.document')
|
92
|
+
optparse(*support_rdoc_document_file!(file)) if use_document_file
|
93
|
+
end
|
94
|
+
|
95
|
+
def parse_yardopts(file = options_file)
|
96
|
+
optparse(*yardopts(file)) if use_yardopts_file
|
97
|
+
end
|
98
|
+
|
99
|
+
# Reads a .document file in the directory to get source file globs
|
100
|
+
# @return [Array<String>] an array of files parsed from .document
|
101
|
+
def support_rdoc_document_file!(file = '.document')
|
102
|
+
return [] unless use_document_file
|
103
|
+
File.read(file).gsub(/^[ \t]*#.+/m, '').split(/\s+/)
|
104
|
+
rescue Errno::ENOENT
|
105
|
+
[]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/yard/cli/yri.rb
CHANGED
@@ -72,8 +72,8 @@ module YARD
|
|
72
72
|
# @return [void]
|
73
73
|
# @since 0.5.6
|
74
74
|
def print_usage
|
75
|
-
puts "Usage: yri [options] <Path to object>"
|
76
|
-
puts "See yri --help for more options."
|
75
|
+
log.puts "Usage: yri [options] <Path to object>"
|
76
|
+
log.puts "See yri --help for more options."
|
77
77
|
end
|
78
78
|
|
79
79
|
# Caches the .yardoc file where an object can be found in the {CACHE_FILE}
|
@@ -170,7 +170,9 @@ module YARD
|
|
170
170
|
if name.to_s[0,2] == NSEP
|
171
171
|
name = name.to_s[2..-1]
|
172
172
|
namespace = Registry.root
|
173
|
-
|
173
|
+
end
|
174
|
+
|
175
|
+
if name =~ /(?:#{NSEPQ})([^:]+)$/
|
174
176
|
return new(Proxy.new(namespace, $`), $1, *args, &block)
|
175
177
|
end
|
176
178
|
|
@@ -5,9 +5,10 @@ module YARD::CodeObjects
|
|
5
5
|
# compatible with most CodeObject interfaces.
|
6
6
|
class ExtraFileObject
|
7
7
|
attr_accessor :filename
|
8
|
-
|
8
|
+
attr_writer :attributes
|
9
9
|
attr_accessor :name
|
10
|
-
|
10
|
+
# @since 0.8.3
|
11
|
+
attr_reader :locale
|
11
12
|
|
12
13
|
# Creates a new extra file object.
|
13
14
|
# @param [String] filename the location on disk of the file
|
@@ -17,15 +18,41 @@ module YARD::CodeObjects
|
|
17
18
|
self.filename = filename
|
18
19
|
self.name = File.basename(filename).gsub(/\.[^.]+$/, '')
|
19
20
|
self.attributes = SymbolHash.new(false)
|
20
|
-
|
21
|
+
@original_contents = contents
|
22
|
+
@parsed = false
|
23
|
+
@locale = nil
|
24
|
+
ensure_parsed
|
21
25
|
end
|
22
26
|
|
23
27
|
alias path name
|
24
28
|
|
29
|
+
def attributes
|
30
|
+
ensure_parsed
|
31
|
+
@attributes
|
32
|
+
end
|
33
|
+
|
25
34
|
def title
|
26
35
|
attributes[:title] || name
|
27
36
|
end
|
28
37
|
|
38
|
+
def contents
|
39
|
+
ensure_parsed
|
40
|
+
@contents
|
41
|
+
end
|
42
|
+
|
43
|
+
def contents=(contents)
|
44
|
+
@original_contents = contents
|
45
|
+
@parsed = false
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param [String] locale the locale name to be translated.
|
49
|
+
# @return [void]
|
50
|
+
# @since 0.8.3
|
51
|
+
def locale=(locale)
|
52
|
+
@locale = locale
|
53
|
+
@parsed = false
|
54
|
+
end
|
55
|
+
|
29
56
|
def inspect
|
30
57
|
"#<yardoc #{type} #{filename} attrs=#{attributes.inspect}>"
|
31
58
|
end
|
@@ -43,10 +70,17 @@ module YARD::CodeObjects
|
|
43
70
|
|
44
71
|
private
|
45
72
|
|
73
|
+
def ensure_parsed
|
74
|
+
return if @parsed
|
75
|
+
@parsed = true
|
76
|
+
@contents = parse_contents(@original_contents || File.read(@filename))
|
77
|
+
end
|
78
|
+
|
46
79
|
# @param [String] data the file contents
|
47
80
|
def parse_contents(data)
|
48
81
|
retried = false
|
49
82
|
cut_index = 0
|
83
|
+
data = translate(data)
|
50
84
|
data = data.split("\n")
|
51
85
|
data.each_with_index do |line, index|
|
52
86
|
case line
|
@@ -65,7 +99,7 @@ module YARD::CodeObjects
|
|
65
99
|
end
|
66
100
|
end
|
67
101
|
data = data[cut_index..-1] if cut_index > 0
|
68
|
-
|
102
|
+
contents = data.join("\n")
|
69
103
|
|
70
104
|
if contents.respond_to?(:force_encoding) && attributes[:encoding]
|
71
105
|
begin
|
@@ -74,16 +108,21 @@ module YARD::CodeObjects
|
|
74
108
|
log.warn "Invalid encoding `#{attributes[:encoding]}' in #{filename}"
|
75
109
|
end
|
76
110
|
end
|
111
|
+
contents
|
77
112
|
rescue ArgumentError => e
|
78
113
|
if retried && e.message =~ /invalid byte sequence/
|
79
114
|
# This should never happen.
|
80
115
|
log.warn "Could not read #{filename}, #{e.message}. You probably want to set `--charset`."
|
81
|
-
|
82
|
-
return
|
116
|
+
return ''
|
83
117
|
end
|
84
118
|
data.force_encoding('binary') if data.respond_to?(:force_encoding)
|
85
119
|
retried = true
|
86
120
|
retry
|
87
121
|
end
|
122
|
+
|
123
|
+
def translate(data)
|
124
|
+
text = YARD::I18n::Text.new(data, :have_header => true)
|
125
|
+
text.translate(YARD::Registry.locale(locale))
|
126
|
+
end
|
88
127
|
end
|
89
128
|
end
|