Class: YARD::CLI::Yardoc
Overview
Yardoc is the default YARD CLI command (+yard doc+ and historic yardoc
executable) used to generate and output (mainly) HTML documentation given a set of source files.
Usage
Main usage for this command is:
$ yardoc [options] [source_files [- extra_files]]
See yardoc –help for details on valid options.
Options File (.yardopts
)
If a .yardopts
file is found in the source directory being processed, YARD will use the contents of the file as arguments to the command, treating newlines as spaces. You can use shell-style quotations to group space delimited arguments, just like on the command line.
A valid .yardopts
file might look like:
--no-private
--title "My Title"
--exclude foo --exclude bar
lib/**/*.erb
lib/**/*.rb -
HACKING.rdoc LEGAL COPYRIGHT
Note that Yardoc also supports the legacy RDoc style .document
file, though this file can only specify source globs to parse, not options.
Queries (--query
)
Yardoc supports queries to select specific code objects for which to generate documentation. For example, you might want to generate documentation only for your public API. If you’ve documented your public methods with @api public, you can use the following query to select all of these objects:
--query '@api.text == "public"'
Note that the syntax for queries is mostly Ruby with a few syntactic simplifications for meta-data tags. See the Verifier class for an overview of this syntax.
Adding Custom Ad-Hoc Meta-data Tags (--tag
)
YARD allows specification of meta-data tags programmatically via the Tags::Library class, but often this is not practical for users writing documentation. To make adding custom tags easier, Yardoc has a few command-line switches for creating basic tags and displaying them in generated HTML output.
To specify a custom tag to be displayed in output, use any of the following:
-
--tag
TAG:TITLE -
--name-tag
TAG:TITLE -
--type-tag
TAG:TITLE -
--type-name-tag
TAG:TITLE -
--title-tag
TAG:TITLE
“TAG:TITLE” is of the form: name:“Display Title”, for example:
--tag overload:"Overloaded Method"
See yardoc –help for a description of the various options.
Tags added in this way are automatically displayed in output. To add a meta-data tag that does not show up in output, use –hide-tag TAG. Note that you can also use this option on existing tags to hide builtin tags, for instance.
Processed Data Storage (.yardoc
directory)
When Yardoc parses a source directory, it creates a .yardoc
directory (by default, override with -b
) at the root of the project. This directory contains marshal dumps for all raw object data in the source, so that you can access it later for various commands (stats
, graph
, etc.). This directory is also used as a cache for any future calls to yardoc
so as to process only the files which have changed since the last call.
When Yardoc uses the cache in subsequent calls to yardoc
, methods or classes that have been deleted from source since the last parsing will not be erased from the cache (YARD never deletes objects). In such a case, you should wipe the cache and do a clean parsing of the source tree. You can do this by deleting the .yardoc
directory manually, or running Yardoc without --use-cache
(-c
).
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_YARDOPTS_FILE =
The configuration filename to load extra options from
".yardopts"
Instance Attribute Summary collapse
-
#assets ⇒ Array<String>
A list of assets to copy after generation.
-
#excluded ⇒ Array<String>
List of excluded paths (regexp matches).
-
#files ⇒ Array<String>
List of Ruby source files to process.
-
#generate ⇒ Boolean
Whether to generate output.
-
#hidden_tags ⇒ Array<Symbol>
A list of tags to hide from templates.
-
#list ⇒ Boolean
Whether to print a list of objects.
-
#options ⇒ Hash
readonly
The hash of options passed to the template.
-
#options_file ⇒ String
The options file name (defaults to DEFAULT_YARDOPTS_FILE).
-
#save_yardoc ⇒ Boolean
Whether objects should be serialized to .yardoc db.
-
#statistics ⇒ Boolean
Whether to print statistics after parsing.
-
#use_cache ⇒ Boolean
Whether to use the existing yardoc db if the .yardoc already exists.
-
#use_document_file ⇒ Boolean
Whether to parse options from .document.
-
#use_yardopts_file ⇒ Boolean
Whether to parse options from .yardopts.
-
#visibilities ⇒ Array<Symbol>
Keep track of which visibilities are to be shown.
Instance Method Summary collapse
-
#all_objects ⇒ Array<CodeObjects::Base>
deprecated
Deprecated.
To hide methods use the @private tag instead.
- #description ⇒ Object
-
#initialize ⇒ Yardoc
constructor
Creates a new instance of the commandline utility.
-
#parse_arguments(*args) ⇒ void
Parses commandline arguments.
-
#run(*args) ⇒ void
Runs the commandline utility, parsing arguments and generating output if set.
-
#yardopts ⇒ Array<String>
Parses the .yardopts file for default yard options.
Methods inherited from Command
#common_options, #load_script, #parse_options, run
Constructor Details
#initialize ⇒ Yardoc
Creates a new instance of the commandline utility
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/yard/cli/yardoc.rb', line 155 def initialize super @options = SymbolHash.new(false) @options.update( :format => :html, :template => :default, :markup => :rdoc, :serializer => YARD::Serializers::FileSystemSerializer.new, :default_return => "Object", :hide_void_return => false, :no_highlight => false, :files => [], :verifier => Verifier.new ) @visibilities = [:public] @assets = {} @excluded = [] @files = [] @hidden_tags = [] @use_cache = false @use_yardopts_file = true @use_document_file = true @generate = true @options_file = DEFAULT_YARDOPTS_FILE @statistics = true @list = false @save_yardoc = true if defined?(Encoding) Encoding.default_external, Encoding.default_internal = 'utf-8', 'utf-8' end end |
Instance Attribute Details
#assets ⇒ Array<String>
Returns a list of assets to copy after generation.
152 153 154 |
# File 'lib/yard/cli/yardoc.rb', line 152 def assets @assets end |
#excluded ⇒ Array<String>
Returns list of excluded paths (regexp matches).
110 111 112 |
# File 'lib/yard/cli/yardoc.rb', line 110 def excluded @excluded end |
#files ⇒ Array<String>
Returns list of Ruby source files to process.
106 107 108 |
# File 'lib/yard/cli/yardoc.rb', line 106 def files @files end |
#generate ⇒ Boolean
Returns whether to generate output.
127 128 129 |
# File 'lib/yard/cli/yardoc.rb', line 127 def generate @generate end |
#hidden_tags ⇒ Array<Symbol>
Returns a list of tags to hide from templates.
144 145 146 |
# File 'lib/yard/cli/yardoc.rb', line 144 def @hidden_tags end |
#list ⇒ Boolean
Returns whether to print a list of objects.
131 132 133 |
# File 'lib/yard/cli/yardoc.rb', line 131 def list @list end |
#options ⇒ Hash (readonly)
Returns the hash of options passed to the template.
103 104 105 |
# File 'lib/yard/cli/yardoc.rb', line 103 def @options end |
#options_file ⇒ String
The options file name (defaults to DEFAULT_YARDOPTS_FILE)
135 136 137 |
# File 'lib/yard/cli/yardoc.rb', line 135 def @options_file end |
#save_yardoc ⇒ Boolean
Returns whether objects should be serialized to .yardoc db.
124 125 126 |
# File 'lib/yard/cli/yardoc.rb', line 124 def save_yardoc @save_yardoc end |
#statistics ⇒ Boolean
Returns whether to print statistics after parsing.
148 149 150 |
# File 'lib/yard/cli/yardoc.rb', line 148 def statistics @statistics end |
#use_cache ⇒ Boolean
Returns whether to use the existing yardoc db if the .yardoc already exists. Also makes use of file checksums to parse only changed files.
115 116 117 |
# File 'lib/yard/cli/yardoc.rb', line 115 def use_cache @use_cache end |
#use_document_file ⇒ Boolean
Returns whether to parse options from .document.
121 122 123 |
# File 'lib/yard/cli/yardoc.rb', line 121 def use_document_file @use_document_file end |
#use_yardopts_file ⇒ Boolean
Returns whether to parse options from .yardopts.
118 119 120 |
# File 'lib/yard/cli/yardoc.rb', line 118 def use_yardopts_file @use_yardopts_file end |
#visibilities ⇒ Array<Symbol>
Keep track of which visibilities are to be shown
140 141 142 |
# File 'lib/yard/cli/yardoc.rb', line 140 def visibilities @visibilities end |
Instance Method Details
#all_objects ⇒ Array<CodeObjects::Base>
To hide methods use the @private tag instead.
The list of all objects to process. Override this method to change which objects YARD should generate documentation for.
261 262 263 |
# File 'lib/yard/cli/yardoc.rb', line 261 def all_objects Registry.all(:root, :module, :class) end |
#description ⇒ Object
188 189 190 |
# File 'lib/yard/cli/yardoc.rb', line 188 def description "Generates documentation" end |
#parse_arguments(*args) ⇒ void
This method returns an undefined value.
Parses commandline arguments
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/yard/cli/yardoc.rb', line 232 def parse_arguments(*args) # Hack: parse out --no-yardopts, --no-document before parsing files ['document', 'yardopts'].each do |file| without, with = args.index("--no-#{file}") || 0, args.index("--#{file}") || 0 send("use_#{file}_file=", false) if without > with end # Parse files and then command line arguments optparse(*support_rdoc_document_file!) if use_document_file optparse(*yardopts) if use_yardopts_file optparse(*args) # Last minute modifications self.files = ['lib/**/*.rb', 'ext/**/*.c'] if self.files.empty? self.files.delete_if {|x| x =~ /\A\s*\Z/ } # remove empty ones [:readme] ||= Dir.glob('README*').first if [:onefile] [:files] << [:readme] if [:readme] [:readme] = Dir.glob(files.first).first end Tags::Library. -= add_visibility_verifier end |
#run(*args) ⇒ void
This method returns an undefined value.
Runs the commandline utility, parsing arguments and generating output if set.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/yard/cli/yardoc.rb', line 197 def run(*args) parse_arguments(*args) # fail early if markup provider is not found return if generate && ! checksums = nil if use_cache Registry.load checksums = Registry.checksums.dup end YARD.parse(files, excluded) Registry.save(use_cache) if save_yardoc if generate run_generate(checksums) copy_assets elsif list print_list end if !list && statistics && log.level < Logger::ERROR Registry.load_all log.enter_level(Logger::ERROR) do Stats.new(false).run(*args) end end true end |
#yardopts ⇒ Array<String>
Parses the .yardopts file for default yard options
267 268 269 270 271 272 |
# File 'lib/yard/cli/yardoc.rb', line 267 def yardopts return [] unless use_yardopts_file File.read_binary().shell_split rescue Errno::ENOENT [] end |