<commit_before>module Webby
  class PagesDB
    def immediate_children( page, opts = {} )
      root = page.dir == "" ? "" : "#{page.dir}/"
      rgxp = Regexp.new "\\A#{root}[^/]+$"
      keys = @db.keys.find_all {|k| rgxp =~ k}

      ary  = keys.map {|k| @db[k]}
      ary.flatten!

      return ary unless opts.has_key? :sort_by

      m = opts[:sort_by]
      ary.sort! {|a,b| a.__send__(m) <=> b.__send__(m)}
      ary.reverse! if opts[:reverse]
      ary
    end
  end
  
  class Resource
    def link
      "<a href=\"#{url}\">#{title}</a>"
    end
    
    def order
      (@mdata['order'] || 10000).to_i
    end
    
    def parent
      parent_path = filename == 'index' ? dir.split("/")[0..-2].join("/") : dir
      p = self.class.pages.find( :filename => 'index', :in_directory => parent_path ) rescue nil
      p == self ? nil : p
    end
    
    def path_from_root
      resources = []
      resource = self
      while(resource)
        resources << resource
        resource = resource.parent
      end
      resources.reverse
    end
    
    def siblings
      self.class.pages.siblings(self).reject{|p| p.title.nil?}
    end

    def immediate_children
      self.class.pages.immediate_children(self).reject{|p| p.title.nil?}.select{|p| p.filename == 'index'}
    end
  end
  
  require File.dirname(__FILE__) + '/../../rspec/lib/spec/version'
  class Renderer
    def rspec_version
      Spec::VERSION::STRING
    end

    def svn_tag
      Spec::VERSION::TAG
    end
    
    def breadcrumb_menu(page)
      '<div class="breadcrumb-menu">' + breadcrumbs(page) + menu(page) + '</div>'
    end
    
    def breadcrumbs(page)
      b = binding
      ERB.new(<<-EOF, nil, '-').result(b)
      <div class="breadcrumbs">
        <ul>
        <% page.path_from_root.each do |p| %>
          <% if p != page %>
            <li><%= p.link %></li>
          <% else %>
            <li class="selected"><span><%= p.title %></span></li>
          <% end %>
        <% end %>
        </ul>
      </div>
      EOF
    end

    def menu(page)
      pages = if page.filename == 'index'
        (page.siblings + page.immediate_children).sort{|a,b| a.order <=> b.order}
      else
        []
      end
      
      sanity_check(pages)
      
      b = binding
      ERB.new(<<-EOF, nil, '-').result(b)
      <div class="menu">
        <ul>
        <% pages.each do |p| %>
          <li>
            <%= p.link %>
          </li>
        <% end %>
        </ul>
      </div>
      EOF
    end
    
    def sanity_check(pages)
      orders = pages.map{|p| p.order}<commit_msg>added rdoc links<commit_after>module Webby
  class PagesDB
    def immediate_children( page, opts = {} )
      root = page.dir == "" ? "" : "#{page.dir}/"
      rgxp = Regexp.new "\\A#{root}[^/]+$"
      keys = @db.keys.find_all {|k| rgxp =~ k}

      ary  = keys.map {|k| @db[k]}
      ary.flatten!

      return ary unless opts.has_key? :sort_by

      m = opts[:sort_by]
      ary.sort! {|a,b| a.__send__(m) <=> b.__send__(m)}
      ary.reverse! if opts[:reverse]
      ary
    end
  end
  
  class Resource
    def link
      "<a href=\"#{url}\">#{title}</a>"
    end
    
    def order
      (@mdata['order'] || 10000).to_i
    end
    
    def parent
      parent_path = filename == 'index' ? dir.split("/")[0..-2].join("/") : dir
      p = self.class.pages.find( :filename => 'index', :in_directory => parent_path ) rescue nil
      p == self ? nil : p
    end
    
    def path_from_root
      resources = []
      resource = self
      while(resource)
        resources << resource
        resource = resource.parent
      end
      resources.reverse
    end
    
    def siblings
      self.class.pages.siblings(self).reject{|p| p.title.nil?}
    end

    def immediate_children
      self.class.pages.immediate_children(self).reject{|p| p.title.nil?}.select{|p| p.filename == 'index'}
    end
  end
  
  require File.dirname(__FILE__) + '/../../rspec/lib/spec/version'
  class Renderer
    def rspec_version
      Spec::VERSION::STRING
    end

    def svn_tag
      Spec::VERSION::TAG
    end
    
    def breadcrumb_menu(page)
      '<div class="breadcrumb-menu">' + breadcrumbs(page) + menu(page) + '</div>'
    end
    
    def breadcrumbs(page)
      b = binding
      ERB.new(<<-EOF, nil, '-').result(b)
      <div class="breadcrumbs">
        <ul>
        <% page.path_from_root.each do |p| %>
          <% if p != page %>
            <li><%= p.link %></li>
          <% else %>
            <li class="selected"><span><%= p.title %></span></li>
          <% end %>
        <% end %>
        </ul>
      </div>
      EOF
    end

    def menu(page)
      pages = if page.filename == 'index'
        (page.siblings + page.immediate_children).sort{|a,b| a.order <=> b.order}
      else
        []
      end
      
      sanity_check(pages)
      
      b = binding
      ERB.new(<<-EOF, nil, '-').result(b)
      <div class="menu">
        <ul>
        <% pages.each do |p| %>
          <li>
            <%= p.link %>
          </li>
        <% end %>
        <% if page.url == '/index.html'  %>
          <li>
            <a href="/rdoc/">RDoc</a>
          </li>
          <li>
            <a href="/rdoc-rails/">RDoc-Rails</a>
          </li>
        <% end %>
        </ul>
      </div>
      EOF
    end
    
    def sanity_check(pages)
      orders = pages.map{|p| p.order}
{'fraction_non_alphanumeric': 0.16769030336869534, 'fraction_numerical': 0.0026056206960729574, 'mean_word_length': 1.7141414141414142, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7113801', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1840, 'n_words': 387}