class YARD::CLI::Display

Display one object @since 0.8.6

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/yard/cli/display.rb, line 8
def initialize(*args)
  super
  options.format = :text # default for this command
  @layout = nil
  @objects = []
end

Public Instance Methods

description() click to toggle source
# File lib/yard/cli/display.rb, line 6
def description; 'Displays a formatted object' end
format_objects() click to toggle source

@return [String] the output data for all formatted objects

# File lib/yard/cli/display.rb, line 26
def format_objects
  @objects.inject([]) do |arr, obj|
    arr.push obj.format(options)
  end.join("\n")
end
output_options(opts) click to toggle source
Calls superclass method
# File lib/yard/cli/display.rb, line 60
def output_options(opts)
  super(opts)
  opts.on('-l', '--layout [LAYOUT]', 'Wraps output in layout template (good for HTML)') do |layout|
    @layout = layout || 'layout'
  end
end
parse_arguments(*args) click to toggle source

Parses commandline options. @param [Array<String>] args each tokenized argument

# File lib/yard/cli/display.rb, line 45
def parse_arguments(*args)
  opts = OptionParser.new
  opts.banner = "Usage: yard display [options] OBJECT [OTHER OBJECTS]"
  general_options(opts)
  output_options(opts)
  parse_options(opts, args)

  Registry.load
  @objects = args.map {|o| Registry.at(o) }

  # validation
  return false if @objects.any? {|o| o.nil? }
  verify_markup_options
end
run(*args) click to toggle source

Runs the commandline utility, parsing arguments and displaying an object from the {Registry}.

@param [Array<String>] args the list of arguments. @return [void]

# File lib/yard/cli/display.rb, line 20
def run(*args)
  return unless parse_arguments(*args)
  log.puts wrap_layout(format_objects)
end
wrap_layout(contents) click to toggle source
# File lib/yard/cli/display.rb, line 32
def wrap_layout(contents)
  return contents unless @layout
  opts = options.merge(
    :contents => contents,
    :object => @objects.first,
    :objects => @objects
  )
  args = [options.template, @layout, options.format]
  Templates::Engine.template(*args).run(opts)
end