Index: lib/bitclust/entry.rb
===================================================================
--- lib/bitclust/entry.rb	(revision 2274)
+++ lib/bitclust/entry.rb	(working copy)
@@ -268,6 +268,8 @@
       property :classes,  '[ClassEntry]'   # :defined classes
       property :methods,  '[MethodEntry]'  # :added/:redefined entries
       property :source,   'String'
+      property :sublibraries, '[LibraryEntry]'
+      property :is_sublibrary,   'bool'
     }
 
     def inspect
@@ -287,10 +289,24 @@
       @link_checked = true
     end
 
+    def all_requires(libs = {})
+      requires.each{|l|
+        next if libs[l.name] 
+        libs[l.name] = l
+        l.all_requires(libs)
+      }
+      libs.values
+    end
+    
     def require(lib)
       requires().push lib
     end
 
+    def sublibrary(lib)
+      sublibraries().push lib
+      lib.is_sublibrary = true
+    end
+    
     def fetch_class(name)
       get_class(name) or
           raise ClassNotFound, "no such class in the library #{name()}: #{name}"
Index: lib/bitclust/rrdparser.rb
===================================================================
--- lib/bitclust/rrdparser.rb	(revision 2274)
+++ lib/bitclust/rrdparser.rb	(working copy)
@@ -62,6 +62,10 @@
         @context.require line.split[1]
       end
       f.skip_blank_lines
+      f.while_match(/\Asublibrary\s/) do |line|
+        @context.sublibrary line.split[1]
+      end
+      f.skip_blank_lines
       @context.library.source = f.break(/\A==?[^=]|\A---/).join('').rstrip
       read_classes f
       if line = f.gets   # error
@@ -307,6 +311,10 @@
         @library.require @db.get_library(libname)
       end
 
+      def sublibrary(libname)
+        @library.sublibrary @db.get_library(libname)
+      end
+      
       def define_class(name, supername)
         superclass = (name == 'Object' ? nil : @db.get_class(supername))
         register_class :class, name, superclass
Index: lib/bitclust/database.rb
===================================================================
--- lib/bitclust/database.rb	(revision 2274)
+++ lib/bitclust/database.rb	(working copy)
@@ -80,6 +80,8 @@
         @properties_dirty = false
       end
       if dirty?
+        update_requires()
+        update_sublibraries()
         # FIXME: many require loops in tk
         #each_dirty_library do |lib|
         #  lib.check_link
@@ -151,6 +153,22 @@
       @dirty_methods.clear
     end
 
+    def update_requires
+      libraries.each{|lib|
+        lib.requires = lib.all_requires
+      }
+    end
+    
+    def update_sublibraries
+      libraries.each{|lib|
+        re = /\A#{lib.name}\// 
+        libraries.each{|l|
+          lib.sublibrary(l) if re =~ l.name
+        }
+      }
+    end
+
+    
     def update_by_stdlibtree(root)
       parse_LIBRARIES("#{root}/LIBRARIES", properties()).each do |libname|
         update_by_file "#{root}/#{libname}.rd", libname
Index: template/library
===================================================================
--- template/library	(revision 2280)
+++ template/library	(working copy)
@@ -19,41 +19,50 @@
 
 <%
     headline_push
-    all_classes = @entry.classes
+    reqs = (@entry.sublibraries & @entry.requires).map{|lib| lib.classes }.flatten
+    all_classes = (@entry.classes + reqs).uniq.sort
     err_classes = all_classes.select{|c| c.ancestors.any?{|k| k.name == 'Exception' }}.sort
     classes = (all_classes - err_classes).sort
 %>
 
+
 <%= headline("Abstract") %>
 <%= compile_rd(@entry.source) %>
-
-<%  unless classes.empty? %>
-<%= headline("Classes/Modules") %>
-<table>
 <%
-      classes.each do |c|
+  [[classes,      'Classes/Modules'],
+   [err_classes,  'Exception Classes']].each do |cs, msg|
+    unless cs.empty?
 %>
+<%= headline(msg) %>
+<table>
+<%    cs.each do |c| %>
 <tr>
 <td class="signature"><%=h c.type.to_s %> <%= class_link(c.name) %></td>
 <td class="description"><%= compile_rd(c.synopsis_source) %></td>
 <%    end %>
 </table>
-<%  end %>
-
-<%  unless err_classes.empty? %>
-<%= headline("Exception Classes") %>
-<table>
 <%
-      err_classes.each do |c|
+    end
+  end
 %>
+<%
+  [[@entry.requires.sort, 'Required Libraries'],
+   [(@entry.sublibraries - @entry.requires).sort, 'Sublibraries']].each do |cs, msg|
+    unless cs.empty?
+%>
+<%= headline(msg) %>
+<table>
+<%    cs.each do |c| %>
 <tr>
-<td class="signature"><%=h c.type.to_s %> <%= class_link(c.name) %></td>
+<td class="signature"><%= library_link(c.name) %></td>
 <td class="description"><%= compile_rd(c.synopsis_source) %></td>
 <%    end %>
 </table>
-<%  end %>
-
 <%
+    end
+  end
+%>
+<%
     ents = @entry.methods.sort
     unless ents.empty? %>
 <%= headline("Added/Redefined Methods") %>
Index: template/library-index
===================================================================
--- template/library-index	(revision 2274)
+++ template/library-index	(working copy)
@@ -25,14 +25,10 @@
 <td class="description"><%= compile_rd(lib.synopsis_source) %></td>
 </tr>
 <%
-    currroot = nil
-    @entries.each do |lib|
+    libs = @entries.sort_by{|lib| lib.name }
+    libs.each do |lib|
       next if lib.id == '_builtin'
-      if currroot and lib.id[0, currroot.size] == currroot
-        next
-      else
-        currroot = lib.id
-      end
+      next if lib.is_sublibrary
 %>
 <tr>
 <td class="signature"><%= library_link(lib.name) %></td>
