Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Commit

Permalink
Self-documenting robot
Browse files Browse the repository at this point in the history
git-svn-id: svn://78.47.249.61/ruby-mediawiki/trunk@36 ba9c31aa-a806-0410-9a81-9f13d15ee83b
  • Loading branch information
astro committed Dec 14, 2005
1 parent 16bfb54 commit 784627e
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
94 changes: 94 additions & 0 deletions apps/rdoc_to_wiki.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env ruby

require 'yaml'
require 'rdoc/ri/ri_reader'

$:.unshift('../lib')
require 'mediawiki/dotfile'


def find(dir, &block)
Dir.foreach(dir) { |file|
next if file =~ /^\./

path = "#{dir}/#{file}"
if File.directory?(path)
find(path) { |f| yield f }
else
yield path
end
}
end

def wiki_format(flow)
s = ''
case flow
when Array
flow.each { |subflow|
s += wiki_format(subflow)
}
when SM::Flow::LIST
flow.contents.each { |subflow|
s += wiki_format(subflow)
}
when SM::Flow::LI
s += "* '''#{flow.label}''' #{flow.body}\n"
when SM::Flow::P
s += "#{flow.body}\n\n"
else
puts "Unknown Flow: #{flow.inspect}"
end
s.gsub!(/"/, '"')
s.gsub!(/<b>(.+?)<\/b>/, '\'\'\'\1\'\'\'')
s.gsub!(/<i>(.+?)<\/i>/, '\'\'\1\'\'')
s
end

def belongs_to_class?(classname, methodname)
c = classname.split(/::|#/)
m = methodname.split(/::|#/)
m.pop
c == m
end

classes = []
methods = []

find("../rdoc-ri") { |file|
next unless file =~ /\.yaml$/
ri = YAML::load(File.new(file))
case ri
when RI::ClassDescription
classes << ri
when RI::MethodDescription
methods << ri
else
puts "Unknown Description: #{ri.inspect}"
end
}

classes.sort! { |a,b|
a.full_name <=> b.full_name
}
methods.sort! { |a,b|
a.full_name <=> b.full_name
}

text = ''
classes.each { |klass|
text += "==#{klass.full_name}==\n\n"
text += wiki_format(klass.comment || [])
methods.each { |method|
if belongs_to_class?(klass.full_name, method.full_name)
text += "===#{method.full_name}===\n"
text += wiki_format(method.comment || [])
text += "\n"
end
}
}


wiki, conf = MediaWiki.dotfile('rdoc to wiki')
article = wiki.article(conf['page'])
article.text = "=#{conf['title']}=\n\n" + text
article.submit("I can even document myself :-)")
1 change: 1 addition & 0 deletions lib/mediawiki/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def text
end

# takes the wiki markup of a table and returns a 2-dimensional array representing the rows and columns of the table
#
# TODO: fill member variables according to parsed tables
def self.parse( text )
table, row = nil, nil
Expand Down
3 changes: 3 additions & 0 deletions mediawikirc.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ c3d2:
date determinator:
pages:
- Benutzer:Astro/Date_Determinator
rdoc to wiki:
title: Ruby-MediaWiki Documentation
page: Ruby-MediaWiki/Documentation
blabla:
url: http://blabla.gov/wiki/
user: GWBush
Expand Down
1 change: 1 addition & 0 deletions mkrdoc.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
rdoc --inline-source --line-numbers --op rdoc lib/mediawiki.rb lib/mediawiki/*.rb
rdoc --inline-source --line-numbers --op rdoc-ri -f ri lib/mediawiki.rb lib/mediawiki/*.rb

0 comments on commit 784627e

Please sign in to comment.