Added super-hacky script to generate the wiki reference pages.

This commit is contained in:
Bob Aman committed 2011-12-02 17:24:56 +03:00
1 parent 5d314e6454
commit 84ae475d55
13 files changed
+1010 -7

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../../lib'))
$LOAD_PATH.unshift(lib_dir)
$LOAD_PATH.uniq!
require 'yard-google-code'
include T('default/module')
def init
super
sections.place(:subclasses).before(:children)
sections.place(:constructor_details, [T('method_details')]).before(:methodmissing)
# Weird bug w/ doubled sections
sections.uniq!
end
def constructor_details
ctors = object.meths(:inherited => true, :included => true)
return unless @ctor = ctors.find {|o| o.name == :initialize }
return if prune_method_listing([@ctor]).empty?
erb(:constructor_details)
end
def subclasses
return if object.path == "Object" # don't show subclasses for Object
unless globals.subclasses
globals.subclasses = {}
list = run_verifier Registry.all(:class)
list.each do |o|
(globals.subclasses[o.superclass.path] ||= []) << o if o.superclass
end
end
@subclasses = globals.subclasses[object.path]
return if @subclasses.nil? || @subclasses.empty?
@subclasses = @subclasses.sort_by {|o| o.path }.map do |child|
name = child.path
if object.namespace
name = object.relative_path(child)
end
[name, child]
end
erb(:subclasses)
end
+54
View File
@@ -0,0 +1,54 @@
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../../lib'))
$LOAD_PATH.unshift(lib_dir)
$LOAD_PATH.uniq!
require 'yard-google-code'
def init
return if object.docstring.blank? && !object.has_tag?(:api)
sections :index, [:private, :deprecated, :abstract, :todo, :note, :returns_void, :text], T('tags')
end
def private
return unless object.has_tag?(:api) && object.tag(:api).text == 'private'
erb(:private)
end
def abstract
return unless object.has_tag?(:abstract)
erb(:abstract)
end
def deprecated
return unless object.has_tag?(:deprecated)
erb(:deprecated)
end
def todo
return unless object.has_tag?(:todo)
erb(:todo)
end
def note
return unless object.has_tag?(:note)
erb(:note)
end
def returns_void
return unless object.type == :method
return if object.name == :initialize && object.scope == :instance
return unless object.tags(:return).size == 1 && object.tag(:return).types == ['void']
erb(:returns_void)
end
def docstring_text
text = ""
unless object.tags(:overload).size == 1 && object.docstring.empty?
text = object.docstring
end
if text.strip.empty? && object.tags(:return).size == 1 && object.tag(:return).text
text = object.tag(:return).text.gsub(/\A([a-z])/) {|x| x.upcase }
end
text.strip
end
+8
View File
@@ -0,0 +1,8 @@
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../../lib'))
$LOAD_PATH.unshift(lib_dir)
$LOAD_PATH.uniq!
require 'yard-google-code'
def init
sections :header, [T('method_details')]
end
@@ -0,0 +1,8 @@
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../../lib'))
$LOAD_PATH.unshift(lib_dir)
$LOAD_PATH.uniq!
require 'yard-google-code'
def init
sections :header, [:method_signature, T('docstring')]
end
+133
View File
@@ -0,0 +1,133 @@
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../../lib'))
$LOAD_PATH.unshift(lib_dir)
$LOAD_PATH.uniq!
require 'yard-google-code'
include Helpers::ModuleHelper
def init
sections :header, :box_info, :pre_docstring, T('docstring'), :children,
:constant_summary, [T('docstring')], :inherited_constants,
:inherited_methods,
:methodmissing, [T('method_details')],
:attribute_details, [T('method_details')],
:method_details_list, [T('method_details')]
end
def pre_docstring
return if object.docstring.blank?
erb(:pre_docstring)
end
def children
@inner = [[:modules, []], [:classes, []]]
object.children.each do |child|
@inner[0][1] << child if child.type == :module
@inner[1][1] << child if child.type == :class
end
@inner.map! {|v| [v[0], run_verifier(v[1].sort_by {|o| o.name.to_s })] }
return if (@inner[0][1].size + @inner[1][1].size) == 0
erb(:children)
end
def methodmissing
mms = object.meths(:inherited => true, :included => true)
return unless @mm = mms.find {|o| o.name == :method_missing && o.scope == :instance }
erb(:methodmissing)
end
def method_listing(include_specials = true)
return @smeths ||= method_listing.reject {|o| special_method?(o) } unless include_specials
return @meths if @meths
@meths = object.meths(:inherited => false, :included => false)
@meths = sort_listing(prune_method_listing(@meths))
@meths
end
def special_method?(meth)
return true if meth.name(true) == '#method_missing'
return true if meth.constructor?
false
end
def attr_listing
return @attrs if @attrs
@attrs = []
[:class, :instance].each do |scope|
object.attributes[scope].each do |name, rw|
@attrs << (rw[:read] || rw[:write])
end
end
@attrs = sort_listing(prune_method_listing(@attrs, false))
end
def constant_listing
return @constants if @constants
@constants = object.constants(:included => false, :inherited => false)
@constants += object.cvars
@constants = run_verifier(@constants)
@constants
end
def sort_listing(list)
list.sort_by {|o| [o.scope.to_s, o.name.to_s.downcase] }
end
def docstring_full(obj)
docstring = ""
if obj.tags(:overload).size == 1 && obj.docstring.empty?
docstring = obj.tag(:overload).docstring
else
docstring = obj.docstring
end
if docstring.summary.empty? && obj.tags(:return).size == 1 && obj.tag(:return).text
docstring = Docstring.new(obj.tag(:return).text.gsub(/\A([a-z])/) {|x| x.upcase }.strip)
end
docstring
end
def docstring_summary(obj)
docstring_full(obj).summary
end
def groups(list, type = "Method")
if groups_data = object.groups
others = list.select {|m| !m.group }
groups_data.each do |name|
items = list.select {|m| m.group == name }
yield(items, name) unless items.empty?
end
else
others = []
group_data = {}
list.each do |meth|
if meth.group
(group_data[meth.group] ||= []) << meth
else
others << meth
end
end
group_data.each {|group, items| yield(items, group) unless items.empty? }
end
scopes(others) {|items, scope| yield(items, "#{scope.to_s.capitalize} #{type} Summary") }
end
def scopes(list)
[:class, :instance].each do |scope|
items = list.select {|m| m.scope == scope }
yield(items, scope) unless items.empty?
end
end
def mixed_into(object)
unless globals.mixed_into
globals.mixed_into = {}
list = run_verifier Registry.all(:class, :module)
list.each {|o| o.mixins.each {|m| (globals.mixed_into[m.path] ||= []) << o } }
end
globals.mixed_into[object.path] || []
end
+55
View File
@@ -0,0 +1,55 @@
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../../lib'))
$LOAD_PATH.unshift(lib_dir)
$LOAD_PATH.uniq!
require 'yard-google-code'
def init
tags = Tags::Library.visible_tags - [:abstract, :deprecated, :note, :todo]
create_tag_methods(tags - [:example, :option, :overload, :see])
sections :index, tags
sections.any(:overload).push(T('docstring'))
end
def return
if object.type == :method
return if object.name == :initialize && object.scope == :instance
return if object.tags(:return).size == 1 && object.tag(:return).types == ['void']
end
tag(:return)
end
private
def tag(name, opts = nil)
return unless object.has_tag?(name)
opts ||= options_for_tag(name)
@no_names = true if opts[:no_names]
@no_types = true if opts[:no_types]
@name = name
out = erb('tag')
@no_names, @no_types = nil, nil
out
end
def create_tag_methods(tags)
tags.each do |tag|
next if respond_to?(tag)
instance_eval(<<-eof, __FILE__, __LINE__ + 1)
def #{tag}; tag(#{tag.inspect}) end
eof
end
end
def options_for_tag(tag)
opts = {:no_types => true, :no_names => true}
case Tags::Library.factory_method_for(tag)
when :with_types
opts[:no_types] = false
when :with_types_and_name
opts[:no_types] = false
opts[:no_names] = false
when :with_name
opts[:no_names] = false
end
opts
end