Skip to content

Instantly share code, notes, and snippets.

@kojix2
Created May 21, 2022 11:50
Show Gist options
  • Save kojix2/9e2cff274fbf856d40f1d00ca158637a to your computer and use it in GitHub Desktop.
Save kojix2/9e2cff274fbf856d40f1d00ca158637a to your computer and use it in GitHub Desktop.
gen_documentation_rb by Sami Sieranoja (@SamiSieranoja)
#!/usr/bin/ruby
require "gtksourceview4"
require "gtk3"
require "ripl"
c = Gtk::TextBuffer
GtkSource::View.new
classes = {}
$wm = Gtk::Widget.instance_methods
Dir.mkdir("gtk_doc_html") if !File.exist?("gtk_doc_html")
def process_class_methods(c)
fn = c.name.gsub(/::/, "_") + ".html"
outfn = "gtk_doc_html/#{fn}"
outf = File.open(outfn, "w")
outf.write "<html><head></head><body>"
outf.write "<h1>#{c.name}</h1>"
outf.write "methods:"
outf.write "<ul>"
for x in c.instance_methods.sort
if !$wm.include?(x)
nump = c.instance_method(x).parameters.size
c.instance_method(x).parameters.collect { |x| [:req, :opt].include? x[0] }
i = 1
params = []
for p in c.instance_method(x).parameters
if p[0] == :req
pstr = "req#{i}"
if p[1]
pstr = p[1].to_s
end
params << pstr
end
if p[0] == :opt
pstr = "opt#{i}="
if p[1]
pstr = p[1].to_s + "="
end
params << pstr
end
i += 1
end
params_all_str = params.join(",")
fcallstr = "#{x.to_s}"
fcallstr << "(#{params_all_str})" if params.size > 0
# puts fcallstr
outf.write("<li >#{fcallstr} <span style='color:#fff'>(debug:#{c.instance_method(x).parameters})</span></li>")
end
end
outf.write "</ul>"
outf.write "constants:"
outf.write "<ul>"
for x in c.constants.sort
outf.write("<li>#{x}</li>")
end
outf.write "</ul>"
outf.write "</body></html>"
outf.close
return fn
end
stack = [{ :obj => Cairo, :trail => [] }, { :obj => Pango, :trail => [] }, { :obj => Gio, :trail => [] }, { :obj => GtkSource, :trail => [] }, { :obj => Gdk, :trail => [] }, { :obj => Gtk, :trail => [] }]
classes = {}
modules = {}
while !stack.empty?
x = stack.pop
xo = x[:obj]
for y in xo.constants.sort
yo = xo.const_get(y)
if yo.is_a? Module
next if modules.has_key?(yo.name)
a = { :obj => yo }
a[:trail] = x[:trail].clone + [yo.name]
modules[yo.name] = a
stack << a if a[:trail].size < 10 # Should not come here
end
if yo.is_a? Class or yo.is_a? Module
next if classes.has_key?(yo.name)
classes[yo.name] = yo
end
end
end
indfn = "gtk_doc_html/index.html"
f = File.open(indfn, "w")
f.write("<html><head></head><body>")
for x in classes
cfn = process_class_methods(x[1])
f.write("<a href='#{cfn}'>#{x[0]}</a><br/>")
end
f.write("</body></html>")
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment