lib/yard/cli/server.rb in yard-0.7.5 vs lib/yard/cli/server.rb in yard-0.8.0
- old
+ new
@@ -21,23 +21,28 @@
# @return [Array<String>] a list of template paths to register
# @since 0.6.2
attr_accessor :template_paths
- def description
- "Runs a local documentation server"
- end
-
- def run(*args)
+ # Creates a new instance of the Server command line utility
+ def initialize
+ super
self.scripts = []
self.template_paths = []
self.libraries = {}
self.options = SymbolHash.new(false).update(
:single_library => true,
:caching => false
)
self.server_options = {:Port => 8808}
+ end
+
+ def description
+ "Runs a local documentation server"
+ end
+
+ def run(*args)
optparse(*args)
select_adapter.setup
load_scripts
load_template_paths
@@ -69,25 +74,40 @@
library, yardoc = args[index], args[index + 1]
yardoc ||= '.yardoc'
yardoc = File.expand_path(yardoc)
if File.exist?(yardoc)
libraries[library] ||= []
- libraries[library] << YARD::Server::LibraryVersion.new(library, nil, yardoc)
+ libraries[library] |= [YARD::Server::LibraryVersion.new(library, nil, yardoc)]
else
log.warn "Cannot find yardoc db for #{library}: #{yardoc}"
end
end
end
def add_gems
require 'rubygems'
Gem.source_index.find_name('').each do |spec|
libraries[spec.name] ||= []
- libraries[spec.name] << YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)
+ libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)]
end
end
+ def add_gems_from_gemfile(gemfile = nil)
+ require 'bundler'
+ gemfile ||= "Gemfile"
+ if File.exists?("#{gemfile}.lock")
+ Bundler::LockfileParser.new(File.read("#{gemfile}.lock")).specs.each do |spec|
+ libraries[spec.name] ||= []
+ libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)]
+ end
+ else
+ log.warn "Cannot find #{gemfile}.lock, ignoring --gemfile option"
+ end
+ rescue LoadError
+ log.error "Bundler not available, ignoring --gemfile option"
+ end
+
def optparse(*args)
opts = OptionParser.new
opts.banner = 'Usage: yard server [options] [[library yardoc_file] ...]'
opts.separator ''
opts.separator 'Example: yard server -m yard .yardoc ruby-core ../ruby/.yardoc'
@@ -106,9 +126,12 @@
opts.on('-r', '--reload', 'Reparses the library code on each request') do
options[:incremental] = true
end
opts.on('-g', '--gems', 'Serves documentation for installed gems') do
add_gems
+ end
+ opts.on('-G', '--gemfile [GEMFILE]', 'Serves documentation for gems from Gemfile') do |gemfile|
+ add_gems_from_gemfile(gemfile)
end
opts.on('-t', '--template-path PATH',
'The template path to look for templates in. (used with -t).') do |path|
self.template_paths << path
end