Class: JsDuck::Format::Batch

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

Overview

Performs the formatting of the doc-object of all classes.

Class Method Summary collapse

Class Method Details

.create_class_formatter(relations, opts) ⇒ Object

Factory method to create new Format::Class instances.



48
49
50
51
52
53
# File 'lib/jsduck/format/batch.rb', line 48

def self.create_class_formatter(relations, opts)
  doc_formatter = Format::Doc.new(relations, opts)
  doc_formatter.images = Img::DirSet.new(opts.images, "images")

  return Format::Class.new(doc_formatter)
end

.format_all!(relations, assets, opts) ⇒ Object

Formats all classes. Also registers found images in assets.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jsduck/format/batch.rb', line 15

def self.format_all!(relations, assets, opts)
  # Format all doc-objects in parallel
  formatted_classes = Util::Parallel.map(relations.classes) do |cls|

    files = cls[:files].map {|f| f[:filename] }.join(" ")
    Logger.log("Markdown formatting #{cls[:name]}", files)

    formatter = create_class_formatter(relations, opts)
    begin
      {
        :doc => formatter.format(cls.internal_doc),
        :images => formatter.images.all_used
      }
    rescue
      Logger.fatal_backtrace("Error while formatting #{cls[:name]} #{files}", $!)
      exit(1)
    end
  end

  # Then merge the data back to classes sequentially
  formatted_classes.each do |cls|
    relations[cls[:doc][:name]].internal_doc = cls[:doc]
    # Perform lookup of all the images again.  We're really doing
    # this work twice now, but as we usually don't have excessive
    # amounts of images, the performance penalty should be minimal.
    cls[:images].each {|img| assets.images.get(img[:filename]) }
  end

  # Print warnings for unused images
  assets.images.report_unused
end