class JsDuck::Web::Data

Creates big JS file with data for Docs app.

Public Class Methods

new(relations, assets, opts) click to toggle source
# File lib/jsduck/web/data.rb, line 13
def initialize(relations, assets, opts)
  @relations = relations
  @assets = assets
  @opts = opts
end

Public Instance Methods

write(filename) click to toggle source

Writes classes, guides, videos, and search data to one big .js file. Then Renames the file so it contains an MD5 hash inside it, returning the resulting fingerprinted name.

# File lib/jsduck/web/data.rb, line 22
def write(filename)
  js = "Docs = " + Util::Json.generate({
    :data => {
      :classes => Web::Tree.create(@relations.classes),
      :guides => @assets.guides.to_array,
      :videos => @assets.videos.to_array,
      :examples => @assets.examples.to_array,
      :search => Web::Search.new.create(@relations.classes, @assets, @opts),
      :guideSearch => @opts.search,
      :tests => @opts.tests,
      :signatures => TagRegistry.signatures,
      :memberTypes => MemberRegistry.definitions,
      :localStorageDb => @opts.local_storage_db,
      :showPrintButton => @opts.seo,
      :touchExamplesUi => @opts.touch_examples_ui,
      :source => @opts.source,
      :commentsUrl => @opts.comments_url,
      :commentsDomain => @opts.comments_domain,
      :message => @opts.message,
    }
  }) + ";\n"

  File.open(filename, 'w') {|f| f.write(js) }

  Util::MD5.rename(filename)
end