Class: YARD::CLI::Display

Inherits:
Yardoc show all
Defined in:
lib/yard/cli/display.rb

Overview

Display one object

Since:

  • 0.8.6

Constant Summary

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Display

Returns a new instance of Display

Since:

  • 0.8.6



8
9
10
11
12
13
# File 'lib/yard/cli/display.rb', line 8

def initialize(*args)
  super
  options.format = :text # default for this command
  @layout = nil
  @objects = []
end

Instance Attribute Details

#apisArray<String> Originally defined in class Yardoc

Keep track of which APIs are to be shown

Returns:

Since:

  • 0.8.1

#assetsArray<String> Originally defined in class Yardoc

Returns a list of assets to copy after generation

Returns:

  • (Array<String>)

    a list of assets to copy after generation

Since:

  • 0.6.0

#excludedArray<String> Originally defined in class Yardoc

Returns list of excluded paths (regexp matches)

Returns:

  • (Array<String>)

    list of excluded paths (regexp matches)

Since:

  • 0.5.3

#filesArray<String> Originally defined in class Yardoc

Returns list of Ruby source files to process

Returns:

  • (Array<String>)

    list of Ruby source files to process

Since:

  • 0.2.1

#generateBoolean Originally defined in class Yardoc

Returns whether to generate output

Returns:

  • (Boolean)

    whether to generate output

Since:

  • 0.2.1

#has_markupBoolean Originally defined in class Yardoc

Returns whether markup option was specified

Returns:

  • (Boolean)

    whether markup option was specified

Since:

  • 0.7.0

#hidden_apisArray<String> Originally defined in class Yardoc

Keep track of which APIs are to be hidden

Returns:

Since:

  • 0.8.7

#hidden_tagsArray<Symbol> Originally defined in class Yardoc

Returns a list of tags to hide from templates

Returns:

  • (Array<Symbol>)

    a list of tags to hide from templates

Since:

  • 0.6.0

#listBoolean Originally defined in class Yardoc

Returns whether to print a list of objects

Returns:

  • (Boolean)

    whether to print a list of objects

Since:

  • 0.5.5

#optionsHash (readonly) Originally defined in class Yardoc

Returns the hash of options passed to the template.

Returns:

  • (Hash)

    the hash of options passed to the template.

See Also:

  • Templates::Engine#render

Since:

  • 0.2.1

#options_fileString Originally defined in class YardoptsCommand

The options file name (defaults to DEFAULT_YARDOPTS_FILE)

Returns:

  • (String)

    the filename to load extra options from

Since:

  • 0.8.3

#save_yardocBoolean Originally defined in class Yardoc

Returns whether objects should be serialized to .yardoc db

Returns:

  • (Boolean)

    whether objects should be serialized to .yardoc db

Since:

  • 0.2.1

#statisticsBoolean Originally defined in class Yardoc

Returns whether to print statistics after parsing

Returns:

  • (Boolean)

    whether to print statistics after parsing

Since:

  • 0.6.0

#use_cacheBoolean Originally defined in class Yardoc

Returns whether to use the existing yardoc db if the .yardoc already exists. Also makes use of file checksums to parse only changed files.

Returns:

  • (Boolean)

    whether to use the existing yardoc db if the .yardoc already exists. Also makes use of file checksums to parse only changed files.

Since:

  • 0.2.1

#use_document_fileBoolean Originally defined in class YardoptsCommand

Returns whether to parse options from .document

Returns:

  • (Boolean)

    whether to parse options from .document

Since:

  • 0.8.3

#use_yardopts_fileBoolean Originally defined in class YardoptsCommand

Returns whether to parse options from .yardopts

Returns:

  • (Boolean)

    whether to parse options from .yardopts

Since:

  • 0.8.3

#visibilitiesArray<Symbol> Originally defined in class Yardoc

Keep track of which visibilities are to be shown

Returns:

  • (Array<Symbol>)

    a list of visibilities

Since:

  • 0.5.6

Instance Method Details

#descriptionObject

Since:

  • 0.8.6



6
# File 'lib/yard/cli/display.rb', line 6

def description; 'Displays a formatted object' end

#format_objectsString

Returns the output data for all formatted objects

Returns:

  • (String)

    the output data for all formatted objects

Since:

  • 0.8.6



26
27
28
29
30
# 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) ⇒ Object

Since:

  • 0.8.6



60
61
62
63
64
65
# 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) ⇒ Object

Parses commandline options.

Parameters:

Since:

  • 0.8.6



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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) ⇒ void

This method returns an undefined value.

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

Parameters:

Since:

  • 0.8.6



20
21
22
23
# 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) ⇒ Object

Since:

  • 0.8.6



32
33
34
35
36
37
38
39
40
41
# 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