Method: RDoc::Servlet#root_search

Defined in:
lib/rdoc/servlet.rb

#root_search(req, res) ⇒ Object

Generates a search index for the root page on res. req is ignored.



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/rdoc/servlet.rb', line 345

def root_search req, res
  search_index = []
  info         = []

  installed_docs.map do |name, href, exists, type, path|
    next unless exists

    search_index << name

    case type
    when :gem
      gemspec = path.gsub(%r%/doc/([^/]*?)/ri$%,
                          '/specifications/\1.gemspec')

      spec = Gem::Specification.load gemspec

      path    = spec.full_name
      comment = spec.summary
    when :system then
      path    = 'ruby'
      comment = 'Documentation for the Ruby standard library'
    when :site then
      path    = 'site'
      comment = 'Documentation for non-gem libraries'
    when :home then
      path    = 'home'
      comment = 'Documentation from your home directory'
    when :extra
      comment = name
    end

    info << [name, '', path, '', comment]
  end

  index = {
    :index => {
      :searchIndex     => search_index,
      :longSearchIndex => search_index,
      :info            => info,
    }
  }

  res.body = "var search_data = #{JSON.dump index};"
  res.content_type = 'application/javascript'
end