class YARD::Server::Commands::LibraryCommand
@abstract
See {Base} for notes on how to subclass a command.
command deals with libraries directly, subclass this class instead.
Some commands do not, but most (like {DisplayObjectCommand}) do. If your
This is the base command for all commands that deal directly with libraries.
def call(request)
def call(request) if can_fork? call_with_fork(request) { super } else begin save_default_template_info call_without_fork(request) { super } ensure restore_template_info end end end
def call_with_fork(request, &block)
def call_with_fork(request, &block) IO.pipe(:binmode => true) do |reader, writer| fork do log.debug "[pid=#{Process.pid}] fork serving: #{request.path}" reader.close writer.print(Marshal.dump(call_without_fork(request, &block))) end writer.close Marshal.load(reader.read) end end
def call_without_fork(request)
def call_without_fork(request) self.request = request self.options = LibraryOptions.new options.reset_defaults options.command = self setup_library options.title = "Documentation for #{library.name} " + (library.version ? '(' + library.version + ')' : '') yield rescue LibraryNotPreparedError not_prepared end
def can_fork?
def can_fork? CAN_FORK && use_fork end
def fulldoc_template
not do any rendering/generation. We need this to access the
Hack to load a custom fulldoc template object that does
def fulldoc_template tplopts = [options.template, :fulldoc, options.format] tplclass = Templates::Engine.template(*tplopts) obj = Object.new.extend(tplclass) class << obj; define_method(:init) {} end obj.class = tplclass obj.send(:initialize, options) class << obj attr_reader :contents define_method(:asset) {|_, contents| @contents = contents } end obj end
def initialize(opts = {})
def initialize(opts = {}) super self.serializer = DocServerSerializer.new end
def load_yardoc
def load_yardoc raise LibraryNotPreparedError unless library.ready? if Thread.current[:__yard_last_yardoc__] == library.yardoc_file log.debug "Reusing yardoc file: #{library.yardoc_file}" return end Registry.clear Templates::ErbCache.clear! Registry.load_yardoc(library.yardoc_file) Thread.current[:__yard_last_yardoc__] = library.yardoc_file end
def not_prepared
def not_prepared options.update(:template => :doc_server, :type => :processing) self.caching = false self.status = 202 self.body = render self.headers = {'Content-Type' => 'text/html'} [status, headers, [body]] end
def restore_template_info
def restore_template_info Templates::Engine.template_paths = @old_template_paths Templates::Template.extra_includes = @old_extra_includes end
def save_default_template_info
def save_default_template_info @old_template_paths = Templates::Engine.template_paths.dup @old_extra_includes = Templates::Template.extra_includes.dup end
def setup_library
def setup_library library.prepare! if request.xhr? && request.query['process'] load_yardoc setup_yardopts true end
def setup_yardopts
def setup_yardopts @@library_chdir_lock.synchronize do Dir.chdir(library.source_path) do yardoc = CLI::Yardoc.new if incremental yardoc.run('-c', '-n', '--no-stats') else yardoc.parse_arguments end yardoc.send(:verify_markup_options) yardoc.options.delete(:serializer) yardoc.options.delete(:serialize) options.update(yardoc.options.to_hash) end end end