[Borges-users] TreeMenu Component

Eric Hodel drbrain at segment7.net
Sun Apr 18 08:09:11 EDT 2004


Kaspar Schiess (eule at space.ch) wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hello all,
> 
> I have developed a small component that could be useful to everyone:
> Rendering a main menu in hierarchical tree form.

This is very nice, one thing to add (or change) would be to use methods
in addition to (or instead of) for supplying the action to perform, like
Borges::NavigationBar.  This will be much lighter weight than using
blocks alone (in memory footprint).

I have a preference for using <ul> or <ol> for nested lists over using
<div> for navigation-style menus, since there are many examples of
applying CSS in order to achieve a variety of nice affects (like
dropdown menus).  Also, it shows up will in text-only browsers.

(Why oh why did they take away <menu> and <dir>, only to taunt us with
<nl> in the vaporous, incompatible XHTML2??)

Shouldn't #is_parent_of? be in class TreeItem? and shouldn't it be named
#is_ancestor_of?  (Due to the until loop).

#render_on should only take one argument (a Renderer), so this method
should be #render_level_on or #render_tree_on.

class Borges::TreeMenu

  def render_on(r)
    render_tree_on(r, self.root, 1)
  end

  def render_tree_on(r, node, level)
    r.list_do(node.subs) do |subnode|
      if is_parent_of?(@selection, subnode) then
        if @selection == subnode then
          r.text(subnode.label)
        else 
          r.anchor(subnode.label) do item_action(subnode) end
        end
        
        self.render_on(r, subnode, level+1)
      else # draw node that has not yet been selected
        r.anchor(subnode.label) do item_action(subnode) end
      end
    end  # list_do
  end

end # class Borges::TreeMenu

-- 
Eric Hodel - drbrain at segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/borges-users/attachments/20040418/270a6098/attachment-0001.bin


More information about the Borges-users mailing list