<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/tendersync/tendersync.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,12 @@
 --- 
 docurl: http://support.newrelic.com
+groups: 
+- - Installation and configuration
+  - /install|config|custom/i
+- - Page by page tour of RPM
+  - / page$/i
+- - Advanced topics
+  - //
+depth: 1
 username: bkayser@newrelic.com
 password: Bell10t</diff>
      <filename>.tendersync</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 require 'fileutils'
 require 'set'
+require 'yaml'
 
 class Tendersync::Document
   Properties = [:section, :document_id, :title, :permalink, :keywords, :body]
@@ -8,14 +9,18 @@ class Tendersync::Document
   NUM_DASHES = 28 # the number of dashes in keyword fields
   
   class TOCEntry
-    attr_reader :name, :link, :children, :level
+    attr_reader :name, :link, :level
     attr_accessor :parent
-    def initialize name, link=nil, level=1
-      @name, @link, @level = name, link, level
-      @children = []
+    def initialize name, link=nil, level=nil
+      @name = name
+      @link = link if link
+      @level = level if level
+    end
+    def children
+      @children ||= []
     end
     # Write this element and all children, recursively as bullet lists with links
-    def write_entries(io, indent = 0, doc_link = parent.link)
+    def write_entries(io, depth=1, indent = 0, doc_link = parent.link)
       io.write &quot; &quot; * 4 * indent # indentation
       io.write &quot;* &quot; # bullet
       if link
@@ -23,7 +28,7 @@ class Tendersync::Document
       else
         io.puts name
       end
-      children.each { | child | child.write_entries(io, indent+1, doc_link)}
+      children.each { | child | child.write_entries(io, depth-1, indent+1, doc_link)} unless depth == 1
     end
     def add child
       if !parent || child.level &gt; self.level
@@ -39,11 +44,11 @@ class Tendersync::Document
   class Group &lt; TOCEntry
     attr_reader :title_regex
     def initialize(name, title_regex=//)
-      super(name)
-      @level = 0
+      super(name, nil, nil)
       @title_regex = title_regex
     end
-    Default = Group.new('Other') 
+    Default = Group.new('Other')
+
   end
   
   def initialize(values={})
@@ -145,15 +150,23 @@ class Tendersync::Document
   #
   # If group_map is empty then headings will be sorted alphabetically
   # and not grouped.
-  def refresh_index(groups=[])
-    toc = groups + [Group::Default] # array of groups
+  #
+  # depth s the number of nested levels to descend into a document.
+  def refresh_index(groups=[], depth=2)
+    generate_index(create_toc(groups), depth)  
+  end
+  
+  private
+  
+  def create_toc(groups)
+    groups += groups + [Group::Default] # array of groups
     link_root = {}
     self.class.each(section) do |document|
       next if document.permalink =~ /-table-of-contents$/
-      puts &quot;processing #{document.permalink}...&quot;
+      puts &quot;indexing #{document.permalink}...&quot;
       title = document.title
-      group = toc.detect { | g | title =~ g.title_regex }
-      doc_entry = TOCEntry.new title, document.permalink, 1
+      group = groups.detect { | g | title =~ g.title_regex }
+      doc_entry = TOCEntry.new title, document.permalink, 0
       group.add doc_entry
       last = doc_entry
       link = nil
@@ -161,33 +174,33 @@ class Tendersync::Document
         name = $1
         heading_level = $2 &amp;&amp; $2.length
         text = $3
-        puts &quot;   &gt;&gt; #{heading_level}, #{text}&quot;
         if name
           # Record the link name for the next header
           link = eval(name)
         elsif heading_level == 1
-          puts &quot;  using level 1: #{title}:#{text}&quot;
           last = last.add(TOCEntry.new(text, link, heading_level)) 
         elsif heading_level &gt;= 2  # level 2
-          puts &quot;  link recommended for #{text}&quot; if !link
           last = last.add(TOCEntry.new(text, link, heading_level)) 
           link = nil
         end
       end
     end
-    toc.reject! { | group | group.children.empty? }
+    groups
+  end
+  
+  def generate_index(groups, depth)
+    groups.reject! { | group | group.children.empty? }
     # Now go through each group
     io = StringIO.new
     io.puts
-    toc.each do | group |
-      puts &quot;Generating #{group.name} group...&quot;
+    groups.each do | group |
       # Show the group heading unless there is only one group
-      io.puts &quot;## #{group.name}&quot; unless toc.size == 1
+      io.puts &quot;## #{group.name}&quot; unless groups.size == 1
       group.children.each do | doc_entry |
         doc_link = doc_entry.link
         io.puts &quot;### [#{doc_entry.name}](#{doc_link})&quot;
         doc_entry.children.each do | doc_section |
-          doc_section.write_entries(io)
+          doc_section.write_entries(io, depth)
         end
         io.puts 
       end
@@ -200,3 +213,4 @@ class Tendersync::Document
   end
   
 end
+</diff>
      <filename>lib/tendersync/document.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,17 +9,24 @@ class Tendersync::Runner
   class Error &lt; StandardError; end
   
   def initialize argv
-    
     @dry_run  = false
     @sections = []
-    
+    @groups = []
+    settings['groups'] ||= []
     @parser = OptionParser.new do |op|
       op.banner += &quot; command\n&quot;
       op.on('-n',                                  &quot;dry run&quot; )       { @dry_run  = true }
       op.on('-s', '--sections','=SECTIONS',Array,  &quot;section names, comma separated&quot; ) { |list| @sections = list }
       op.on('-u', '--username','=EMAIL',   String, &quot;*login e-mail&quot; ) {|str| settings['username'] = str }
       op.on('-p', '--password','=PASS',    String, &quot;*password&quot; )     {|str| settings['password'] = str }
-      op.on(      '--docurl',  '=URL',     String,  &quot;*tender site URL&quot; ) { |dir| settings['docurl'] = dir }
+      op.on(      '--docurl',  '=URL',     String, &quot;*tender site URL&quot; ) { |dir| settings['docurl'] = dir }
+      op.separator &quot;&quot;
+      op.on('-g', '--group',   '=TITLE;regex', String, &quot;*map of regex to group title for TOC groups &quot;) { | g |
+        pair = g.split(';')
+        settings['groups'] &lt;&lt; [pair.first, pair.last]
+      }
+      op.on('-d', '--depth',   '=DEPTH', String, &quot;*Number of levels to descend into a document being indexed&quot;) { | g | settings['depth'] = g.to_i }
+      
         %Q{
         * saved in .tendersync file for subsequent default
         
@@ -50,11 +57,11 @@ class Tendersync::Runner
     @root = settings['root']
     
     case
-      when ! @username
+    when ! @username
       raise Error, &quot;Please enter a username and password.  You only need to do this once.&quot;
-      when ! @password
+    when ! @password
       raise Error, &quot;Please enter a password.  You only need to do this once.&quot;
-      when ! @dochome
+    when ! @dochome
       raise Error, &quot;Please enter a --docurl indicating the home page URL of your Tender docs.\n&quot; +
            &quot;You only need to do this once.&quot;
     else
@@ -66,9 +73,9 @@ class Tendersync::Runner
     $session = Tendersync::Session.new @dochome, @username, @password
     $dry_run = @dry_run
     case @command || 'help'
-      when 'help'
+    when 'help'
       raise Error, @parser.to_s
-      when *%w[pull post create irb ls index]
+    when *%w[pull post create irb ls index]
       send @command
     else
       raise Error, &quot;Unknown command: #{@command}\n\n#{@parser}&quot;
@@ -163,17 +170,16 @@ EOF
     IRB.start
   end
   def index
-    if @dry_run
-      # FIXME I think we should build the sections, and not post
-      puts &quot;build index for #{sections} and post to tender&quot;
-    else
-      section_details = $session.all_sections
-      sections.each do |section|
-        doc = Tendersync::Document.index_for section, section_details[section]
-        puts &quot;indexing #{section}: #{doc.section}/#{doc.permalink}&quot;
-        doc.refresh_index []
-        doc.save
-      end
+    groups = settings['groups'].map do |title,regex|
+      regex = eval(regex) if regex =~ %r{^/.*/[a-z]*$}
+      Tendersync::Document::Group.new title, Regexp.new(regex)
+    end
+    section_details = $session.all_sections
+    sections.each do |section|
+      doc = Tendersync::Document.index_for section, section_details[section]
+      puts &quot;indexing #{section}: #{doc.section}/#{doc.permalink}&quot;
+      doc.refresh_index groups, settings['depth'] || 2
+      doc.save
     end
   end
   def sections
@@ -182,12 +188,12 @@ EOF
   end
   def settings
     case
-      when @settings
-        return @settings 
-      when File.exists?(&quot;.tendersync&quot;)
-        File.open(&quot;.tendersync&quot;, &quot;r&quot;) { |f| @settings = YAML.load(f) }
-      else
-        @settings = {}
+    when @settings
+      return @settings 
+    when File.exists?(&quot;.tendersync&quot;)
+      File.open(&quot;.tendersync&quot;, &quot;r&quot;) { |f| @settings = YAML.load(f) }
+    else
+      @settings = {}
     end
     def @settings.save!
       File.open(&quot;.tendersync&quot;,&quot;w&quot;) do |f|</diff>
      <filename>lib/tendersync/runner.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e9e1b34d5860668605627ba49069e22093c1b071</id>
    </parent>
  </parents>
  <author>
    <name>Bill Kayser</name>
    <email>bkayser@newrelic.com</email>
  </author>
  <url>http://github.com/newrelic/tendersync/commit/c17ec718a3b781d440effe6a89d3f0ff22e2cc16</url>
  <id>c17ec718a3b781d440effe6a89d3f0ff22e2cc16</id>
  <committed-date>2009-07-16T00:02:18-07:00</committed-date>
  <authored-date>2009-07-16T00:02:18-07:00</authored-date>
  <message>Finishing up indexing</message>
  <tree>a34eafd16dad27e3e1c63eb2cad1bf317793653d</tree>
  <committer>
    <name>Bill Kayser</name>
    <email>bkayser@newrelic.com</email>
  </committer>
</commit>
