class Wrongdoc::Final

Constants

SE_URL

Public Class Methods

new(opts, git_tag = nil) click to toggle source
# File lib/wrongdoc/final.rb, line 15
def initialize(opts, git_tag = nil)
  @cgit_uri = URI.parse(opts[:cgit_url])
  @rdoc_uri = URI.parse(opts[:rdoc_url])
  ml_url = opts[:ml_url] and @ml_uri = URI.parse(ml_url)
  @public_email = opts[:public_email] or warn ":public_email unset"
  @private_email = opts[:private_email] or warn ":private_email unset"
  @git_tag = git_tag
end

Public Instance Methods

advertise!(doc) click to toggle source

Don't give the original Darkfish a bad name, and advertise ourselves :)

fix(file) click to toggle source
# File lib/wrongdoc/final.rb, line 143
def fix(file)
  File.open(file, "a+") do |fp|
    buf = process(fp.read)
    fp.truncate 0
    fp.write buf
  end
end
killkillkill!(doc) click to toggle source

delete all the stuff that offends us

# File lib/wrongdoc/final.rb, line 34
def killkillkill!(doc)
  unlink = proc { |node| node.unlink }

  # JavaScript is dangerous
  doc.search("script").each(&unlink)

  # if your project's big enough to need JS search, it's too bloated
  doc.search('span.search-toggle').each(&unlink)
  doc.search('form').each(&unlink)

  # remove W3C validator link, we use tidy instead
  doc.search('div#validator-badges p').each { |x|
    /Validate/i =~ x.content and x.unlink
  }

  # this shows up in browsers that don't do stylesheets
  doc.search('div#no-class-search-results').each(&unlink)
end
path_uri(path, lineno) click to toggle source

returns a cgit URI for the given path and lineno

# File lib/wrongdoc/final.rb, line 25
def path_uri(path, lineno)
  uri = @cgit_uri.dup
  uri.path += "/tree/#{URI.escape(path)}"
  uri.fragment = "n#{lineno}"
  uri.query = "id=#{URI.escape(@git_tag)}" if @git_tag
  uri
end
process(str) click to toggle source

the main entry point, this does all the require processing on any given String buffer.

# File lib/wrongdoc/final.rb, line 153
def process(str)
  doc = parse_xml(str)
  killkillkill!(doc)
  source_linkify!(doc)
  advertise!(doc)
  doc.to_xhtml(:indent => 0)
end
run() click to toggle source
# File lib/wrongdoc/final.rb, line 9
def run
  Find.find('doc') { |path| /\.html\z/ =~ path and fix(path) }
  FileUtils.rm_rf('doc/js')
  news_atom
end
source_linkify!(doc) click to toggle source

since we killed off JavaScript, viewing source isn't possible with RDoc anymore, so link people to the web source viewer

# File lib/wrongdoc/final.rb, line 55
def source_linkify!(doc)
  doc.search('div.method-detail').each { |mdetail|
    path = lineno = nil
    mdetail.search('div.method-source-code').each { |src|
      src.search('span.ruby-comment').each { |x|
        if x.content =~ /File\s+(\S+),\s+line\s+(\d+)/s
          path, lineno = $1, $2
        end
      }
      src.unlink if path && lineno
    }
    mdetail.search('span.method-click-advice').each { |x|
      x.content = ''
      a = Nokogiri::XML::Node.new('a', doc)
      a['href'] = (path && lineno ? path_uri(path, lineno) : @cgit_uri).to_s
      a.content = 'view method source'
      x.add_child(a)
    }
  }
end