[Jifty-commit] r4913 - in jifty/trunk: . lib/Jifty/Mason
lib/Jifty/Plugin share/web/static/css share/web/static/js
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jan 23 18:37:23 EST 2008
Author: sartak
Date: Wed Jan 23 18:37:23 2008
New Revision: 4913
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
jifty/trunk/share/web/templates/__jifty/halo
Log:
r50696 at onn: sartak | 2008-01-23 18:37:06 -0500
Now each halo has a proper header. You can now toggle between rendered output and HTML source. It's ugly as sin, but it works.
Other misc cleanups.
Modified: jifty/trunk/lib/Jifty/Mason/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Mason/Halo.pm (original)
+++ jifty/trunk/lib/Jifty/Mason/Halo.pm Wed Jan 23 18:37:23 2008
@@ -4,6 +4,7 @@
use base qw/HTML::Mason::Plugin/;
use Time::HiRes 'time';
use Class::Trigger;
+use Jifty::Plugin::Halo;
=head1 NAME
@@ -30,10 +31,10 @@
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 $ID = Jifty->web->serial;
- my $INDEX_STACK = Jifty->handler->stash->{'_halo_index_stack'};
my $frame = {
id => $ID,
@@ -48,15 +49,13 @@
my $previous = $STACK->[-1];
push @$STACK, $frame;
-
-
push @$INDEX_STACK, $#$STACK;
return if $self->_unrendered_component($context);
$self->call_trigger('halo_pre_template', frame => $frame, previous => $previous);
- $context->request->out(qq{<div id="halo-$ID" class="halo">});
+ $context->request->out(Jifty::Plugin::Halo->halo_header($frame));
}
=head2 end_component_hook CONTEXT_OBJECT
@@ -77,7 +76,7 @@
my $FRAME_ID = pop @$INDEX_STACK;
my $frame = $STACK->[$FRAME_ID];
- $frame->{'render_time'} = int((time - $frame->{'start_time'}) * 1000)/1000;
+ $frame->{'end_time'} = time;
my $previous = $FRAME_ID ? $STACK->[$FRAME_ID - 1] : {};
@@ -91,22 +90,8 @@
# if we didn't render a beginning of the span, don't render an end
unless ( $frame->{'proscribed'} ) {
my $comp_name = $frame->{'path'};
- $context->request->out('</div>');
- $context->request->out(
- Jifty->web->link(
- label => _( 'Edit %1', $comp_name ),
- class => 'inline_edit',
- onclick => [
- { element => "#halo-" . $frame->{id},
- replace_with =>
- '/__jifty/edit_inline/mason_component/'.$comp_name
- }
- ]
- )
- )
- if 0 and ( $frame->{'path'} and $frame->{'path'} !~ /^\/?__jifty/ );
+ $context->request->out(Jifty::Plugin::Halo->halo_footer($frame));
}
-
}
=head2 _unrendered_component CONTEXT
@@ -145,7 +130,7 @@
my @stack = @{ Jifty->handler->stash->{'_halo_stack'} };
for (@stack) {
- $_->{'render_time'} = int((time - $_->{'start_time'}) * 1000)/1000
+ $_->{'render_time'} = int((($_->{'end_time'}||time) - $_->{'start_time'}) * 1000)/1000
unless defined $_->{'render_time'};
}
Modified: jifty/trunk/lib/Jifty/Plugin/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Halo.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Halo.pm Wed Jan 23 18:37:23 2008
@@ -20,6 +20,7 @@
sub init {
my $self = shift;
+ return if $self->_pre_init;
# 0.28 added around_template instrumentation
eval { Template::Declare->VERSION('0.28'); 1 }
@@ -40,9 +41,9 @@
sub around_template {
my ($self, $orig, $path, $args) = @_;
+ my $ID = Jifty->web->serial;
my $STACK = Jifty->handler->stash->{'_halo_stack'} ||= [];
my $DEPTH = ++Jifty->handler->stash->{'_halo_depth'};
- my $ID = Jifty->web->serial;
# for now, call the last piece of the template's path the name
$path =~ m{.*/(.+)};
@@ -67,16 +68,54 @@
$self->call_trigger('halo_pre_template', frame => $frame, previous => $previous);
- Jifty->web->out(qq{<div id="halo-$ID" class="halo">});
+ Template::Declare->buffer->append($self->halo_header($frame));
$orig->();
- Jifty->web->out(qq{</div>});
+ Template::Declare->buffer->append($self->halo_footer($frame));
- $frame->{'render_time'} = int((time - $frame->{'start_time'}) * 1000)/1000
- unless defined $frame->{'render_time'};
+ $frame->{'end_time'} = time;
$self->call_trigger('halo_post_template', frame => $frame, previous => $previous);
--Jifty->handler->stash->{'_halo_depth'};
}
+sub halo_header {
+ my $self = shift;
+ my $frame = shift;
+ my $id = $frame->{id};
+
+ return << " HEADER";
+ <div id="halo-$id" class="halo">
+ <div class="halo_header">
+ <span class="halo_name">
+ $frame->{name}
+ </span>
+ <span class="halo_rendermode">
+ [
+ <a style="font-weight: bold"
+ id="halo-render-$id"
+ onclick="halo_render('$id'); return false"
+ href="#">R</a>
+ |
+ <a id="halo-source-$id"
+ onclick="halo_source('$id'); return false"
+ href="#">S</a>
+ ]
+ </span>
+ </div>
+ <div id="halo-inner-$id">
+ HEADER
+}
+
+sub halo_footer {
+ my $self = shift;
+ my $frame = shift;
+
+ return << " FOOTER";
+ </div>
+ </div>
+ FOOTER
+}
+
+
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 Wed Jan 23 18:37:23 2008
@@ -1,3 +1,15 @@
+.halo {
+}
+
+.halo_header {
+ display: none;
+ border-bottom: 1px dotted #666666;
+}
+
+.halo_source {
+ font-family: monospace;
+}
+
.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 Wed Jan 23 18:37:23 2008
@@ -62,3 +62,52 @@
window.style.width = newWidth;
grip.xFrom = x;
}
+
+function render_info_tree() {
+ var halo_header_display = 'none';
+ var halo_border = '0';
+
+ var info_tree = $("render_info_tree");
+ Element.toggle(info_tree);
+
+ if (Element.visible(info_tree)) {
+ halo_header_display = 'block';
+ halo_border = '2px solid #666666';
+ }
+
+ YAHOO.util.Dom.getElementsByClassName("halo_header", null, null,
+ function (e) {
+ e.style.display = halo_header_display;
+ }
+ );
+
+ YAHOO.util.Dom.getElementsByClassName("halo", null, null,
+ function (e) {
+ e.style.border = halo_border;
+ }
+ );
+
+}
+
+function halo_render(id) {
+ $('halo-render-'+id).style.fontWeight = 'bold';
+ $('halo-source-'+id).style.fontWeight = 'normal';
+
+ var e = $('halo-inner-'+id);
+ if (e.halo_rendered) {
+ e.innerHTML = e.halo_rendered;
+ e.halo_rendered = null;
+ }
+}
+
+function halo_source(id) {
+ $('halo-source-'+id).style.fontWeight = 'bold';
+ $('halo-render-'+id).style.fontWeight = 'normal';
+
+ var e = $('halo-inner-'+id);
+ if (!e.halo_rendered) {
+ e.halo_rendered = e.innerHTML;
+ e.innerHTML = '<div class="halo_source">' + e.innerHTML.escapeHTML() + '</div>';
+ }
+}
+
Modified: jifty/trunk/share/web/templates/__jifty/halo
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/halo (original)
+++ jifty/trunk/share/web/templates/__jifty/halo Wed Jan 23 18:37:23 2008
@@ -1,4 +1,4 @@
-<div><a href="#" id="render_info" onclick="Element.toggle('render_info_tree'); return false"><%_('Page info')%></a></div>
+<div><a href="#" id="render_info" onclick="render_info_tree(); return false"><%_('Page info')%></a></div>
<div style="display: none" id="render_info_tree">
% foreach my $item (@stack) {
% if ( $item->{depth} > $depth ) {
More information about the Jifty-commit
mailing list