[Jifty-commit] r4971 - in jifty/trunk: . lib/Jifty/Mason lib/Jifty/Plugin share/web/static/js
Jifty commits
jifty-commit at lists.jifty.org
Fri Feb 1 12:52:56 EST 2008
Author: sartak
Date: Fri Feb 1 12:52:43 2008
New Revision: 4971
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Mason/Halo.pm
jifty/trunk/lib/Jifty/Plugin/Halo.pm
jifty/trunk/share/web/static/css/halos.css
jifty/trunk/share/web/static/js/halo.js
Log:
r51316 at onn: sartak | 2008-02-01 12:47:44 -0500
Halo refactor to allow arbitrary plugins to add their data to be displayed
Modified: jifty/trunk/lib/Jifty/Mason/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Mason/Halo.pm (original)
+++ jifty/trunk/lib/Jifty/Mason/Halo.pm Fri Feb 1 12:52:43 2008
@@ -31,21 +31,18 @@
return if ($context->comp->path || '') eq "/__jifty/halo";
- my $ID = Jifty->web->serial;
my $STACK = Jifty->handler->stash->{'_halo_stack'} ||= [];
my $INDEX_STACK = Jifty->handler->stash->{'_halo_index_stack'} ||= [];
my $DEPTH = ++Jifty->handler->stash->{'_halo_depth'};
- my $frame = {
- id => $ID,
+ my $frame = Jifty::Plugin::Halo->new_frame(
args => [map { eval { defined $_ and fileno( $_ ) } ? "*GLOB*" : $_} @{$context->args}],
- start_time => time,
path => $context->comp->path || '',
subcomponent => $context->comp->is_subcomp() ? 1 : 0,
name => $context->comp->name || '(Unnamed component)',
proscribed => $self->_unrendered_component($context) ? 1 : 0,
depth => $DEPTH,
- };
+ );
my $previous = $STACK->[-1];
push @$STACK, $frame;
Modified: jifty/trunk/lib/Jifty/Plugin/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Halo.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Halo.pm Fri Feb 1 12:52:43 2008
@@ -42,9 +42,8 @@
sub around_template {
my ($self, $orig, $path, $args, $code) = @_;
- my $ID = Jifty->web->serial;
- my $STACK = Jifty->handler->stash->{'_halo_stack'} ||= [];
- my $DEPTH = ++Jifty->handler->stash->{'_halo_depth'};
+ my $STACK = Jifty->handler->stash->{'_halo_stack'} ||= [];
+ my $DEPTH = ++Jifty->handler->stash->{'_halo_depth'};
# for now, call the last piece of the template's path the name
$path =~ m{.*/(.+)};
@@ -55,17 +54,13 @@
Data::Dump::Streamer::Dump($code)->Out;
};
- my $frame = {
- id => $ID,
- args => [ %{ Jifty->web->request->arguments } ], # ugh :)
- start_time => time,
- path => $path,
- subcomponent => 0,
- name => $name,
- proscribed => 0,
- depth => $DEPTH,
- perl => $deparsed,
- };
+ my $frame = $self->new_frame(
+ args => [ %{ Jifty->web->request->arguments } ], # ugh :)
+ path => $path,
+ name => $name,
+ depth => $DEPTH,
+ perl => $deparsed,
+ );
# if this is the first frame, discard anything from the previous queries
my $previous = $STACK->[-1] || {};
@@ -87,51 +82,80 @@
}
sub halo_header {
- my $self = shift;
- my $frame = shift;
- my $id = $frame->{id};
- my $perl = $frame->{perl} || '';
- my $name = $frame->{name};
-
- for ($perl, $name) {
- $_ = Jifty->web->escape($_);
+ my $self = shift;
+ my $frame = shift;
+ my $id = $frame->{id};
+ my $name = Jifty->web->escape($frame->{name});
+ my $displays = $frame->{displays};
+
+ my @buttons;
+ for my $letter (sort keys %$displays) {
+ my $d = $displays->{$letter};
+ my $name = Jifty->web->escape($d->{name});
+
+ push @buttons, join "\n", grep { $_ }
+ qq{<a id="halo-button-$name-$id"},
+ qq{ onclick="halo_render('$id', '$name')"; return false"},
+ $d->{default} && qq{ style="font-weight:bold"},
+ qq{ href="#">$letter</a>},
}
- my $perl_link = $perl ? qq{ | <a id="halo-button-perl-$id" onclick="halo_perl('$id'); return false" href="#">P</a> } : '';
- my $perl_div = $perl ? qq{<div id="halo-perl-$id" class="halo_perl"><pre>$perl</pre></div>} : '';
+ my $rendermode = '[' . join('|', @buttons) . ']';
return << " HEADER";
<div id="halo-$id" class="halo">
- <div class="halo_header">
- <span class="halo_rendermode">
- [
- <a style="font-weight: bold"
- id="halo-button-render-$id"
- onclick="halo_render('$id'); return false"
- href="#">R</a>
- |
- <a id="halo-button-source-$id"
- onclick="halo_source('$id'); return false"
- href="#">S</a>
- $perl_link
- ]
+ <div class="halo-header">
+ <span id="halo-rendermode-$id" class="halo-rendermode">
+ $rendermode
</span>
- <div class="halo_name">$name</div>
+ <div class="halo-name">$name</div>
</div>
- $perl_div
<div id="halo-inner-$id">
HEADER
}
sub halo_footer {
- my $self = shift;
- my $frame = shift;
+ my $self = shift;
+ my $frame = shift;
+ my $id = $frame->{id};
+ my $displays = $frame->{displays};
+
+ my @divs;
+ for (sort keys %$displays) {
+ my $d = $displays->{$_};
+ my $name = Jifty->web->escape($d->{name});
+
+ push @divs, join "\n", grep { $_ }
+ qq{<div id="halo-info-$name-$id" style="display: none">},
+ $d->{callback} && $d->{callback}->($d),
+ qq{</div>},
+ }
+
+ my $divs = join "\n", @divs;
return << " FOOTER";
</div>
+ <div id="halo-info-$id">
+ $divs
+ </div>
</div>
FOOTER
}
+sub new_frame {
+ my $self = shift;
+
+ return {
+ id => Jifty->web->serial,
+ start_time => time,
+ subcomponent => 0,
+ proscribed => 0,
+ displays => {
+ R => { name => "render", default => 1 },
+ S => { name => "source" },
+ },
+ @_,
+ };
+}
1;
Modified: jifty/trunk/share/web/static/css/halos.css
==============================================================================
--- jifty/trunk/share/web/static/css/halos.css (original)
+++ jifty/trunk/share/web/static/css/halos.css Fri Feb 1 12:52:43 2008
@@ -5,24 +5,20 @@
margin: 0;
}
-.halo_header {
+.halo-header {
display: none;
border-bottom: 1px dashed #ffd700;
background: #fff;
}
-.halo_rendermode {
+.halo-rendermode {
float: right;
}
-.halo_source, .halo_perl {
+.halo-source {
font-family: monospace;
}
-.halo_perl {
- display: none;
-}
-
.halo_actions {
position: fixed;
border: 1px solid black;
Modified: jifty/trunk/share/web/static/js/halo.js
==============================================================================
--- jifty/trunk/share/web/static/js/halo.js (original)
+++ jifty/trunk/share/web/static/js/halo.js Fri Feb 1 12:52:43 2008
@@ -77,7 +77,7 @@
halo_margin = '2px';
}
- YAHOO.util.Dom.getElementsByClassName("halo_header", null, null,
+ YAHOO.util.Dom.getElementsByClassName("halo-header", null, null,
function (e) {
e.style.display = halo_header_display;
}
@@ -95,42 +95,50 @@
Element.toggle("render_info_tree");
}
-function halo_render(id) {
+function halo_render(id, name) {
halo_reset(id);
- $('halo-button-render-'+id).style.fontWeight = 'bold';
+ $('halo-button-'+name+'-'+id).style.fontWeight = 'bold';
var e = $('halo-inner-'+id);
- if (e.halo_rendered) {
- e.innerHTML = e.halo_rendered;
- e.halo_rendered = null;
- }
-}
-function halo_source(id) {
- halo_reset(id);
- $('halo-button-source-'+id).style.fontWeight = 'bold';
-
- var e = $('halo-inner-'+id);
- if (!e.halo_rendered) {
+ if (name == 'source') {
e.halo_rendered = e.innerHTML;
- e.innerHTML = '<div class="halo_source">' + e.innerHTML.escapeHTML() + '</div>';
+ e.innerHTML = '<div class="halo-source">' + e.innerHTML.escapeHTML() + '</div>';
+ }
+ else if (name == 'render') {
+ /* ignore */
+ }
+ else {
+ e.style.display = 'none';
+ $('halo-info-'+name+'-'+id).style.display = 'block';
}
-}
-
-function halo_perl(id) {
- halo_reset(id);
- $('halo-button-perl-'+id).style.fontWeight = 'bold';
- $('halo-inner-'+id).style.display = 'none';
- $('halo-perl-'+id).style.display = 'block';
-
}
function halo_reset(id) {
- $('halo-button-perl-'+id).style.fontWeight = 'normal';
- $('halo-button-source-'+id).style.fontWeight = 'normal';
- $('halo-button-render-'+id).style.fontWeight = 'normal';
+ /* restore all buttons to nonbold */
+ for (var child = $('halo-rendermode-'+id).firstChild;
+ child != null;
+ child = child.nextSibling) {
+ if (child.style) {
+ child.style.fontWeight = 'normal';
+ }
+ }
+
+ /* hide all the info divs */
+ for (var child = $('halo-info-'+id).firstChild;
+ child != null;
+ child = child.nextSibling) {
+ if (child.style) {
+ child.style.display = 'none';
+ }
+ }
- $('halo-inner-'+id).style.display = 'block';
- $('halo-perl-'+id).style.display = 'none';
+ /* restore the rendered div */
+ var e = $('halo-inner-'+id);
+ e.style.display = 'block';
+ if (e.halo_rendered) {
+ e.innerHTML = e.halo_rendered;
+ e.halo_rendered = null;
+ }
}
More information about the Jifty-commit
mailing list