1. Shlomi Fish
  2. perl-HTML-Widgets-NavMenu

Commits

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

Added the no_leading_dot option and bumped the version number.

  • Participants
  • Parent commits f9700c2
  • Branches default
  • Tags cpan-releases/1.x/1.02/1.0200

Comments (0)

Files changed (5)

File module/Changes

View file
  • Ignore whitespace
 Revision history for Perl extension Shlomif::NavMenu.
 
+1.0200    Sun Mar 23 21:53:37 IST 2008
     - Removed trailing whitespace from "# TEST" lines - this can confuse
     early version of Test-Count
+    - Fixed a "# TEST" instead of a "# TESTbr" line that confused Test-Count.
+    - Added the no_leading_dot option with a test.
 
 1.0100    Fri Feb  8 19:19:09 IST 2008
     - Fixed a bug in HTML::Widgets::NavMenu::Url:

File module/META.yml

View file
  • Ignore whitespace
 ---
 name: HTML-Widgets-NavMenu
-version: 1.0100
+version: 1.0200
 author:
   - |-
     Shlomi Fish E<lt>shlomif@iglu.org.ilE<gt> 
 provides:
   HTML::Widgets::NavMenu:
     file: lib/HTML/Widgets/NavMenu.pm
-    version: 1.0100
+    version: 1.0200
   HTML::Widgets::NavMenu::Error:
     file: lib/HTML/Widgets/NavMenu.pm
   HTML::Widgets::NavMenu::Error::Redirect:

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

View file
  • Ignore whitespace
 
 package HTML::Widgets::NavMenu;
 
-our $VERSION = '1.0100';
+our $VERSION = '1.0200';
 
 package HTML::Widgets::NavMenu::Error;
 
 
     $self->{'ul_classes'} = ($args{'ul_classes'} || []);
 
+    $self->{'no_leading_dot'} =
+        exists($args{'no_leading_dot'}) ? $args{'no_leading_dot'} : 0;
+
     return 0;
 }
 
 {
     my $from_text = shift;
     my $to_text = shift(@_);
+    my $no_leading_dot = shift;
 
     my $from_url = _text_to_url_obj($from_text);
     my $to_url = _text_to_url_obj($to_text);
     my $ret = 
         $from_url->_get_relative_url(
             $to_url, 
-            _is_slash_terminated($from_text)
+            _is_slash_terminated($from_text),
+            $no_leading_dot,
         );
    return $ret;
 }
     }
     elsif ($url_type eq "rel")
     {
-        return _get_relative_url($self->path_info(), $host_url);
+        return _get_relative_url(
+            $self->path_info(), $host_url, $self->{'no_leading_dot'}
+        );
     }
     elsif ($url_type eq "site_abs")
     {
     my %nav_links;
     my %nav_links_obj;
 
-    my %links_proto = 
+    my %links_proto =
         (
             'prev' => $self->_get_coords_while_skipping_skips(
                         \&_get_prev_coords),
 
     my $js_code = "";
     
-    return 
+    return
         {
             'html' => $html,
             'leading_path' => $self->_get_leading_path(),
 
 If classes are undef, the UL tag will not contain a class parameter.
 
+=item no_leading_dot
+
+When this parameter is set to 1, the object will try to generate URLs that
+do not start with "./" when possible. That way, the generated markup will
+be a little more compact. This option is not enabled by default for
+backwards compatibility, but is highly recommended.
+
 =back
 
 A complete invocation of an HTML::Widgets::NavMenu constructor can be

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

View file
  • Ignore whitespace
 sub _get_relative_url
 {
     my $base = shift;
+
+    my $url = $base->_get_url_worker(@_);
+
+    return ( ($url eq "") ? "./" : $url);
+}
+
+sub _get_url_worker
+{
+    my $base = shift;
     my $to = shift;
     my $slash_terminated = shift;
+    my $no_leading_dot = shift;
+
+    my $prefix = ($no_leading_dot ? "" : "./");
 
     my @this_url = @{$base->_get_url()};
     my @other_url = @{$to->_get_url()};
         {
             if (scalar(@this_url_bak))
             {
-                return "./" . $this_url_bak[-1];
+                return $prefix . $this_url_bak[-1];
             }
             else
             {
     {
         if ((scalar(@this_url) == 0) && (scalar(@other_url) == 0))
         {
-            $ret = "./";
+            $ret = $prefix;
         }
         else
         {
     else
     {
         my @components = ((map { ".." } @this_url[1..$#this_url]), @other_url);
-        $ret .= ("./" . join("/", @components)); 
+        $ret .= ($prefix . join("/", @components)); 
         if (($to->_is_dir()) && ($base->{'mode'} ne "harddisk") && scalar(@components))
         {
             $ret .= "/";

File module/t/04nav-menu.t

View file
  • Ignore whitespace
 
 use strict;
 
-use Test::More tests => 24;
+use Test::More tests => 25;
 
 use HTML::Widgets::NavMenu;
 use HTML::Widgets::NavMenu::HeaderRole;
 </ul>
 EOF
 
-    # TESTbr 
+    # TEST
     test_nav_menu($rendered, $expected_string, "Nav Menu with a role of \"header\""); 
 }
 
     # TEST
     test_nav_menu($rendered, $expected_string, "Non Capturing Expand"); 
 }
+
+# This test tests that the URLs do not have "./" prepended to them
+# when given the no_leading_dot option.
+{
+    my $nav_menu = HTML::Widgets::NavMenu->new(
+        'path_info' => "/me/bio.html",
+        @{$test_data->{'items_in_sub'}},
+        'ul_classes' => [ "navbarmain", ("navbarnested") x 5 ],
+        no_leading_dot => 1,
+    );
+
+    my $rendered = 
+        $nav_menu->render();
+
+    my $expected_string = <<"EOF";
+<ul class="navbarmain">
+<li>
+<a href="../">Home</a>
+</li>
+<li>
+<a href="./" title="About Myself">About Me</a>
+<br />
+<ul class="navbarnested">
+<li>
+<b>Bio</b>
+</li>
+<li>
+<a href="gloria/" title="A Useful Conspiracy">Gloria</a>
+</li>
+</ul>
+</li>
+<li>
+<a href="../hoola/" title="Drumming is good for your health">Tam Tam Drums</a>
+</li>
+</ul>
+EOF
+
+    # TEST
+    test_nav_menu($rendered, $expected_string, "no_leading_dot removes the extra ./");
+}