[Rt-commit] rt branch, 4.2/render-menu-in-lib, created. rt-4.0.8-568-g523f879
Ruslan Zakirov
ruz at bestpractical.com
Sun Nov 25 06:32:28 EST 2012
The branch, 4.2/render-menu-in-lib has been created
at 523f879cd1bbf4a097a3395029957112153cca55 (commit)
- Log -----------------------------------------------------------------
commit 523f879cd1bbf4a097a3395029957112153cca55
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sat Aug 25 21:20:25 2012 +0400
RenderMenu in libs instead of Menu component
code is faster and cleaner
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index c9928c6..f5d7d02 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1529,7 +1529,88 @@ sub PageWidgets {
return $HTML::Mason::Commands::m->notes('page-widgets');
}
+sub RenderMenu {
+ my %args = (toplevel => 1, parent_id => '', depth => 0, @_);
+ return unless $args{'menu'};
+
+ my ($menu, $depth, $toplevel, $id, $parent_id)
+ = @args{qw(menu depth toplevel id parent_id)};
+
+ my $interp = $m->interp;
+ my $web_path = RT->Config->Get('WebPath');
+
+ my $res = '';
+ $res .= ' ' x $depth;
+ $res .= '<ul';
+ $res .= ' id="'. $interp->apply_escapes($id, 'h') .'"'
+ if $id;
+ $res .= ' class="toplevel"' if $toplevel;
+ $res .= ">\n";
+
+ for my $child ($menu->children) {
+ $res .= ' 'x ($depth+1);
+
+ my $item_id = lc(($parent_id? "$parent_id-" : "") .$child->key);
+ $item_id =~ s/\s/-/g;
+ my $eitem_id = $interp->apply_escapes($item_id, 'h');
+ $res .= qq{<li id="li-$eitem_id"};
+
+ my @classes;
+ push @classes, 'has-children' if $child->has_children;
+ push @classes, 'active' if $child->active;
+ $res .= ' class="'. join( ' ', @classes ) .'"'
+ if @classes;
+
+ $res .= '>';
+
+ if ( my $tmp = $child->raw_html ) {
+ $res .= $tmp;
+ } else {
+ $res .= qq{<a id="$eitem_id" class="menu-item};
+ if ( $tmp = $child->class ) {
+ $res .= ' '. $interp->apply_escapes($tmp, 'h');
+ }
+ $res .= '"';
+
+ my $path = $child->path;
+ my $url = (not $path or $path =~ m{^\w+:/}) ? $path : $web_path . $path;
+ $res .= ' href="'. $interp->apply_escapes($url, 'h') .'"'
+ if $url;
+
+ if ( $tmp = $child->target ) {
+ $res .= ' target="'. $interp->apply_escapes($tmp, 'h') .'"'
+ }
+ $res .= '>';
+
+ if ( $child->escape_title ) {
+ $res .= $interp->apply_escapes($child->title, 'h');
+ } else {
+ $res .= $child->title;
+ }
+ $res .= '</a>';
+ }
+ if ( $child->has_children ) {
+ $res .= "\n";
+ $res .= RenderMenu(
+ menu => $child,
+ toplevel => 0,
+ parent_id => $item_id,
+ depth => $depth+1,
+ return => 1,
+ );
+ $res .= "\n";
+ $res .= ' ' x ($depth+1);
+ }
+ $res .= "</li>\n";
+ }
+ $res .= ' ' x $depth;
+ $res .= '</ul>';
+ return $res if $args{'return'};
+
+ $m->print($res);
+ return '';
+}
=head2 loc ARRAY
diff --git a/share/html/Elements/Menu b/share/html/Elements/Menu
index b56bacd..ef04f1f 100644
--- a/share/html/Elements/Menu
+++ b/share/html/Elements/Menu
@@ -45,36 +45,6 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-% return unless ($menu);
-<%" " x $depth%><ul<%$id ? ' id="'.$id.'"' : '' |n%><% $toplevel? ' class="toplevel"' : '' |n %>>
-% for my $child ($menu->children) {
-% my $item_id = lc(($parent_id? $parent_id."-" : "") .$child->key);
-% $item_id =~ s/\s/-/g;
-% my @classes;
-% push @classes, 'has-children' if $child->has_children;
-% push @classes, 'active' if $child->active;
-<%" " x ($depth+1)%><li id="li-<%$item_id%>"\
-% if (@classes) {
- class="<% join ' ', @classes %>"\
-% }
->\
-% if ($child->raw_html) {
-<% $child->raw_html |n %>
-% } else {
-% my $url = (not $child->path or $child->path =~ m{^\w+:/}) ? $child->path : RT->Config->Get('WebPath').$child->path;
-<a id="<%$item_id%>" class="menu-item <% $child->class || '' %>"<% $child->path ? ' href="'.$url.'"' : '' |n%><% $child->target ? ' target="'.$child->target.'"' : '' |n %>>\
-<% $child->escape_title ? $m->interp->apply_escapes($child->title, 'h') : $child->title |n %>\
-</a>\
-% }
-% if ($child->has_children) {
-
-<& Menu, menu => $child, toplevel => 0, parent_id => ($parent_id? $parent_id."-": '').$child->key, depth=> ($depth+1) &>
-<%" " x ($depth+1)%></li>
-% } else {
-</li>
-% }
-% }
-<%" " x $depth%></ul>\
<%ARGS>
$menu
$id => undef
@@ -82,3 +52,6 @@ $toplevel => 1
$parent_id => ''
$depth => 0
</%ARGS>
+<%INIT>
+RenderMenu( %ARGS );
+</%INIT>
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list