Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed d0b12a8

Nav-Menu:

Converted the 'value' key in an input tree node to 'text', and modified
all places in the Unit tests accordingly.

  • Participants
  • Parent commits 8906031

Comments (0)

Files changed (8)

File module/HTML/Widgets/NavMenu/Test/Data.pm

     'tree_contents' =>
     {
         'host' => "default",
-        'value' => "Top 1",
+        'text' => "Top 1",
         'title' => "T1 Title",
         'subs' =>
         [
             {
-                'value' => "Home",
+                'text' => "Home",
                 'url' => "",
             },
             {
-                'value' => "About Me",
+                'text' => "About Me",
                 'title' => "About Myself",
                 'url' => "me/",
             },
     'tree_contents' =>
     {
         'host' => "default",
-        'value' => "Top 1",
+        'text' => "Top 1",
         'title' => "T1 Title",
         'subs' =>
         [
             {
-                'value' => "Home",
+                'text' => "Home",
                 'url' => "",
             },
             {
-                'value' => "About Me",
+                'text' => "About Me",
                 'title' => "About Myself",
                 'url' => "me/",
                 'subs' =>
                 [
                     {
                         'url' => "round/hello/personal.html",
-                        'value' => "Bio",
+                        'text' => "Bio",
                         'title' => "Biography of Myself",
                     },
                     {
                         'url' => "round/toto/",
-                        'value' => "Gloria",
+                        'text' => "Gloria",
                         'title' => "A Useful Conspiracy",
                     },
                 ],
             },
             {
-                'value' => "Tam Tam Drums",
+                'text' => "Tam Tam Drums",
                 'title' => "Drumming is good for your health",
                 'url' => "hoola/",
                 'host' => "other",
                     {
                         'url' => "hello/hoop.html",
                         'title' => "Hoola Hoops Rulez and Ownz!",
-                        'value' => "Hoola Hoops",
+                        'text' => "Hoola Hoops",
                         'host' => "default",
                     },
                     {
                         'url' => "tetra/",
-                        'value' => "Tetrahedron",
+                        'text' => "Tetrahedron",
                         'subs' =>
                         [
                             {
                                 'url' => "tetra/one/",
-                                'value' => "Tetra One",
+                                'text' => "Tetra One",
                                 'title' => "Tetra One Title",
                             },
                         ],
     'tree_contents' =>
     {
         'host' => "default",
-        'value' => "Top 1",
+        'text' => "Top 1",
         'title' => "T1 Title",
         'subs' =>
         [
             {
-                'value' => "Home",
+                'text' => "Home",
                 'url' => "",
             },
             {
-                'value' => "About Me",
+                'text' => "About Me",
                 'title' => "About Myself",
                 'url' => "me/",
             },
             {
-                'value' => "Foo",
+                'text' => "Foo",
                 'title' => "Fooish",
                 'url' => "foo/",
                 'subs' =>
                 [
                     {
-                        'value' => "Expanded",
+                        'text' => "Expanded",
                         'title' => "Expanded",
                         'url' => "foo/expanded/",
                         'expand' => { 're' => "", },
     'tree_contents' =>
     {
         'host' => "default",
-        'value' => "Top 1",
+        'text' => "Top 1",
         'title' => "T1 Title",
         'subs' =>
         [
             {
-                'value' => "Home",
+                'text' => "Home",
                 'url' => "",
             },
             {
-                'value' => "About Me",
+                'text' => "About Me",
                 'title' => "About Myself",
                 'url' => "me/",
             },
             {
-                'value' => "Show Always",
+                'text' => "Show Always",
                 'url' => "show-always/",
                 'show_always' => 1,
                 'subs' =>
                 [
                     {
-                        'value' => "Gandalf",
+                        'text' => "Gandalf",
                         'url' => "show-always/gandalf/",
                     },
                     {
-                        'value' => "Robin",
+                        'text' => "Robin",
                         'url' => "robin/",
                         'subs' =>
                         [
                             {
-                                'value' => "Hood",
+                                'text' => "Hood",
                                 'url' => "robin/hood/",
                             },
                         ],
                     },
                     {
-                        'value' => "Queen Esther",
+                        'text' => "Queen Esther",
                         'url' => "esther/",
                         'subs' =>
                         [
                             {
-                                'value' => "Haman",
+                                'text' => "Haman",
                                 'url' => "haman/",
                             },
                         ],
     'tree_contents' =>
     {
         'host' => "default",
-        'value' => "Top 1",
+        'text' => "Top 1",
         'title' => "T1 Title",
         'subs' =>
         [
             {
-                'value' => "Home",
+                'text' => "Home",
                 'url' => "",
             },
             {
-                'value' => "About Me",
+                'text' => "About Me",
                 'title' => "About Myself",
                 'url' => "me/",
                 'subs' =>
                 [
                     {
                         'url' => "me/bio.html",
-                        'value' => "Bio",
+                        'text' => "Bio",
                         'title' => "Biography of Myself",
                     },
                     {
                         'url' => "me/gloria/",
-                        'value' => "Gloria",
+                        'text' => "Gloria",
                         'title' => "A Useful Conspiracy",
                     },
                 ],
             },
             {
-                'value' => "Tam Tam Drums",
+                'text' => "Tam Tam Drums",
                 'title' => "Drumming is good for your health",
                 'url' => "hoola/",
             },
     'tree_contents' =>
     {
         'host' => "default",
-        'value' => "Top 1",
+        'text' => "Top 1",
         'title' => "T1 Title",
         'subs' =>
         [
             {
-                'value' => "Home",
+                'text' => "Home",
                 'url' => "",
             },
             {
-                'value' => "About Me",
+                'text' => "About Me",
                 'title' => "About Myself",
                 'url' => "me/",
                 'subs' =>
                 [
                     {
-                        'value' => "Group Hug",
+                        'text' => "Group Hug",
                         'url' => "me/group-hug/",
                     },
                     {
-                        'value' => "Cool I/O",
+                        'text' => "Cool I/O",
                         'url' => "me/cool-io/",
                     },
                     {
                         'skip' => 1,
                     },
                     {
-                        'value' => "Resume",
+                        'text' => "Resume",
                         'url' => "resume.html",
                     },
                 ],
                 'skip' => 1,
             },
             {
-                'value' => "Halifax",
+                'text' => "Halifax",
                 'url' => "halifax/",
             },
         ],
     'tree_contents' =>
     {
         'host' => "default",
-        'value' => "Top 1",
+        'text' => "Top 1",
         'title' => "T1 Title",
         'subs' =>
         [
             {
-                'value' => "Home",
+                'text' => "Home",
                 'url' => "",
             },
             {
-                'value' => "About Me",
+                'text' => "About Me",
                 'title' => "About Myself",
                 'url' => "me/",
                 'subs' =>
                 [
                     {
-                        'value' => "Visible",
+                        'text' => "Visible",
                         'url' => "me/visible/",
                     },
                     {
-                        'value' => "Hidden",
+                        'text' => "Hidden",
                         'url' => "me/hidden/",
                         'hide' => 1,
                     },
                     {
-                        'value' => "Visible Too",
+                        'text' => "Visible Too",
                         'url' => "me/visible-too/",
                     },
                 ],
     'tree_contents' =>
     {
         'host' => "default",
-        'value' => "Top 1",
+        'text' => "Top 1",
         'title' => "T1 Title",
         'subs' =>
         [
             {
-                'value' => "Home",
+                'text' => "Home",
                 'url' => "",
             },
             {
-                'value' => "About Me",
+                'text' => "About Me",
                 'title' => "About Myself",
                 'url' => "me/",
                 'role' => "header",
                 'subs' =>
                 [
                     {
-                        'value' => "Sub Me",
+                        'text' => "Sub Me",
                         'url' => "me/sub-me1/",
                     },
                     {
-                        'value' => "Sub Me 2",
+                        'text' => "Sub Me 2",
                         'url' => "me/sub-me-two/",
                     },
                 ],
     'tree_contents' =>
     {
         'host' => "default",
-        'value' => "Top 1",
+        'text' => "Top 1",
         'title' => "T1 Title",
         'subs' =>
         [
             {
-                'value' => "Home",
+                'text' => "Home",
                 'url' => "",
             },
             {
-                'value' => "About Me",
+                'text' => "About Me",
                 'title' => "About Myself",
                 'url' => "me/",
                 'expand' => { 're' => "^me/", },
                 'subs' =>
                 [
                     {
-                        'value' => "Group Hug",
+                        'text' => "Group Hug",
                         'url' => "me/group-hug/",
                     },
                     {
-                        'value' => "Cool I/O",
+                        'text' => "Cool I/O",
                         'url' => "me/cool-io/",
                     },
                     {
-                        'value' => "Resume",
+                        'text' => "Resume",
                         'url' => "resume.html",
                     },
                 ],
             },
             {
-                'value' => "Halifax",
+                'text' => "Halifax",
                 'url' => "halifax/",
             },
             {
-                'value' => "Software",
+                'text' => "Software",
                 'title' => "Open Source Software I Wrote",
                 'url' => "open-source/",
                 'expand' => { 're' => "^open-source/", },
                 'subs' =>
                 [
                     {
-                        'value' => "Fooware",
+                        'text' => "Fooware",
                         'url' => "open-source/fooware/",
                     },
                     {
-                        'value' => "Condor-Man",
+                        'text' => "Condor-Man",
                         'title' => "Kwalitee",
                         'url' => "open-source/condor-man/",
                     },

File module/lib/HTML/Widgets/NavMenu.pm

                         'host' => $host,
                         'host_url' => $host_url,
                         'title' => $ptr->{title},
-                        'label' => $ptr->{value},
+                        'label' => $ptr->{text},
                         'direct_url' =>
                             $self->get_cross_host_rel_url(
                                 'host' => $host,
             'tree_contents' =>
             {
                 'host' => "default",
-                'value' => "Top 1",
+                'text' => "Top 1",
                 'title' => "T1 Title",
                 'expand_re' => "",
                 'subs' =>
                 [
                     {
-                        'value' => "Home",
+                        'text' => "Home",
                         'url' => "",
                     },
                     {
-                        'value' => "About Me",
+                        'text' => "About Me",
                         'title' => "About Myself",
                         'url' => "me/",
                     },
 
 This module generates a navigation menu for a site. It can also generate
 a complete site map, a path of leading components, and also keeps
-track of navigation links ("Next", "Prev", "Up", etc.) It's a little bit 
-scarse on documentation now, because it's still was not made ready for
-public consumption yet. You can start from the example above and see more
-examples in the tests, and complete working sites in the Subversion
-repositories at L<http://stalker.iguide.co.il:8080/svn/shlomif-homepage/>
+track of navigation links ("Next", "Prev", "Up", etc.) You can start from the 
+example above and see more examples in the tests, and complete working sites 
+in the Subversion repositories at 
+L<http://stalker.iguide.co.il:8080/svn/shlomif-homepage/>
 and L<http://opensvn.csie.org/perlbegin/perl-begin/>.
 
 To use this module call the constructor with the following named arguments:
 
 The URL should be specified for every nodes except separators and the such.
 
-=item 'value'
+=item 'text'
 
 This is the text that will be presented to the user as the text of the 
-link inside the navigation bar. E.g.: if C<'value'> is "Hi There", then the
+link inside the navigation bar. E.g.: if C<'text'> is "Hi There", then the
 link will look something like this:
 
     <a href="my-url/">Hi There</a>
 =item 'title'
 
 This is the text of the link tag's title attribute. It is also not
-processed and so the user of the module, should make sure it is escaped
+processed and so the user of the module should make sure it is escaped
 if needed, to prevent HTML-injection attacks. It is optional, and if not
 specified, no title will be presented.
 
 
 =item label
 
-The label of the node. (one given in its 'value' key). This is not
+The label of the node. (one given in its 'text' key). This is not
 SGML-escaped.
 
 =item title 

File module/lib/HTML/Widgets/NavMenu/Iterator/Html.pm

+package HTML::Widgets::NavMenu::Iterator::Html;
+
+use base qw(HTML::Widgets::NavMenu::Iterator::Base);
+
+sub node_start
+{
+    my $self = shift;
+
+    if ($self->_is_root())
+    {
+        return $self->start_root();
+    }
+    elsif ($self->_is_top_separator())
+    {
+        # start_sep() is short for start_separator().
+        return $self->start_sep();
+    }
+    else
+    {
+        return $self->start_regular();
+    }
+}
+
+sub node_end
+{
+    my $self = shift;
+
+    if ($self->_is_root())
+    {
+        return $self->end_root();
+    }
+    elsif ($self->_is_top_separator())
+    {
+        return $self->end_sep();
+    }
+    else
+    {
+        return $self->end_regular();
+    }
+}
+
+sub end_root
+{
+    my $self = shift;
+
+    $self->_add_tags("</ul>");
+}
+
+sub end_regular
+{
+    my $self = shift;
+    if ($self->top()->num_subs() && $self->is_expanded())
+    {
+        $self->_add_tags("</ul>");
+    }
+    $self->_add_tags("</li>");
+}
+
+sub node_should_recurse
+{
+    my $self = shift;
+    return $self->is_expanded();
+}
+
+# Get the HTML <a href=""> tag.
+#
+sub get_a_tag
+{
+    my $self = shift;
+    my $node = $self->top->node;
+
+    my $tag ="<a";
+    my $title = $node->title;
+
+    $tag .= " href=\"" .
+        CGI::escapeHTML(
+            $self->nav_menu()->get_cross_host_rel_url(
+                'host' => $self->_get_top_host(),
+                'host_url' => $node->url(),
+            )
+        ). "\"";
+    if (defined($title))
+    {
+        $tag .= " title=\"$title\"";
+    }
+    $tag .= ">" . $node->text() . "</a>";
+    return $tag;
+}
+
+1;
+

File module/lib/HTML/Widgets/NavMenu/Iterator/NavMenu.pm

     my $node = $self->top->node();
     if ($node->CurrentlyActive())
     {
-        return "<b>" . $node->value() . "</b>";
+        return "<b>" . $node->text() . "</b>";
     }
     else
     {

File module/lib/HTML/Widgets/NavMenu/Tree/Node.pm

 
 __PACKAGE__->mk_accessors(
     qw(CurrentlyActive expanded hide host role separator show_always),
-    qw(subs title url value)
+    qw(subs title url text)
     );
 
 sub initialize
 {
     my $self = shift;
 
-    return (qw(host role show_always title url value));
+    return (qw(host role show_always title url text));
 }
 
 sub list_boolean_keys

File module/t/02site-map.t

+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More tests => 4;
+
+use HTML::Widgets::NavMenu;
+
+use HTML::Widgets::NavMenu::Test::Data;
+
+my $test_data = get_test_data();
+
+{
+    my $nav_menu = HTML::Widgets::NavMenu->new(
+        'path_info' => "hello/",
+        @{$test_data->{'minimal'}},
+    );
+
+    my $returned_text = $nav_menu->gen_site_map();
+    my $expected_text = <<"EOF";
+<ul>
+<li>
+<a href="../">Home</a>
+</li>
+<li>
+<a href="../me/" title="About Myself">About Me</a> - About Myself
+</li>
+</ul>
+EOF
+    is($returned_text, $expected_text, "site_map #1"); # TEST
+}
+
+{
+    my $nav_menu = HTML::Widgets::NavMenu->new(
+        'path_info' => "hello/",
+        'current_host' => "default",
+        'hosts' => { 'default' => { 'base_url' => "http://www.hello.com/" }, },
+        'tree_contents' =>
+        {
+            'host' => "default",
+            'text' => "Top 1",
+            'title' => "T1 Title",
+            'expand_re' => "",
+            'subs' =>
+            [
+                {
+                    'text' => "Home",
+                    'url' => "",
+                },
+                {
+                    'text' => "About Me",
+                    'title' => "About Myself",
+                    'url' => "me/",
+                    'subs' =>
+                    [
+                        {
+                            'url' => "round/hello/personal.html",
+                            'text' => "Bio",
+                            'title' => "Biography of Myself",
+                        },
+                    ],
+                },
+            ],
+        },
+    );
+
+    my $returned_text = $nav_menu->gen_site_map();
+    my $expected_text = <<"EOF";
+<ul>
+<li>
+<a href="../">Home</a>
+</li>
+<li>
+<a href="../me/" title="About Myself">About Me</a> - About Myself
+<br />
+<ul>
+<li>
+<a href="../round/hello/personal.html" title="Biography of Myself">Bio</a> - Biography of Myself
+</li>
+</ul>
+</li>
+</ul>
+EOF
+    is($returned_text, $expected_text, "site_map #2"); # TEST
+}
+
+{
+    my $nav_menu = HTML::Widgets::NavMenu->new(
+        'path_info' => "hello/world/",
+        @{$test_data->{'two_sites'}},
+    );
+
+    my $returned_text = $nav_menu->gen_site_map();
+    my $expected_text = <<"EOF";
+<ul>
+<li>
+<a href="../../">Home</a>
+</li>
+<li>
+<a href="../../me/" title="About Myself">About Me</a> - About Myself
+<br />
+<ul>
+<li>
+<a href="../../round/hello/personal.html" title="Biography of Myself">Bio</a> - Biography of Myself
+</li>
+<li>
+<a href="../../round/toto/" title="A Useful Conspiracy">Gloria</a> - A Useful Conspiracy
+</li>
+</ul>
+</li>
+<li>
+<a href="http://www.other-url.co.il/~shlomif/hoola/" title="Drumming is good for your health">Tam Tam Drums</a> - Drumming is good for your health
+<br />
+<ul>
+<li>
+<a href="../hoop.html" title="Hoola Hoops Rulez and Ownz!">Hoola Hoops</a> - Hoola Hoops Rulez and Ownz!
+</li>
+<li>
+<a href="http://www.other-url.co.il/~shlomif/tetra/">Tetrahedron</a>
+<br />
+<ul>
+<li>
+<a href="http://www.other-url.co.il/~shlomif/tetra/one/" title="Tetra One Title">Tetra One</a> - Tetra One Title
+</li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+EOF
+    is($returned_text, $expected_text, "site_map - complex"); # TEST
+}
+
+# Now testing that the separator is safely skipped and does not generate
+# a double </li>
+{
+    my $nav_menu = HTML::Widgets::NavMenu->new(
+        'path_info' => "hello/",
+        'current_host' => "default",
+        'hosts' => { 'default' => { 'base_url' => "http://www.hello.com/" }, },
+        'tree_contents' =>
+        {
+            'host' => "default",
+            'text' => "Top 1",
+            'title' => "T1 Title",
+            'expand_re' => "",
+            'subs' =>
+            [
+                {
+                    'text' => "Home",
+                    'url' => "",
+                },
+                {
+                    'text' => "About Me",
+                    'title' => "About Myself",
+                    'url' => "me/",
+                },
+                {
+                    'separator' => 1,
+                    'skip' => 1,
+                },
+                {
+                    'text' => "Hoola",
+                    'title' => "Hoola Hoop",
+                    'url' => "me-too/",
+                },
+            ],
+        },
+    );
+
+    my $returned_text = $nav_menu->gen_site_map();
+    my $expected_text = <<"EOF";
+<ul>
+<li>
+<a href="../">Home</a>
+</li>
+<li>
+<a href="../me/" title="About Myself">About Me</a> - About Myself
+</li>
+<li>
+<a href="../me-too/" title="Hoola Hoop">Hoola</a> - Hoola Hoop
+</li>
+</ul>
+EOF
+    is($returned_text, $expected_text, "site_map - separator"); # TEST
+
+    
+
+}
+

File module/t/03nav-links.t

+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More tests => 3;
+
+use HTML::Widgets::NavMenu;
+
+my @site_args = 
+(
+    'current_host' => "default",
+    'hosts' => { 'default' => { 'base_url' => "http://www.hello.com/" }, },
+    'tree_contents' =>
+    {
+        'host' => "default",
+        'text' => "Top 1",
+        'title' => "T1 Title",
+        'expand_re' => "",
+        'subs' =>
+        [
+            {
+                'text' => "Home",
+                'url' => "",
+            },
+            {
+                'text' => "About Me",
+                'title' => "About Myself",
+                'url' => "me/",
+            },
+            {
+                'text' => "Last Page",
+                'title' => "Last Page",
+                'url' => "last-page.html",
+            }
+        ],
+    },    
+);
+
+# The purpose of this test is to check for the in-existence of navigation
+# links from the first page. Generally, there shouldn't be "top", "up" and 
+# "prev" nav-links and only "next".
+{
+    my $nav_menu = HTML::Widgets::NavMenu->new(
+        'path_info' => "/",
+        @site_args
+    );
+
+    my $rendered = $nav_menu->render();
+
+    my $nav_links = $rendered->{'nav_links'};
+    
+    # TEST
+    ok ((scalar(keys(%$nav_links)) == 1) && (exists($nav_links->{'next'})),
+        "Lack of Nav-Links in the First Page")
+}
+
+# The purpose of this test is to check for up arrow leading from the middle
+# page to the "Home" page
+{
+    my $nav_menu = HTML::Widgets::NavMenu->new(
+        'path_info' => "/me/",
+        @site_args
+    );
+
+    my $rendered = $nav_menu->render();
+
+    my $nav_links = $rendered->{'nav_links'};
+
+    # TEST
+    is($nav_links->{'up'}, "../",
+       "Up page leading upwards to the first page.");
+    # TEST
+    is($nav_links->{'top'}, "../",
+       "Top nav-link leading topwards to the first page.");
+}

File module/t/08tree-node.t

 
     $node->set("url", "Rabbi/Zalman/");
     is($node->url(), "Rabbi/Zalman/", "Testing for URL Setting"); # TEST
-    $node->set("value", "Trail of Innocence");
-    is($node->value(), "Trail of Innocence", "Testing for value"); # TEST
+    $node->set("text", "Trail of Innocence");
+    is($node->text(), "Trail of Innocence", "Testing for text"); # TEST
     $node->set("show_always", 1);
     is($node->show_always(), 1, "Set/get show_always"); # TEST 
     $node->set("title", "It's Raining");
     # Testing again for the same values to see that they are still OK.
 
     is($node->url(), "Rabbi/Zalman/", "Testing for URL Setting"); # TEST
-    is($node->value(), "Trail of Innocence", "Testing for value"); # TEST
+    is($node->text(), "Trail of Innocence", "Testing for text"); # TEST
     is($node->show_always(), 1, "Set/get show_always");  # TEST
     is($node->title(), "It's Raining", "Set/get title"); # TEST
     is($node->host(), "vipe", "Set/get host"); # TEST