class YARD::CodeObjects::ExtraFileObject
compatible with most CodeObject interfaces.
it implements ‘path`, `name` and `type`, and therefore should be structurally
file). It is not strictly a CodeObject (does not inherit from `Base`) although
An ExtraFileObject represents an extra documentation file (README or other
def ==(other)
def ==(other) return false unless self.class === other other.filename == filename end
def attributes
def attributes ensure_parsed @attributes end
def contents
def contents ensure_parsed @contents end
def contents=(contents)
def contents=(contents) @original_contents = contents @parsed = false end
def ensure_parsed
def ensure_parsed return if @parsed @parsed = true @contents = parse_contents(@original_contents || File.read(@filename)) end
def hash; filename.hash end
def hash; filename.hash end
def initialize(filename, contents = nil)
-
contents(String) -- the file contents. If not set, the contents -
filename(String) -- the location on disk of the file
def initialize(filename, contents = nil) self.filename = filename self.name = File.basename(filename).gsub(/\.[^.]+$/, '') self.attributes = SymbolHash.new(false) @original_contents = contents @parsed = false @locale = nil ensure_parsed end
def inspect
def inspect "#<yardoc #{type} #{filename} attrs=#{attributes.inspect}>" end
def locale=(locale)
- Since: - 0.8.3
Returns:
-
(void)-
Parameters:
-
locale(String) -- the locale name to be translated.
def locale=(locale) @locale = locale @parsed = false end
def parse_contents(data)
-
data(String) -- the file contents
def parse_contents(data) retried = false cut_index = 0 data = translate(data) data = data.split("\n") data.each_with_index do |line, index| case line when /^#!(\S+)\s*$/ if index == 0 attributes[:markup] = $1 else cut_index = index break end when /^\s*#\s*@(\S+)\s*(.+?)\s*$/ attributes[$1] = $2 when /^\s*<!--\s*$/, /^\s*-->\s*$/ # Ignore HTML comments else cut_index = index break end end data = data[cut_index..-1] if cut_index > 0 contents = data.join("\n") if contents.respond_to?(:force_encoding) && attributes[:encoding] begin contents.force_encoding(attributes[:encoding]) rescue ArgumentError log.warn "Invalid encoding `#{attributes[:encoding]}' in #{filename}" end end contents rescue ArgumentError => e raise unless e.message =~ /invalid byte sequence/ if retried # This should never happen. log.warn "Could not read #{filename}, #{e.message}. You probably want to set `--charset`." return '' else data.force_encoding('binary') if data.respond_to?(:force_encoding) retried = true retry end end
def title
def title attributes[:title] || name end
def translate(data)
def translate(data) text = YARD::I18n::Text.new(data, :have_header => true) text.translate(YARD::Registry.locale(locale)) end
def type; :extra_file end
def type; :extra_file end