Class: JsDuck::Doc::Subproperties
- Inherits:
-
Object
- Object
- JsDuck::Doc::Subproperties
- Includes:
- Util::Singleton
- Defined in:
- lib/jsduck/doc/subproperties.rb
Overview
Detects nested structure of subproperties.
Instance Method Summary collapse
-
#nest(raw_items, pos) ⇒ Object
Given array of e.g.
- #warn(name, pos) ⇒ Object
Methods included from Util::Singleton
Instance Method Details
#nest(raw_items, pos) ⇒ Object
Given array of e.g. @param tags from Doc::Parser with names containing dots:
{:name => "foo"},
{:name => "foo.bar"},
{:name => "foo.baz"},
{:name => "zap"},
Produces nested structure:
{:name => "foo", :properties => [
{:name => "bar"},
{:name => "baz"}]},
{:name => "zap"},
Secondly it takes a position argument which is used for logging warnings when bogus subproperty syntax is encountered.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jsduck/doc/subproperties.rb', line 28 def nest(raw_items, pos) # First item can't be namespaced, if it is ignore the rest. if raw_items[0] && raw_items[0][:name] =~ /\./ warn(raw_items[0][:name], pos) raw_items[0][:name].sub!(/\..*$/, '') return [raw_items[0]] end # build name-index of all items index = {} raw_items.each {|it| index[it[:name]] = it } # If item name has no dots, add it directly to items array. # Otherwise look up the parent of item and add it as the # property of that parent. items = [] raw_items.each do |it| if it[:name] =~ /^(.+)\.([^.]+)$/ it[:name] = $2 parent = index[$1] if parent parent[:properties] = [] unless parent[:properties] parent[:properties] << it else warn("#{$1}.#{$2}", pos) end else items << it end end return items end |
#warn(name, pos) ⇒ Object
62 63 64 65 66 |
# File 'lib/jsduck/doc/subproperties.rb', line 62 def warn(name, pos) parent = name.sub(/\.[^.]*$/, '') msg = "Ignoring subproperty '#{name}' no parent found with name '#{parent}'." Logger.warn(:subproperty, msg, pos) end |