sections may now have associated descriptions

This commit is contained in:
steve donovan 2011-06-08 19:12:04 +02:00
parent be9c3f2f70
commit 014c003a1a
3 changed files with 16 additions and 7 deletions

View File

@ -141,12 +141,14 @@ function File:finish()
end end
-- right, this item was within a section or a 'class' -- right, this item was within a section or a 'class'
local section_description
if this_mod.section then if this_mod.section then
item.section = this_mod.section.display_name item.section = this_mod.section.display_name
-- if it was a class, then the name should be 'Class.foo' -- if it was a class, then the name should be 'Class.foo'
if this_mod.section.type == 'type' then if this_mod.section.type == 'type' then
item.name = this_mod.section.name .. '.' .. item.name item.name = this_mod.section.name .. '.' .. item.name
end end
section_description = this_mod.section.description
else -- otherwise, just goes into the default sections (Functions,Tables,etc) else -- otherwise, just goes into the default sections (Functions,Tables,etc)
item.section = item.type item.section = item.type
end end
@ -156,9 +158,8 @@ function File:finish()
these_items.by_name[item.name] = item these_items.by_name[item.name] = item
these_items:append(item) these_items:append(item)
-- register this item with the iterator -- register this item with the iterator
this_mod.kinds:add(item,these_items) this_mod.kinds:add(item,these_items,section_description)
else else
-- must be a free-standing function (sometimes a problem...) -- must be a free-standing function (sometimes a problem...)

View File

@ -102,6 +102,7 @@
# --- function parameters or table fields. # --- function parameters or table fields.
# for kind, items in module.kinds() do # for kind, items in module.kinds() do
<h2><a name="$(no_spaces(kind))"></a>$(kind)</h2> <h2><a name="$(no_spaces(kind))"></a>$(kind)</h2>
$(M(module.kinds:get_section_description(kind)))
<dl class="function"> <dl class="function">
# for item in items() do # for item in items() do
<dt> <dt>

View File

@ -44,8 +44,8 @@ end
local KindMap = class() local KindMap = class()
M.KindMap = KindMap M.KindMap = KindMap
-- calling a KindMap returns an iterator. This returns the kind and the iterator -- calling a KindMap returns an iterator. This returns the kind, the iterator
-- over the items of that type. -- over the items of that type, and the actual type tag value.
function KindMap:__call () function KindMap:__call ()
local i = 1 local i = 1
local klass = self.klass local klass = self.klass
@ -69,14 +69,20 @@ function KindMap:type_of (item)
return klass.types_by_kind [kind] return klass.types_by_kind [kind]
end end
function KindMap:get_section_description (kind)
return self.klass.descriptions[kind]
end
-- called for each new item. It does not actually create separate lists, -- called for each new item. It does not actually create separate lists,
-- (although that would not break the interface) but creates iterators -- (although that would not break the interface) but creates iterators
-- for that item type if not already created. -- for that item type if not already created.
function KindMap:add (item,items) function KindMap:add (item,items,description)
local group = item[self.fieldname] local group = item[self.fieldname] -- which wd be item's type or section
local kname = self.klass.types_by_tag[group] local kname = self.klass.types_by_tag[group] -- the kind name
if not self[kname] then if not self[kname] then
self[kname] = M.type_iterator (items,self.fieldname,group) self[kname] = M.type_iterator (items,self.fieldname,group)
--print(kname,description)
self.klass.descriptions[kname] = description
end end
end end
@ -86,6 +92,7 @@ function KindMap._class_init (klass)
klass.kinds = {} -- list in correct order of kinds klass.kinds = {} -- list in correct order of kinds
klass.types_by_tag = {} -- indexed by tag klass.types_by_tag = {} -- indexed by tag
klass.types_by_kind = {} -- indexed by kind klass.types_by_kind = {} -- indexed by kind
klass.descriptions = {} -- optional description for each kind
end end