yard 0.5.8 → 0.6.0
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/.yardopts +2 -0
- data/ChangeLog +1064 -0
- data/README.md +103 -42
- data/Rakefile +3 -2
- data/benchmarks/parsing.rb +2 -1
- data/bin/yard +4 -0
- data/bin/yard-graph +1 -1
- data/bin/yard-server +4 -0
- data/docs/GettingStarted.md +8 -8
- data/docs/Handlers.md +5 -5
- data/docs/Overview.md +5 -5
- data/docs/Parser.md +1 -1
- data/docs/Tags.md +1 -1
- data/docs/Templates.md +27 -6
- data/docs/WhatsNew.md +222 -2
- data/lib/rubygems_plugin.rb +1 -0
- data/lib/yard.rb +7 -1
- data/lib/yard/autoload.rb +46 -6
- data/lib/yard/cli/{base.rb → command.rb} +20 -6
- data/lib/yard/cli/command_parser.rb +87 -0
- data/lib/yard/cli/diff.rb +176 -0
- data/lib/yard/cli/gems.rb +74 -0
- data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
- data/lib/yard/cli/help.rb +18 -0
- data/lib/yard/cli/server.rb +137 -0
- data/lib/yard/cli/stats.rb +210 -0
- data/lib/yard/cli/yardoc.rb +315 -116
- data/lib/yard/cli/yri.rb +45 -4
- data/lib/yard/code_objects/base.rb +73 -30
- data/lib/yard/code_objects/class_object.rb +9 -1
- data/lib/yard/code_objects/method_object.rb +11 -0
- data/lib/yard/code_objects/namespace_object.rb +8 -2
- data/lib/yard/code_objects/proxy.rb +2 -2
- data/lib/yard/core_ext/array.rb +3 -49
- data/lib/yard/core_ext/file.rb +7 -0
- data/lib/yard/core_ext/insertion.rb +60 -0
- data/lib/yard/docstring.rb +34 -7
- data/lib/yard/globals.rb +2 -2
- data/lib/yard/handlers/base.rb +101 -20
- data/lib/yard/handlers/processor.rb +23 -7
- data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
- data/lib/yard/handlers/ruby/base.rb +71 -2
- data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
- data/lib/yard/handlers/ruby/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
- data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
- data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_handler.rb +5 -1
- data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/process_handler.rb +7 -1
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
- data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
- data/lib/yard/logging.rb +7 -1
- data/lib/yard/parser/base.rb +1 -0
- data/lib/yard/parser/c_parser.rb +2 -0
- data/lib/yard/parser/ruby/ast_node.rb +82 -63
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
- data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
- data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
- data/lib/yard/parser/source_parser.rb +6 -1
- data/lib/yard/registry.rb +284 -278
- data/lib/yard/registry_store.rb +4 -2
- data/lib/yard/serializers/base.rb +30 -13
- data/lib/yard/serializers/file_system_serializer.rb +10 -1
- data/lib/yard/server/adapter.rb +51 -0
- data/lib/yard/server/commands/base.rb +98 -0
- data/lib/yard/server/commands/display_file_command.rb +20 -0
- data/lib/yard/server/commands/display_object_command.rb +50 -0
- data/lib/yard/server/commands/frames_command.rb +31 -0
- data/lib/yard/server/commands/library_command.rb +83 -0
- data/lib/yard/server/commands/library_index_command.rb +23 -0
- data/lib/yard/server/commands/list_command.rb +44 -0
- data/lib/yard/server/commands/search_command.rb +67 -0
- data/lib/yard/server/commands/static_file_command.rb +45 -0
- data/lib/yard/server/doc_server_helper.rb +22 -0
- data/lib/yard/server/doc_server_serializer.rb +29 -0
- data/lib/yard/server/library_version.rb +86 -0
- data/lib/yard/server/rack_adapter.rb +38 -0
- data/lib/yard/server/router.rb +110 -0
- data/lib/yard/server/static_caching.rb +16 -0
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
- data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
- data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
- data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
- data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
- data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
- data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
- data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
- data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
- data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
- data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
- data/lib/yard/server/webrick_adapter.rb +38 -0
- data/lib/yard/tags/default_factory.rb +0 -5
- data/lib/yard/tags/library.rb +61 -22
- data/lib/yard/tags/tag.rb +26 -4
- data/lib/yard/templates/engine.rb +12 -1
- data/lib/yard/templates/erb_cache.rb +2 -1
- data/lib/yard/templates/helpers/base_helper.rb +96 -3
- data/lib/yard/templates/helpers/filter_helper.rb +5 -0
- data/lib/yard/templates/helpers/html_helper.rb +204 -94
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
- data/lib/yard/templates/helpers/markup_helper.rb +58 -3
- data/lib/yard/templates/helpers/method_helper.rb +7 -0
- data/lib/yard/templates/helpers/module_helper.rb +5 -0
- data/lib/yard/templates/helpers/text_helper.rb +10 -1
- data/lib/yard/templates/helpers/uml_helper.rb +13 -0
- data/lib/yard/templates/section.rb +106 -0
- data/lib/yard/templates/template.rb +20 -19
- data/lib/yard/verifier.rb +21 -2
- data/spec/cli/command_parser_spec.rb +43 -0
- data/spec/cli/diff_spec.rb +170 -0
- data/spec/cli/help_spec.rb +22 -0
- data/spec/cli/server_spec.rb +140 -0
- data/spec/cli/stats_spec.rb +75 -0
- data/spec/cli/yardoc_spec.rb +438 -182
- data/spec/cli/yri_spec.rb +13 -1
- data/spec/code_objects/base_spec.rb +51 -6
- data/spec/code_objects/class_object_spec.rb +15 -1
- data/spec/code_objects/method_object_spec.rb +29 -0
- data/spec/code_objects/namespace_object_spec.rb +150 -129
- data/spec/core_ext/array_spec.rb +4 -23
- data/spec/core_ext/insertion_spec.rb +37 -0
- data/spec/docstring_spec.rb +63 -0
- data/spec/handlers/attribute_handler_spec.rb +4 -0
- data/spec/handlers/base_spec.rb +98 -26
- data/spec/handlers/class_handler_spec.rb +5 -1
- data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
- data/spec/handlers/method_handler_spec.rb +5 -0
- data/spec/handlers/module_handler_spec.rb +4 -0
- data/spec/handlers/visibility_handler_spec.rb +6 -0
- data/spec/parser/source_parser_spec.rb +24 -0
- data/spec/registry_spec.rb +44 -8
- data/spec/server/adapter_spec.rb +38 -0
- data/spec/server/commands/base_spec.rb +87 -0
- data/spec/server/commands/static_file_command_spec.rb +67 -0
- data/spec/server/doc_server_serializer_spec.rb +58 -0
- data/spec/server/router_spec.rb +115 -0
- data/spec/server/spec_helper.rb +17 -0
- data/spec/server/static_caching_spec.rb +39 -0
- data/spec/server/webrick_servlet_spec.rb +20 -0
- data/spec/templates/constant_spec.rb +40 -0
- data/spec/templates/engine_spec.rb +9 -5
- data/spec/templates/examples/class002.html +1 -3
- data/spec/templates/examples/constant001.txt +25 -0
- data/spec/templates/examples/constant002.txt +7 -0
- data/spec/templates/examples/constant003.txt +11 -0
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/examples/module002.html +319 -0
- data/spec/templates/helpers/base_helper_spec.rb +2 -2
- data/spec/templates/helpers/html_helper_spec.rb +93 -3
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
- data/spec/templates/helpers/markup_helper_spec.rb +94 -67
- data/spec/templates/helpers/shared_signature_examples.rb +9 -0
- data/spec/templates/helpers/text_helper_spec.rb +12 -0
- data/spec/templates/module_spec.rb +21 -4
- data/spec/templates/section_spec.rb +146 -0
- data/spec/templates/template_spec.rb +9 -20
- data/templates/default/class/setup.rb +5 -5
- data/templates/default/constant/text/header.erb +11 -0
- data/templates/default/constant/text/setup.rb +3 -0
- data/templates/default/fulldoc/html/css/style.css +29 -3
- data/templates/default/fulldoc/html/js/app.js +67 -1
- data/templates/default/fulldoc/html/js/full_list.js +3 -8
- data/templates/default/fulldoc/html/js/jquery.js +150 -15
- data/templates/default/fulldoc/html/setup.rb +9 -0
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/layout/html/setup.rb +7 -25
- data/templates/default/method_details/html/source.erb +1 -1
- data/templates/default/module/html/attribute_summary.erb +2 -2
- data/templates/default/module/html/method_summary.erb +2 -2
- data/templates/default/module/setup.rb +27 -4
- data/templates/default/onefile/html/files.erb +5 -0
- data/templates/default/onefile/html/layout.erb +22 -0
- data/templates/default/onefile/html/readme.erb +3 -0
- data/templates/default/onefile/html/setup.rb +40 -0
- data/templates/default/root/html/setup.rb +1 -0
- data/templates/default/tags/setup.rb +26 -33
- metadata +80 -10
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module YARD
|
6
|
+
module CLI
|
7
|
+
# CLI command to return the objects that were added/removed from 2 versions
|
8
|
+
# of a project (library, gem, working copy).
|
9
|
+
# @since 0.6.0
|
10
|
+
class Diff < Command
|
11
|
+
def initialize
|
12
|
+
require_rubygems
|
13
|
+
super
|
14
|
+
@list_all = false
|
15
|
+
log.show_backtraces = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
'Returns the object diff of two gems or .yardoc files'
|
20
|
+
end
|
21
|
+
|
22
|
+
def run(*args)
|
23
|
+
registry = optparse(*args).map do |gemfile|
|
24
|
+
if load_gem_data(gemfile)
|
25
|
+
log.info "Found #{gemfile}"
|
26
|
+
Registry.all.map {|o| o.path }
|
27
|
+
else
|
28
|
+
log.error "Cannot find gem #{gemfile}"
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end.compact
|
32
|
+
|
33
|
+
return if registry.size != 2
|
34
|
+
|
35
|
+
[ ["Added objects", registry[1] - registry[0]],
|
36
|
+
["Removed objects", registry[0] - registry[1]]].each do |name, objects|
|
37
|
+
next if objects.empty?
|
38
|
+
last_object = nil
|
39
|
+
all_objects_notice = false
|
40
|
+
puts name + ":"
|
41
|
+
objects.sort.each do |object|
|
42
|
+
if !@list_all && last_object && object =~ /#{Regexp.quote last_object}(::|\.|#)/
|
43
|
+
print " (...)" unless all_objects_notice
|
44
|
+
all_objects_notice = true
|
45
|
+
next
|
46
|
+
else
|
47
|
+
puts
|
48
|
+
end
|
49
|
+
all_objects_notice = false
|
50
|
+
print " " + object
|
51
|
+
last_object = object
|
52
|
+
end
|
53
|
+
puts
|
54
|
+
puts
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def load_gem_data(gemfile)
|
61
|
+
Registry.clear
|
62
|
+
|
63
|
+
# First check for argument as .yardoc file
|
64
|
+
[File.join(gemfile, '.yardoc'), gemfile].each do |yardoc|
|
65
|
+
log.info "Searching for .yardoc db at #{yardoc}"
|
66
|
+
if File.directory?(yardoc)
|
67
|
+
Registry.load_yardoc(yardoc)
|
68
|
+
Registry.load_all
|
69
|
+
return true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Next check installed RubyGems
|
74
|
+
gemfile_without_ext = gemfile.sub(/\.gem$/, '')
|
75
|
+
log.info "Searching for installed gem #{gemfile_without_ext}"
|
76
|
+
Gem.source_index.find_name('').find do |spec|
|
77
|
+
if spec.full_name == gemfile_without_ext
|
78
|
+
if yardoc = Registry.yardoc_file_for_gem(spec.name, "= #{spec.version}")
|
79
|
+
Registry.load_yardoc(yardoc)
|
80
|
+
Registry.load_all
|
81
|
+
else
|
82
|
+
log.enter_level(Logger::ERROR) do
|
83
|
+
olddir = Dir.pwd
|
84
|
+
Gems.run(spec.name, spec.version.to_s)
|
85
|
+
Dir.chdir(olddir)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
return true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Look for local .gem file
|
93
|
+
gemfile += '.gem' unless gemfile =~ /\.gem$/
|
94
|
+
log.info "Searching for local gem file #{gemfile}"
|
95
|
+
if File.exist?(gemfile)
|
96
|
+
File.open(gemfile, 'rb') do |io|
|
97
|
+
expand_and_parse(gemfile, io)
|
98
|
+
end
|
99
|
+
return true
|
100
|
+
end
|
101
|
+
|
102
|
+
# Remote gemfile from rubygems.org
|
103
|
+
url = "http://rubygems.org/downloads/#{gemfile}"
|
104
|
+
log.info "Searching for remote gem file #{url}"
|
105
|
+
begin
|
106
|
+
open(url) {|io| expand_and_parse(gemfile, io) }
|
107
|
+
return true
|
108
|
+
rescue OpenURI::HTTPError
|
109
|
+
end
|
110
|
+
false
|
111
|
+
end
|
112
|
+
|
113
|
+
def expand_and_parse(gemfile, io)
|
114
|
+
dir = expand_gem(gemfile, io)
|
115
|
+
generate_yardoc(dir)
|
116
|
+
cleanup(gemfile)
|
117
|
+
end
|
118
|
+
|
119
|
+
def generate_yardoc(dir)
|
120
|
+
olddir = Dir.pwd
|
121
|
+
Dir.chdir(dir)
|
122
|
+
log.enter_level(Logger::ERROR) { Yardoc.run('-n', '--no-save') }
|
123
|
+
Dir.chdir(olddir)
|
124
|
+
end
|
125
|
+
|
126
|
+
def expand_gem(gemfile, io)
|
127
|
+
tmpdir = File.join(Dir.tmpdir, gemfile)
|
128
|
+
log.info "Expanding #{gemfile} to #{tmpdir}..."
|
129
|
+
FileUtils.mkdir_p(tmpdir)
|
130
|
+
Gem::Package.open(io) do |pkg|
|
131
|
+
pkg.each do |entry|
|
132
|
+
pkg.extract_entry(tmpdir, entry)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
tmpdir
|
136
|
+
end
|
137
|
+
|
138
|
+
def require_rubygems
|
139
|
+
require 'rubygems'
|
140
|
+
require 'rubygems/package'
|
141
|
+
rescue LoadError => e
|
142
|
+
log.error "Missing RubyGems, cannot run this command."
|
143
|
+
raise(e)
|
144
|
+
end
|
145
|
+
|
146
|
+
def cleanup(gemfile)
|
147
|
+
dir = File.join(Dir.tmpdir, gemfile)
|
148
|
+
log.info "Cleaning up #{dir}..."
|
149
|
+
FileUtils.rm_rf(dir)
|
150
|
+
end
|
151
|
+
|
152
|
+
def optparse(*args)
|
153
|
+
opts = OptionParser.new
|
154
|
+
opts.banner = "Usage: yard diff [options] oldgem newgem"
|
155
|
+
opts.separator ""
|
156
|
+
opts.separator "Example: yard diff yard-0.5.6 yard-0.5.8"
|
157
|
+
opts.separator ""
|
158
|
+
opts.separator "If the files don't exist locally, they will be grabbed using the `gem fetch`"
|
159
|
+
opts.separator "command. If the gem is a .yardoc directory, it will be used. Finally, if the"
|
160
|
+
opts.separator "gem name matches an installed gem (full name-version syntax), that gem will be used."
|
161
|
+
|
162
|
+
opts.on('-a', '--all', 'List all objects, even if they are inside added/removed module/class') do
|
163
|
+
@list_all = true
|
164
|
+
end
|
165
|
+
common_options(opts)
|
166
|
+
parse_options(opts, args)
|
167
|
+
unless args.size == 2
|
168
|
+
puts opts.banner
|
169
|
+
exit(0)
|
170
|
+
end
|
171
|
+
|
172
|
+
args
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module YARD
|
2
|
+
module CLI
|
3
|
+
# @since 0.6.0
|
4
|
+
class Gems < Command
|
5
|
+
def initialize
|
6
|
+
@rebuild = false
|
7
|
+
@gems = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def description; "Builds YARD index for gems" end
|
11
|
+
|
12
|
+
# Runs the commandline utility, parsing arguments and generating
|
13
|
+
# YARD indexes for gems.
|
14
|
+
#
|
15
|
+
# @param [Array<String>] args the list of arguments
|
16
|
+
# @return [void]
|
17
|
+
def run(*args)
|
18
|
+
optparse(*args)
|
19
|
+
@gems += Gem.source_index.find_name('') if @gems.empty?
|
20
|
+
build_gems
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Builds .yardoc files for all non-existing gems
|
26
|
+
# @param [Array] gems
|
27
|
+
def build_gems
|
28
|
+
require 'rubygems'
|
29
|
+
@gems.each do |spec|
|
30
|
+
ver = "= #{spec.version}"
|
31
|
+
dir = Registry.yardoc_file_for_gem(spec.name, ver)
|
32
|
+
if dir && File.directory?(dir) && !@rebuild
|
33
|
+
log.debug "#{spec.name} index already exists at '#{dir}'"
|
34
|
+
else
|
35
|
+
yfile = Registry.yardoc_file_for_gem(spec.name, ver, true)
|
36
|
+
next unless yfile
|
37
|
+
next unless File.directory?(spec.full_gem_path)
|
38
|
+
Registry.clear
|
39
|
+
Dir.chdir(spec.full_gem_path)
|
40
|
+
log.info "Building yardoc index for gem: #{spec.full_name}"
|
41
|
+
Yardoc.run('--no-stats', '-n', '-b', yfile)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_gems(gems)
|
47
|
+
gems.each_slice(2) do |gem, ver_require|
|
48
|
+
specs = Gem.source_index.find_name(gem, ver_require || ">= 0")
|
49
|
+
@gems += specs unless specs.empty?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Parses options
|
54
|
+
def optparse(*args)
|
55
|
+
opts = OptionParser.new
|
56
|
+
opts.banner = 'Usage: yard gems [options] [gem_name [version]]'
|
57
|
+
opts.separator ""
|
58
|
+
opts.separator "#{description}. If no gem_name is given,"
|
59
|
+
opts.separator "all gems are built."
|
60
|
+
opts.separator ""
|
61
|
+
opts.on('--rebuild', 'Rebuilds index') do
|
62
|
+
@rebuild = true
|
63
|
+
end
|
64
|
+
opts.on('--legacy', 'Use old style parser and handlers. Unavailable under Ruby 1.8.x') do
|
65
|
+
YARD::Parser::SourceParser.parser_type = :ruby18
|
66
|
+
end
|
67
|
+
|
68
|
+
common_options(opts)
|
69
|
+
parse_options(opts, args)
|
70
|
+
add_gems(args)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -3,8 +3,9 @@ module YARD
|
|
3
3
|
# A command-line utility to generate Graphviz graphs from
|
4
4
|
# a set of objects
|
5
5
|
#
|
6
|
-
# @see
|
7
|
-
|
6
|
+
# @see Graph#run
|
7
|
+
# @since 0.6.0
|
8
|
+
class Graph < Command
|
8
9
|
# The options parsed out of the commandline.
|
9
10
|
# Default options are:
|
10
11
|
# :format => :dot
|
@@ -13,10 +14,6 @@ module YARD
|
|
13
14
|
# The set of objects to include in the graph.
|
14
15
|
attr_reader :objects
|
15
16
|
|
16
|
-
# Helper method to run the utility on an instance.
|
17
|
-
# @see #run
|
18
|
-
def self.run(*args) new.run(*args) end
|
19
|
-
|
20
17
|
# Creates a new instance of the command-line utility
|
21
18
|
def initialize
|
22
19
|
super
|
@@ -24,10 +21,14 @@ module YARD
|
|
24
21
|
@options = SymbolHash[:format => :dot]
|
25
22
|
end
|
26
23
|
|
24
|
+
def description
|
25
|
+
"Graphs class diagram using Graphviz"
|
26
|
+
end
|
27
|
+
|
27
28
|
# Runs the command-line utility.
|
28
29
|
#
|
29
30
|
# @example
|
30
|
-
# grapher =
|
31
|
+
# grapher = Graph.new
|
31
32
|
# grapher.run('--private')
|
32
33
|
# @param [Array<String>] args each tokenized argument
|
33
34
|
def run(*args)
|
@@ -90,7 +91,7 @@ module YARD
|
|
90
91
|
common_options(opts)
|
91
92
|
parse_options(opts, args)
|
92
93
|
|
93
|
-
@verifier =
|
94
|
+
@verifier = Verifier.new("object.type != :method || #{visibilities.uniq.inspect}.include?(object.visibility)")
|
94
95
|
if args.first
|
95
96
|
@objects = args.map {|o| Registry.at(o) }.compact
|
96
97
|
else
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module YARD
|
2
|
+
module CLI
|
3
|
+
# Handles help for commands
|
4
|
+
# @since 0.6.0
|
5
|
+
class Help < Command
|
6
|
+
def description; "Retrieves help for a command" end
|
7
|
+
|
8
|
+
def run(*args)
|
9
|
+
if args.first && cmd = CommandParser.commands[args.first.to_sym]
|
10
|
+
cmd.run('--help')
|
11
|
+
else
|
12
|
+
puts "Command #{args.first} not found." if args.first
|
13
|
+
CommandParser.run('--help')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module YARD
|
2
|
+
module CLI
|
3
|
+
# A local documentation server
|
4
|
+
# @since 0.6.0
|
5
|
+
class Server < Command
|
6
|
+
# @return [Hash] a list of options to pass to the doc server
|
7
|
+
attr_accessor :options
|
8
|
+
|
9
|
+
# @return [Hash] a list of options to pass to the web server
|
10
|
+
attr_accessor :server_options
|
11
|
+
|
12
|
+
# @return [Hash] a list of library names and yardoc files to serve
|
13
|
+
attr_accessor :libraries
|
14
|
+
|
15
|
+
# @return [Adapter] the adapter to use for loading the web server
|
16
|
+
attr_accessor :adapter
|
17
|
+
|
18
|
+
def description
|
19
|
+
"Runs a local documentation server"
|
20
|
+
end
|
21
|
+
|
22
|
+
def run(*args)
|
23
|
+
self.libraries = {}
|
24
|
+
self.options = SymbolHash.new(false).update(
|
25
|
+
:single_library => true,
|
26
|
+
:caching => false
|
27
|
+
)
|
28
|
+
self.server_options = {:Port => 8808}
|
29
|
+
optparse(*args)
|
30
|
+
|
31
|
+
select_adapter
|
32
|
+
adapter.new(libraries, options, server_options).start
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def select_adapter
|
38
|
+
return adapter if adapter
|
39
|
+
require 'rubygems'
|
40
|
+
require 'rack'
|
41
|
+
self.adapter = YARD::Server::RackAdapter
|
42
|
+
rescue LoadError
|
43
|
+
self.adapter = YARD::Server::WebrickAdapter
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_libraries(args)
|
47
|
+
(0...args.size).step(2) do |index|
|
48
|
+
library, yardoc = args[index], args[index + 1]
|
49
|
+
yardoc ||= '.yardoc'
|
50
|
+
if File.exist?(yardoc)
|
51
|
+
libraries[library] ||= []
|
52
|
+
libraries[library] << YARD::Server::LibraryVersion.new(library, nil, yardoc)
|
53
|
+
else
|
54
|
+
log.warn "Cannot find yardoc db for #{library}: #{yardoc}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_gems
|
60
|
+
require 'rubygems'
|
61
|
+
Gem.source_index.find_name('').each do |spec|
|
62
|
+
libraries[spec.name] ||= []
|
63
|
+
libraries[spec.name] << YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def optparse(*args)
|
68
|
+
opts = OptionParser.new
|
69
|
+
opts.banner = 'Usage: yard server [options] [[library yardoc_file] ...]'
|
70
|
+
opts.separator ''
|
71
|
+
opts.separator 'Example: yard server yard .yardoc ruby-core ../ruby/.yardoc'
|
72
|
+
opts.separator 'The above example serves documentation for YARD and Ruby-core'
|
73
|
+
opts.separator ''
|
74
|
+
opts.separator 'If no library/yardoc_file is specified, the server uses'
|
75
|
+
opts.separator 'the name of the current directory and `.yardoc` respectively'
|
76
|
+
opts.separator ''
|
77
|
+
opts.separator "General Options:"
|
78
|
+
opts.on('-e', '--load FILE', 'A Ruby script to load before the source tree is parsed.') do |file|
|
79
|
+
if !require(file.gsub(/\.rb$/, ''))
|
80
|
+
log.error "The file `#{file}' was already loaded, perhaps you need to specify the absolute path to avoid name collisions."
|
81
|
+
exit
|
82
|
+
end
|
83
|
+
end
|
84
|
+
opts.on('-m', '--multi-library', 'Serves documentation for multiple libraries') do
|
85
|
+
options[:single_library] = false
|
86
|
+
end
|
87
|
+
opts.on('-c', '--cache', 'Caches all documentation to document root (see --docroot)') do
|
88
|
+
options[:caching] = true
|
89
|
+
end
|
90
|
+
opts.on('-r', '--reload', 'Reparses the library code on each request') do
|
91
|
+
options[:incremental] = true
|
92
|
+
end
|
93
|
+
opts.on('-g', '--gems', 'Serves documentation for installed gems') do
|
94
|
+
add_gems
|
95
|
+
end
|
96
|
+
opts.separator ''
|
97
|
+
opts.separator "Web Server Options:"
|
98
|
+
opts.on('-d', '--daemon', 'Daemonizes the server process') do
|
99
|
+
server_options[:daemonize] = true
|
100
|
+
end
|
101
|
+
opts.on('-p PORT', '--port', 'Serves documentation on PORT') do |port|
|
102
|
+
server_options[:Port] = port.to_i
|
103
|
+
end
|
104
|
+
opts.on('--docroot DOCROOT', 'Uses DOCROOT as document root') do |docroot|
|
105
|
+
server_options[:DocumentRoot] = File.expand_path(docroot)
|
106
|
+
end
|
107
|
+
opts.on('-a', '--adapter ADAPTER', 'Use the ADAPTER (full Ruby class) for web server') do |adapter|
|
108
|
+
if adapter.downcase == 'webrick'
|
109
|
+
self.adapter = YARD::Server::WebrickAdapter
|
110
|
+
elsif adapter.downcase == 'rack'
|
111
|
+
self.adapter = YARD::Server::RackAdapter
|
112
|
+
else
|
113
|
+
self.adapter = eval(adapter)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
opts.on('-s', '--server TYPE', 'Use a specific server type eg. thin,mongrel,cgi (Rack specific)') do |type|
|
117
|
+
server_options[:server] = type
|
118
|
+
end
|
119
|
+
common_options(opts)
|
120
|
+
parse_options(opts, args)
|
121
|
+
|
122
|
+
if args.empty? && libraries.empty?
|
123
|
+
if !File.exist?('.yardoc')
|
124
|
+
log.enter_level(Logger::INFO) do
|
125
|
+
log.info "No .yardoc file found in current directory, parsing source before starting server..."
|
126
|
+
end
|
127
|
+
Yardoc.run('-n')
|
128
|
+
end
|
129
|
+
add_libraries([File.basename(Dir.pwd), '.yardoc'])
|
130
|
+
else
|
131
|
+
add_libraries(args)
|
132
|
+
options[:single_library] = false if libraries.size > 1
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|