Sha256: e5b84d016d86cbdfc00951f6b6ce857b3f7a91497c79b458b7f0054e4f430fee

Contents?: true

Size: 1.83 KB

Versions: 30

Compression:

Stored size: 1.83 KB

Contents

require 'jsduck/util/parallel'
require 'jsduck/format/class'
require 'jsduck/format/doc'
require 'jsduck/img/dir_set'
require 'jsduck/logger'

module JsDuck
  module Format

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

      # 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.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

      # Factory method to create new Format::Class instances.
      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

    end

  end
end

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
solvas-jsduck-6.0.0.30539 lib/jsduck/format/batch.rb
solvas-jsduck-6.0.0.9571 lib/jsduck/format/batch.rb
solvas-jsduck-6.0.0.6154 lib/jsduck/format/batch.rb
solvas-jsduck-6.0.0.4021 lib/jsduck/format/batch.rb
solvas-jsduck-6.0.0.2554 lib/jsduck/format/batch.rb
solvas-jsduck-6.0.0.1891 lib/jsduck/format/batch.rb
solvas-jsduck-6.0.0.beta.1888 lib/jsduck/format/batch.rb
jsduck-troopjs-0.0.10 lib/jsduck/format/batch.rb
jsduck-troopjs-0.0.9 lib/jsduck/format/batch.rb
jsduck-troopjs-0.0.8 lib/jsduck/format/batch.rb
jsduck-troopjs-0.0.7 lib/jsduck/format/batch.rb
jsduck-troopjs-0.0.5 lib/jsduck/format/batch.rb
jsduck-troopjs-0.0.4 lib/jsduck/format/batch.rb
jsduck-troopjs-0.0.3 lib/jsduck/format/batch.rb
jsduck-troopjs-0.0.1 lib/jsduck/format/batch.rb
jsduck-6.0.0beta lib/jsduck/format/batch.rb
jsduck-5.3.4 lib/jsduck/format/batch.rb
jsduck-5.3.3 lib/jsduck/format/batch.rb
jsduck-5.3.2 lib/jsduck/format/batch.rb
jsduck-5.3.1 lib/jsduck/format/batch.rb