Class: JsDuck::Format::Subproperties

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/format/subproperties.rb

Overview

Helper for recursively formatting subproperties.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter) ⇒ Subproperties

Returns a new instance of Subproperties.



11
12
13
14
# File 'lib/jsduck/format/subproperties.rb', line 11

def initialize(formatter)
  @formatter = formatter
  @skip_type_parsing = false
end

Instance Attribute Details

#skip_type_parsingObject

Set to true to skip parsing and formatting of types. Used to skip parsing of SCSS typesdefs.



18
19
20
# File 'lib/jsduck/format/subproperties.rb', line 18

def skip_type_parsing
  @skip_type_parsing
end

Instance Method Details

#format(item) ⇒ Object

Takes a hash of param, return value, throws value or subproperty.

  • Markdown-formats the :doc field in it.

  • Parses the :type field and saves HTML to :html_type.

  • Recursively does the same with all items in :properties field.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jsduck/format/subproperties.rb', line 26

def format(item)
  item[:doc] = @formatter.format(item[:doc]) if item[:doc]

  if item[:type]
    item[:html_type] = format_type(item[:type])
  end

  if item[:properties]
    item[:properties].each {|p| format(p) }
  end
end

#format_type(type) ⇒ Object

Formats the given type definition string using TypeParser.

  • On success returns HTML-version of the type definition.

  • On failure logs error and returns the type string with only HTML escaped.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jsduck/format/subproperties.rb', line 43

def format_type(type)
  # Skip the formatting entirely when type-parsing is turned off.
  return Util::HTML.escape(type) if @skip_type_parsing

  tp = TypeParser.new(@formatter)
  if tp.parse(type)
    tp.out
  else
    context = @formatter.doc_context
    if tp.error == :syntax
      Logger.warn(:type_syntax, "Incorrect type syntax #{type}", context)
    else
      Logger.warn(:type_name, "Unknown type #{type}", context)
    end
    Util::HTML.escape(type)
  end
end