Sha256: b4c007c10cdb33d770e728b1d0e52d0c33bdba9301cd24cbfaeae8af85fb3b9c

Contents?: true

Size: 1.56 KB

Versions: 12

Compression:

Stored size: 1.56 KB

Contents

require 'jsduck/util/parallel'
require 'jsduck/class_formatter'
require 'jsduck/doc_formatter'
require 'jsduck/logger'

module JsDuck

  # Performs the formatting of the doc-object of all classes.
  class BatchFormatter

    # Formats all classes.
    # Also registers found images in assets.
    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
          }
        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]
        cls[:images].each {|img| assets.images.add(img) }
      end
    end

    # Factory method to create new ClassFormatter instances.
    def self.create_class_formatter(relations, opts)
      doc_formatter = DocFormatter.new(opts)
      doc_formatter.relations = relations
      doc_formatter.img_path = "images"

      class_formatter = ClassFormatter.new(relations, doc_formatter)
      # Don't format types when exporting
      class_formatter.include_types = !opts.export

      class_formatter
    end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jsduck-4.6.1 lib/jsduck/batch_formatter.rb
jsduck-4.6.0 lib/jsduck/batch_formatter.rb
jsduck-4.5.1 lib/jsduck/batch_formatter.rb
jsduck-4.5.0 lib/jsduck/batch_formatter.rb
jsduck-4.4.1 lib/jsduck/batch_formatter.rb
jsduck-4.4.0 lib/jsduck/batch_formatter.rb
jsduck-4.3.2 lib/jsduck/batch_formatter.rb
jsduck-4.3.1 lib/jsduck/batch_formatter.rb
jsduck-4.3.0 lib/jsduck/batch_formatter.rb
jsduck-4.2.1 lib/jsduck/batch_formatter.rb
jsduck-4.2.0 lib/jsduck/batch_formatter.rb
jsduck-4.1.1 lib/jsduck/batch_formatter.rb