yard 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/ChangeLog +341 -0
- data/LICENSE +1 -1
- data/README.md +31 -6
- data/Rakefile +22 -3
- data/docs/Tags.md +5 -1
- data/docs/WhatsNew.md +18 -1
- data/lib/rubygems_plugin.rb +3 -99
- data/lib/yard.rb +1 -1
- data/lib/yard/autoload.rb +37 -35
- data/lib/yard/cli/config.rb +25 -2
- data/lib/yard/cli/graph.rb +1 -1
- data/lib/yard/cli/yardoc.rb +4 -0
- data/lib/yard/code_objects/base.rb +17 -9
- data/lib/yard/code_objects/method_object.rb +0 -9
- data/lib/yard/code_objects/proxy.rb +6 -0
- data/lib/yard/docstring.rb +5 -0
- data/lib/yard/handlers/base.rb +3 -1
- data/lib/yard/handlers/processor.rb +1 -1
- data/lib/yard/handlers/ruby/alias_handler.rb +9 -8
- data/lib/yard/handlers/ruby/class_handler.rb +3 -3
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +9 -7
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -0
- data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +21 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
- data/lib/yard/handlers/ruby/method_handler.rb +7 -0
- data/lib/yard/handlers/ruby/private_constant_handler.rb +36 -0
- data/lib/yard/parser/ruby/ast_node.rb +41 -24
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +3 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +2 -0
- data/lib/yard/parser/ruby/legacy/statement_list.rb +27 -4
- data/lib/yard/parser/ruby/ruby_parser.rb +71 -36
- data/lib/yard/parser/source_parser.rb +11 -10
- data/lib/yard/registry.rb +62 -24
- data/lib/yard/registry_store.rb +18 -5
- data/lib/yard/rubygems/doc_manager.rb +75 -0
- data/lib/yard/rubygems/specification.rb +23 -0
- data/lib/yard/serializers/process_serializer.rb +1 -1
- data/lib/yard/serializers/yardoc_serializer.rb +7 -2
- data/lib/yard/server/commands/display_object_command.rb +1 -1
- data/lib/yard/server/commands/library_command.rb +2 -2
- data/lib/yard/tags/default_factory.rb +1 -1
- data/lib/yard/tags/library.rb +2 -2
- data/lib/yard/templates/helpers/base_helper.rb +19 -0
- data/lib/yard/templates/helpers/html_helper.rb +22 -9
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +28 -0
- data/lib/yard/templates/helpers/markup_helper.rb +14 -22
- data/lib/yard/templates/template.rb +1 -1
- data/spec/cli/config_spec.rb +20 -0
- data/spec/cli/yardoc_spec.rb +12 -0
- data/spec/code_objects/base_spec.rb +13 -0
- data/spec/code_objects/proxy_spec.rb +9 -0
- data/spec/config_spec.rb +4 -1
- data/spec/docstring_spec.rb +5 -0
- data/spec/handlers/alias_handler_spec.rb +14 -1
- data/spec/handlers/attribute_handler_spec.rb +1 -1
- data/spec/handlers/base_spec.rb +21 -21
- data/spec/handlers/class_condition_handler_spec.rb +1 -1
- data/spec/handlers/class_handler_spec.rb +1 -1
- data/spec/handlers/class_variable_handler_spec.rb +1 -1
- data/spec/handlers/constant_handler_spec.rb +2 -2
- data/spec/handlers/examples/alias_handler_001.rb.txt +14 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +6 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/private_constant_handler_001.rb.txt +8 -0
- data/spec/handlers/exception_handler_spec.rb +1 -1
- data/spec/handlers/extend_handler_spec.rb +1 -1
- data/spec/handlers/method_condition_handler_spec.rb +1 -1
- data/spec/handlers/method_handler_spec.rb +7 -1
- data/spec/handlers/mixin_handler_spec.rb +1 -1
- data/spec/handlers/module_handler_spec.rb +5 -1
- data/spec/handlers/private_constant_handler_spec.rb +24 -0
- data/spec/handlers/process_handler_spec.rb +1 -1
- data/spec/handlers/ruby/base_spec.rb +4 -4
- data/spec/handlers/visibility_handler_spec.rb +1 -1
- data/spec/handlers/yield_handler_spec.rb +1 -1
- data/spec/parser/base_spec.rb +3 -5
- data/spec/parser/c_parser_spec.rb +1 -1
- data/spec/parser/ruby/ast_node_spec.rb +23 -26
- data/spec/parser/ruby/legacy/statement_list_spec.rb +9 -0
- data/spec/parser/ruby/ruby_parser_spec.rb +179 -177
- data/spec/parser/source_parser_spec.rb +41 -7
- data/spec/rake/yardoc_task_spec.rb +3 -3
- data/spec/registry_spec.rb +52 -0
- data/spec/registry_store_spec.rb +71 -1
- data/spec/serializers/yardoc_serializer_spec.rb +18 -7
- data/spec/server/rack_adapter_spec.rb +2 -2
- data/spec/spec_helper.rb +10 -0
- data/spec/tags/default_factory_spec.rb +122 -120
- data/spec/templates/helpers/base_helper_spec.rb +38 -14
- data/spec/templates/helpers/html_helper_spec.rb +19 -0
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +10 -6
- data/spec/templates/helpers/markup_helper_spec.rb +21 -5
- data/templates/default/class/dot/superklass.erb +1 -1
- data/templates/default/docstring/setup.rb +1 -1
- data/templates/default/fulldoc/html/css/style.css +12 -4
- data/templates/default/fulldoc/html/js/app.js +1 -1
- data/templates/default/fulldoc/html/js/jquery.js +5 -143
- data/templates/default/layout/html/files.erb +11 -0
- data/templates/default/layout/html/headers.erb +1 -1
- data/templates/default/layout/html/index.erb +2 -49
- data/templates/default/layout/html/listing.erb +4 -0
- data/templates/default/layout/html/objects.erb +32 -0
- data/templates/default/layout/html/setup.rb +1 -1
- data/templates/default/module/dot/info.erb +1 -1
- data/templates/default/module/dot/setup.rb +1 -1
- metadata +15 -6
- data/lib/yard/templates/helpers/html_syntax_highlight_helper18.rb +0 -25
data/lib/yard/registry_store.rb
CHANGED
@@ -137,8 +137,14 @@ module YARD
|
|
137
137
|
@serializer = Serializers::YardocSerializer.new(@file)
|
138
138
|
end
|
139
139
|
destroy unless merge
|
140
|
-
|
141
|
-
|
140
|
+
|
141
|
+
sdb = Registry.single_object_db
|
142
|
+
if sdb == true || (sdb == nil && keys.size < 3000)
|
143
|
+
@serializer.serialize(@store)
|
144
|
+
else
|
145
|
+
values(false).each do |object|
|
146
|
+
@serializer.serialize(object)
|
147
|
+
end
|
142
148
|
end
|
143
149
|
write_proxy_types
|
144
150
|
write_checksums
|
@@ -197,12 +203,12 @@ module YARD
|
|
197
203
|
end
|
198
204
|
end
|
199
205
|
|
206
|
+
private
|
207
|
+
|
200
208
|
def load_yardoc_old
|
201
209
|
@store, @proxy_types = *Marshal.load(File.read_binary(@file))
|
202
210
|
end
|
203
211
|
|
204
|
-
private
|
205
|
-
|
206
212
|
def load_proxy_types
|
207
213
|
return unless File.file?(proxy_types_path)
|
208
214
|
@proxy_types = Marshal.load(File.read_binary(proxy_types_path))
|
@@ -218,7 +224,14 @@ module YARD
|
|
218
224
|
|
219
225
|
def load_root
|
220
226
|
if root = @serializer.deserialize('root')
|
221
|
-
@
|
227
|
+
@loaded_objects += 1
|
228
|
+
if root.is_a?(Hash) # single object db
|
229
|
+
log.debug "Loading single object DB from .yardoc"
|
230
|
+
@loaded_objects += (root.keys.size - 1)
|
231
|
+
@store = root
|
232
|
+
else # just the root object
|
233
|
+
@store[:root] = root
|
234
|
+
end
|
222
235
|
end
|
223
236
|
end
|
224
237
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rubygems/doc_manager'
|
2
|
+
|
3
|
+
class Gem::DocManager
|
4
|
+
def self.load_yardoc
|
5
|
+
require File.dirname(__FILE__) + '/../../yard'
|
6
|
+
end
|
7
|
+
|
8
|
+
def run_yardoc(*args)
|
9
|
+
args << '--quiet'
|
10
|
+
args << @spec.require_paths
|
11
|
+
if @spec.extra_rdoc_files.size > 0
|
12
|
+
args << '-'
|
13
|
+
args += @spec.extra_rdoc_files
|
14
|
+
end
|
15
|
+
args = args.flatten.map {|arg| arg.to_s }
|
16
|
+
|
17
|
+
old_pwd = Dir.pwd
|
18
|
+
Dir.chdir(@spec.full_gem_path)
|
19
|
+
YARD::CLI::Yardoc.run(*args)
|
20
|
+
rescue Errno::EACCES => e
|
21
|
+
dirname = File.dirname e.message.split("-")[1].strip
|
22
|
+
raise Gem::FilePermissionError.new(dirname)
|
23
|
+
rescue => ex
|
24
|
+
alert_error "While generating documentation for #{@spec.full_name}"
|
25
|
+
ui.errs.puts "... MESSAGE: #{ex}"
|
26
|
+
ui.errs.puts "... YARDDOC args: #{args.join(' ')}"
|
27
|
+
ui.errs.puts "\t#{ex.backtrace.join("\n\t")}" if Gem.configuration.backtrace
|
28
|
+
ui.errs.puts "(continuing with the rest of the installation)"
|
29
|
+
ensure
|
30
|
+
Dir.chdir(old_pwd)
|
31
|
+
end
|
32
|
+
|
33
|
+
undef setup_rdoc
|
34
|
+
def setup_rdoc
|
35
|
+
if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
|
36
|
+
raise Gem::FilePermissionError.new(@doc_dir)
|
37
|
+
end
|
38
|
+
|
39
|
+
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
|
40
|
+
|
41
|
+
self.class.load_rdoc if @spec.has_rdoc?
|
42
|
+
self.class.load_yardoc if @spec.has_yardoc?
|
43
|
+
end
|
44
|
+
|
45
|
+
def install_yardoc
|
46
|
+
rdoc_dir = File.join(@doc_dir, 'rdoc')
|
47
|
+
|
48
|
+
FileUtils.rm_rf rdoc_dir
|
49
|
+
|
50
|
+
say "Installing YARD documentation for #{@spec.full_name}..."
|
51
|
+
run_yardoc '-o', rdoc_dir
|
52
|
+
end
|
53
|
+
|
54
|
+
def install_ri_yard
|
55
|
+
install_ri_yard_orig if @spec.has_rdoc?
|
56
|
+
return if @spec.has_rdoc? == false
|
57
|
+
return if @spec.has_yardoc?
|
58
|
+
|
59
|
+
self.class.load_yardoc
|
60
|
+
say "Building YARD (yri) index for #{@spec.full_name}..."
|
61
|
+
run_yardoc '-c', '-n'
|
62
|
+
end
|
63
|
+
alias install_ri_yard_orig install_ri
|
64
|
+
alias install_ri install_ri_yard
|
65
|
+
|
66
|
+
def install_rdoc_yard
|
67
|
+
if @spec.has_rdoc?
|
68
|
+
install_rdoc_yard_orig
|
69
|
+
elsif @spec.has_yardoc?
|
70
|
+
install_yardoc
|
71
|
+
end
|
72
|
+
end
|
73
|
+
alias install_rdoc_yard_orig install_rdoc
|
74
|
+
alias install_rdoc install_rdoc_yard
|
75
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems/specification'
|
2
|
+
|
3
|
+
class Gem::Specification
|
4
|
+
# has_rdoc should not be ignored!
|
5
|
+
overwrite_accessor(:has_rdoc) { @has_rdoc }
|
6
|
+
overwrite_accessor(:has_rdoc=) {|v| @has_rdoc = v }
|
7
|
+
|
8
|
+
# @since 0.5.3
|
9
|
+
def has_yardoc=(value)
|
10
|
+
@has_rdoc = 'yard'
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_yardoc
|
14
|
+
@has_rdoc == 'yard'
|
15
|
+
end
|
16
|
+
|
17
|
+
undef has_rdoc?
|
18
|
+
def has_rdoc?
|
19
|
+
@has_rdoc && @has_rdoc != 'yard'
|
20
|
+
end
|
21
|
+
|
22
|
+
alias has_yardoc? has_yardoc
|
23
|
+
end
|
@@ -13,7 +13,7 @@ module YARD
|
|
13
13
|
@cmd = cmd
|
14
14
|
end
|
15
15
|
|
16
|
-
# Overrides serialize
|
16
|
+
# Overrides serialize behaviour and writes data to standard input
|
17
17
|
# of the associated command
|
18
18
|
def serialize(object, data)
|
19
19
|
IO.popen(@cmd, 'w') {|io| io.write(data) }
|
@@ -61,7 +61,11 @@ module YARD
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def serialize(object)
|
64
|
-
|
64
|
+
if Hash === object
|
65
|
+
super(object[:root], dump(object)) if object[:root]
|
66
|
+
else
|
67
|
+
super(object, dump(object))
|
68
|
+
end
|
65
69
|
end
|
66
70
|
|
67
71
|
def deserialize(path, is_path = false)
|
@@ -78,7 +82,8 @@ module YARD
|
|
78
82
|
private
|
79
83
|
|
80
84
|
def dump(object)
|
81
|
-
|
85
|
+
object = internal_dump(object, true) unless object.is_a?(Hash)
|
86
|
+
Marshal.dump(object)
|
82
87
|
end
|
83
88
|
|
84
89
|
def internal_dump(object, first_object = false)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module YARD
|
2
2
|
module Server
|
3
3
|
module Commands
|
4
|
-
# Displays documentation for a specific object
|
4
|
+
# Displays documentation for a specific object identified by the path
|
5
5
|
class DisplayObjectCommand < LibraryCommand
|
6
6
|
def run
|
7
7
|
return index if path.empty?
|
@@ -76,13 +76,13 @@ module YARD
|
|
76
76
|
|
77
77
|
def load_yardoc
|
78
78
|
raise LibraryNotPreparedError unless library.yardoc_file
|
79
|
-
if
|
79
|
+
if Thread.current[:__yard_last_yardoc__] == library.yardoc_file
|
80
80
|
log.debug "Reusing yardoc file: #{library.yardoc_file}"
|
81
81
|
return
|
82
82
|
end
|
83
83
|
Registry.clear
|
84
84
|
Registry.load_yardoc(library.yardoc_file)
|
85
|
-
|
85
|
+
Thread.current[:__yard_last_yardoc__] = library.yardoc_file
|
86
86
|
end
|
87
87
|
|
88
88
|
def not_prepared
|
@@ -10,7 +10,7 @@ module YARD
|
|
10
10
|
# @param [String] text the raw tag text
|
11
11
|
# @return [Tag] a tag object with the tag_name and text values filled
|
12
12
|
def parse_tag(tag_name, text)
|
13
|
-
Tag.new(tag_name, text)
|
13
|
+
Tag.new(tag_name, text.strip)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Parses tag text and creates a new tag with a key name and descriptive text
|
data/lib/yard/tags/library.rb
CHANGED
@@ -9,8 +9,8 @@ module YARD
|
|
9
9
|
# be auto expanded into ruby code similar to what is shown in method #2. If you
|
10
10
|
# do not provide a factory method to use, it will default to {DefaultFactory#parse_tag}
|
11
11
|
# Example:
|
12
|
-
# define_tag :param, :with_types_and_name
|
13
|
-
# define_tag :author
|
12
|
+
# define_tag "Parameter", :param, :with_types_and_name
|
13
|
+
# define_tag "Author", :author
|
14
14
|
#
|
15
15
|
# The first line will expand to the code:
|
16
16
|
# def param_tag(text) tag_factory.parse_tag_with_types_and_name(text) end
|
@@ -50,12 +50,21 @@ module YARD::Templates::Helpers
|
|
50
50
|
case args.first
|
51
51
|
when %r{://}, /^mailto:/
|
52
52
|
link_url(args[0], args[1], {:target => '_parent'}.merge(args[2]||{}))
|
53
|
+
when /^include:file:(\S+)/
|
54
|
+
file = $1
|
55
|
+
if File.file?(file)
|
56
|
+
link_include_file(file)
|
57
|
+
else
|
58
|
+
log.warn "Cannot find file at `#{file}' for inclusion"
|
59
|
+
""
|
60
|
+
end
|
53
61
|
when /^include:(\S+)/
|
54
62
|
path = $1
|
55
63
|
if obj = YARD::Registry.resolve(object.namespace, path)
|
56
64
|
link_include_object(obj)
|
57
65
|
else
|
58
66
|
log.warn "Cannot find object at `#{path}' for inclusion"
|
67
|
+
""
|
59
68
|
end
|
60
69
|
when /^file:(\S+?)(?:#(\S+))?$/
|
61
70
|
link_file($1, args[1] ? args[1] : $1, $2)
|
@@ -69,9 +78,19 @@ module YARD::Templates::Helpers
|
|
69
78
|
|
70
79
|
# Includes an object's docstring into output.
|
71
80
|
# @since 0.6.0
|
81
|
+
# @param [CodeObjects::Base] object the object to include
|
82
|
+
# @return [String] the object's docstring (no tags)
|
72
83
|
def link_include_object(object)
|
73
84
|
object.docstring
|
74
85
|
end
|
86
|
+
|
87
|
+
# Include a file as a docstring in output
|
88
|
+
# @since 0.7.0
|
89
|
+
# @param [String] file the filename to include
|
90
|
+
# @return [String] the file's contents
|
91
|
+
def link_include_file(file)
|
92
|
+
File.read(file)
|
93
|
+
end
|
75
94
|
|
76
95
|
# Links to an object with an optional title
|
77
96
|
#
|
@@ -7,8 +7,6 @@ module YARD
|
|
7
7
|
include MarkupHelper
|
8
8
|
include HtmlSyntaxHighlightHelper
|
9
9
|
|
10
|
-
SimpleMarkupHtml = RDoc::Markup::ToHtml.new rescue SM::ToHtml.new
|
11
|
-
|
12
10
|
# @group Escaping Template Data
|
13
11
|
|
14
12
|
# Escapes HTML entities
|
@@ -80,8 +78,8 @@ module YARD
|
|
80
78
|
# @since 0.6.0
|
81
79
|
def html_markup_rdoc(text)
|
82
80
|
begin
|
83
|
-
|
84
|
-
html =
|
81
|
+
simple_markup_html.instance_variable_set("@from_path", url_for(object))
|
82
|
+
html = markup_class(:rdoc).new.convert(text, simple_markup_html)
|
85
83
|
end
|
86
84
|
|
87
85
|
html = fix_dash_dash(html)
|
@@ -113,11 +111,11 @@ module YARD
|
|
113
111
|
#
|
114
112
|
# @todo Refactor into own SimpleMarkup subclass
|
115
113
|
def fix_typewriter(text)
|
116
|
-
text.gsub(
|
117
|
-
type_text, pre_text, no_match = $1, $`, $&
|
118
|
-
pre_match = pre_text.scan(%r(</?(?:pre|tt|code)
|
119
|
-
if pre_match.last.nil? || pre_match.last
|
120
|
-
'<tt>' + h(type_text) + '</tt>'
|
114
|
+
text.gsub(/(\s|^|>)\+(?! )([^\n\+]{1,900})(?! )\+/) do
|
115
|
+
first_text, type_text, pre_text, no_match = $1, $2, $`, $&
|
116
|
+
pre_match = (pre_text+first_text).scan(%r(</?(?:(?:pre|tt|code).*?>|[^>]+)\Z))
|
117
|
+
if pre_match.last.nil? || pre_match.last[1,1] == '/'
|
118
|
+
first_text + '<tt>' + h(type_text) + '</tt>'
|
121
119
|
else
|
122
120
|
no_match
|
123
121
|
end
|
@@ -448,6 +446,21 @@ module YARD
|
|
448
446
|
|
449
447
|
private
|
450
448
|
|
449
|
+
# Gets the SimpleMarkup class for the local thread
|
450
|
+
#
|
451
|
+
# @return [RDoc::Markup::ToHtml] if RDoc 2.x is loaded
|
452
|
+
# @return [SM::ToHtml] if RDoc 1.x is loaded
|
453
|
+
# @since 0.6.5
|
454
|
+
def simple_markup_html
|
455
|
+
begin
|
456
|
+
require 'rdoc/markup/to_html'
|
457
|
+
rescue LoadError
|
458
|
+
require 'rdoc/markup/simple_markup/to_html'
|
459
|
+
end
|
460
|
+
Thread.current[:__yard_simple_markup_html__] ||=
|
461
|
+
(RDoc::Markup::ToHtml.new rescue SM::ToHtml.new)
|
462
|
+
end
|
463
|
+
|
451
464
|
# Converts a set of hash options into HTML attributes for a tag
|
452
465
|
#
|
453
466
|
# @param [Hash{String => String}] opts the tag options
|
@@ -7,6 +7,16 @@ module YARD
|
|
7
7
|
# @param [String] source the Ruby source code
|
8
8
|
# @return [String] the highlighted Ruby source
|
9
9
|
def html_syntax_highlight_ruby(source)
|
10
|
+
if Parser::SourceParser.parser_type == :ruby
|
11
|
+
html_syntax_highlight_ruby_ripper(source)
|
12
|
+
else
|
13
|
+
html_syntax_highlight_ruby_legacy(source)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def html_syntax_highlight_ruby_ripper(source)
|
10
20
|
tokenlist = Parser::Ruby::RubyParser.parse(source, "(syntax_highlight)").tokens
|
11
21
|
output = ""
|
12
22
|
tokenlist.each do |s|
|
@@ -25,6 +35,24 @@ module YARD
|
|
25
35
|
rescue Parser::ParserSyntaxError
|
26
36
|
h(source)
|
27
37
|
end
|
38
|
+
|
39
|
+
def html_syntax_highlight_ruby_legacy(source)
|
40
|
+
tokenlist = Parser::Ruby::Legacy::TokenList.new(source)
|
41
|
+
tokenlist.map do |s|
|
42
|
+
prettyclass = s.class.class_name.sub(/^Tk/, '').downcase
|
43
|
+
prettysuper = s.class.superclass.class_name.sub(/^Tk/, '').downcase
|
44
|
+
|
45
|
+
case s
|
46
|
+
when Parser::Ruby::Legacy::RubyToken::TkWhitespace, Parser::Ruby::Legacy::RubyToken::TkUnknownChar
|
47
|
+
h s.text
|
48
|
+
when Parser::Ruby::Legacy::RubyToken::TkId
|
49
|
+
prettyval = h(s.text)
|
50
|
+
"<span class='#{prettyval} #{prettyclass} #{prettysuper}'>#{prettyval}</span>"
|
51
|
+
else
|
52
|
+
"<span class='#{prettyclass} #{prettysuper}'>#{h s.text}</span>"
|
53
|
+
end
|
54
|
+
end.join
|
55
|
+
end
|
28
56
|
end
|
29
57
|
end
|
30
58
|
end
|
@@ -23,15 +23,18 @@ module YARD
|
|
23
23
|
MARKUP_PROVIDERS = {
|
24
24
|
:markdown => [
|
25
25
|
{:lib => :bluecloth, :const => 'BlueCloth'},
|
26
|
+
{:lib => :kramdown, :const => "Kramdown::Document"},
|
26
27
|
{:lib => :maruku, :const => 'Maruku'},
|
27
28
|
{:lib => :"rpeg-markdown", :const => "PEGMarkdown"},
|
28
|
-
{:lib => :rdiscount, :const => "RDiscount"}
|
29
|
-
{:lib => :kramdown, :const => "Kramdown::Document"}
|
29
|
+
{:lib => :rdiscount, :const => "RDiscount"}
|
30
30
|
],
|
31
31
|
:textile => [
|
32
32
|
{:lib => :redcloth, :const => 'RedCloth'}
|
33
33
|
],
|
34
|
-
:rdoc => [
|
34
|
+
:rdoc => [
|
35
|
+
{:lib => 'rdoc/markup', :const => 'RDoc::Markup'},
|
36
|
+
{:lib => 'rdoc/markup/simple_markup', :const => 'SM::SimpleMarkup'}
|
37
|
+
],
|
35
38
|
:text => [],
|
36
39
|
:html => []
|
37
40
|
}
|
@@ -52,32 +55,19 @@ module YARD
|
|
52
55
|
# files to detect the markup type.
|
53
56
|
MARKUP_FILE_SHEBANG = /\A#!(\S+)\s*$/
|
54
57
|
|
55
|
-
begin
|
56
|
-
require 'rdoc/markup'
|
57
|
-
require 'rdoc/markup/to_html'
|
58
|
-
SimpleMarkup = RDoc::Markup.new
|
59
|
-
rescue Gem::LoadError
|
60
|
-
raise
|
61
|
-
rescue LoadError
|
62
|
-
require 'rubygems'
|
63
|
-
require 'rdoc/markup/simple_markup'
|
64
|
-
require 'rdoc/markup/simple_markup/to_html'
|
65
|
-
SimpleMarkup = SM::SimpleMarkup.new
|
66
|
-
end
|
67
|
-
|
68
58
|
# Attempts to load the first valid markup provider in {MARKUP_PROVIDERS}.
|
69
59
|
# If a provider is specified, immediately try to load it.
|
70
60
|
#
|
71
61
|
# On success this sets `@markup_provider` and `@markup_class` to
|
72
62
|
# the provider name and library constant class/module respectively for
|
73
|
-
# the loaded
|
63
|
+
# the loaded provider.
|
74
64
|
#
|
75
65
|
# On failure this method will inform the user that no provider could be
|
76
66
|
# found and exit the program.
|
77
67
|
#
|
78
68
|
# @return [Boolean] whether the markup provider was successfully loaded.
|
79
69
|
def load_markup_provider(type = options[:markup])
|
80
|
-
return true if
|
70
|
+
return true if MarkupHelper.markup_cache[type]
|
81
71
|
MarkupHelper.markup_cache[type] ||= {}
|
82
72
|
|
83
73
|
providers = MARKUP_PROVIDERS[type]
|
@@ -87,15 +77,17 @@ module YARD
|
|
87
77
|
end
|
88
78
|
|
89
79
|
if providers == nil || providers.empty?
|
90
|
-
log.error "Invalid markup type '#{type}' or markup provider
|
80
|
+
log.error "Invalid markup type '#{type}' or markup provider " +
|
81
|
+
"(#{options[:markup_provider]}) is not registered."
|
91
82
|
return false
|
92
83
|
end
|
93
84
|
|
94
85
|
# Search for provider, return the library class name as const if found
|
95
86
|
providers.each do |provider|
|
96
87
|
begin require provider[:lib].to_s; rescue LoadError; next end
|
88
|
+
begin klass = eval("::" + provider[:const]); rescue NameError; next end
|
97
89
|
MarkupHelper.markup_cache[type][:provider] = provider[:lib] # Cache the provider
|
98
|
-
MarkupHelper.markup_cache[type][:class] =
|
90
|
+
MarkupHelper.markup_cache[type][:class] = klass
|
99
91
|
return true
|
100
92
|
end
|
101
93
|
|
@@ -145,7 +137,7 @@ module YARD
|
|
145
137
|
# @param [Symbol] the markup type (:rdoc, :markdown, etc.)
|
146
138
|
# @return [Class] the markup class
|
147
139
|
def markup_class(type = options[:markup])
|
148
|
-
|
140
|
+
MarkupHelper.markup_cache[type][:class]
|
149
141
|
end
|
150
142
|
|
151
143
|
# Gets the markup provider name for a markup type
|
@@ -154,7 +146,7 @@ module YARD
|
|
154
146
|
# @param [Symbol] the markup type (:rdoc, :markdown, etc.)
|
155
147
|
# @return [Symbol] the markup provider name (usually the gem name of the library)
|
156
148
|
def markup_provider(type = options[:markup])
|
157
|
-
|
149
|
+
MarkupHelper.markup_cache[type][:provider]
|
158
150
|
end
|
159
151
|
end
|
160
152
|
end
|