Move siteviews to use the DW::Routing/Template interface.

        Patch by exor674. 

diffs (198 lines):

diff -r ac1192735bd3 -r 00e6eaf8e071 bin/upgrading/s2layers/siteviews/layout.s2
--- a/bin/upgrading/s2layers/siteviews/layout.s2        Wed Jan 06 01:46:12 
2010 +0000
+++ b/bin/upgrading/s2layers/siteviews/layout.s2        Wed Jan 06 02:08:20 
2010 +0000
@@ -3,27 +3,34 @@ layerinfo redist_uniq = "siteviews/layou
 layerinfo redist_uniq = "siteviews/layout";
 layerinfo is_internal = "1";
 
-property builtin bool SITEVIEWS_RENDERED {
+class Siteviews {
+    function builtin need_res(string res);
+    function builtin start_capture();
+    function builtin end_capture() : string;
+
+    function builtin set_content(string area, string text);
+}
+
+property builtin Siteviews SITEVIEWS {
     noui = 1;
     doc_flags = "[sys]";
-    des = "Will be 1 if this layout is going to be parsed for BML once it's 
done";
+    des = "Instance of the Siteviews class";
 }
 
 function Page::print() {
-    if ($*SITEVIEWS_RENDERED) {
-        """<?page
-body<=\n""";
-$this->print_body();
-"""\n<=body\n""";
-$this->print_head_title();
-"""page?>""";
+    if ( $*SITEVIEWS ) {
+        $*SITEVIEWS->start_capture();
+        $this->print_head();
+        $this->print_stylesheets();
+        $*SITEVIEWS->set_content("head",$*SITEVIEWS->end_capture());
+        $*SITEVIEWS->set_content("windowtitle",$this->view_title());
+
+        $this->print_body();
     } else {
        print safe "<b>This style is not intended for direct use.</b>";
     }
 }
 
-function Page::print_head_title() {
-    print "title=>";
-    print safe $this->view_title();
-    print "\n";
+function Page::print_stylesheets() {
+    # Do not actually *print* any stylesheets here, but you can 
$*SITEVIEWS->need_res(...); here to pull in anything.
 }
diff -r ac1192735bd3 -r 00e6eaf8e071 cgi-bin/Apache/LiveJournal.pm
--- a/cgi-bin/Apache/LiveJournal.pm     Wed Jan 06 01:46:12 2010 +0000
+++ b/cgi-bin/Apache/LiveJournal.pm     Wed Jan 06 02:08:20 2010 +0000
@@ -40,6 +40,7 @@ use XMLRPC::Transport::HTTP;
 use XMLRPC::Transport::HTTP;
 use LJ::URI;
 use DW::Routing::Apache2;
+use DW::Template::Apache2;
 
 BEGIN {
     $LJ::OPTMOD_ZLIB = eval "use Compress::Zlib (); 1;";
@@ -1358,6 +1359,7 @@ sub journal_content
         },
         'handle_with_bml_ref' => \$handle_with_bml,
         'handle_with_siteviews_ref' => \$handle_with_siteviews,
+        'siteviews_extra_content' => {},
         'ljentry' => $RQ{'ljentry'},
     };
 
@@ -1376,10 +1378,8 @@ sub journal_content
     # only if HTML is set, otherwise leave it alone so the user
     # gets "messed up template definition", cause something went wrong.
     if ( $handle_with_siteviews && $html ) {
-        $r->pnotes->{siteview_code} = $html;
-        $r->notes->{bml_filename} = "$LJ::HOME/htdocs/misc/siteviews.bml";
-        return Apache::BML::handler($r);
-    } elsif ($handle_with_bml) {
+        return DW::Template::Apache2->render_string( $html, 
$opts->{siteviews_extra_content} );
+    } elsif ( $handle_with_bml ) {
         my $args = $r->args;
         my $args_wq = $args ? "?$args" : "";
 
diff -r ac1192735bd3 -r 00e6eaf8e071 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm  Wed Jan 06 01:46:12 2010 +0000
+++ b/cgi-bin/LJ/S2.pm  Wed Jan 06 02:08:20 2010 +0000
@@ -91,8 +91,16 @@ sub make_journal
         # kill the flag
         ${$opts->{'handle_with_bml_ref'}} = 0;
         ${$opts->{'handle_with_siteviews_ref'}} = 1;
-
-        $ctx->[S2::PROPS]->{'SITEVIEWS_RENDERED'} = 1;
+        $opts->{siteviews_extra_content} ||= {};
+
+        my $siteviews_class = {
+            '_type' => "Siteviews",
+            '_input_captures' => [],
+            '_content' => $opts->{siteviews_extra_content},
+        };
+        
+        $ctx->[S2::SCRATCH]->{siteviews_enabled} = 1;
+        $ctx->[S2::PROPS]->{SITEVIEWS} = $siteviews_class;
     } else {
         if ( ! $ctx->[S2::PROPS]->{use_journalstyle_entry_page} && ( $view eq 
"entry" || $view eq "reply" ) ) {
             ${$opts->{'handle_with_bml_ref'}} = 1;
@@ -1177,8 +1185,6 @@ sub populate_system_props
     $ctx->[S2::PROPS]->{'SITENAMEABBREV'} = $LJ::SITENAMEABBREV;
     $ctx->[S2::PROPS]->{'IMGDIR'} = $LJ::IMGPREFIX;
     $ctx->[S2::PROPS]->{'STATDIR'} = $LJ::STATPREFIX;
-
-    $ctx->[S2::PROPS]->{'SITEVIEWS_RENDERED'} = 0;
 }
 
 # renamed some props from core1 => core2. Make sure that S2 still handles 
these variables correctly when working with a core1 layer
@@ -4190,5 +4196,43 @@ sub string__css_keyword_list
     return join(' ', @out);
 }
 
+sub Siteviews__need_res
+{
+    my ($ctx, $this, $res) = @_;
+    die "Siteviews doesn't work standalone" unless 
$ctx->[S2::SCRATCH]->{siteviews_enabled};
+    LJ::need_res($res);
+}
+
+sub Siteviews__start_capture {
+    my ($ctx, $this) = @_;
+    die "Siteviews doesn't work standalone" unless 
$ctx->[S2::SCRATCH]->{siteviews_enabled};
+
+    # force flush
+    S2::get_output()->("");
+
+    push @{$this->{_input_captures}}, $LJ::S2::ret_ref;
+    my $text = "";
+    $LJ::S2::ret_ref = \$text;
+}
+
+sub Siteviews__end_capture {
+    my ($ctx, $this) = @_;
+    die "Siteviews doesn't work standalone" unless 
$ctx->[S2::SCRATCH]->{siteviews_enabled};
+
+    return "" unless scalar( @{$this->{_input_captures}} );
+
+    # force flush
+    S2::get_output()->("");
+    my $text_ref = $LJ::S2::ret_ref;
+    $LJ::S2::ret_ref = pop @{$this->{_input_captures}};
+    return $$text_ref;
+}
+
+sub Siteviews__set_content {
+    my ($ctx, $this, $content, $text) = @_;
+    die "Siteviews doesn't work standalone" unless 
$ctx->[S2::SCRATCH]->{siteviews_enabled};
+    
+    $this->{_content}->{$content} = $text;
+}
 
 1;
diff -r ac1192735bd3 -r 00e6eaf8e071 cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm        Wed Jan 06 01:46:12 2010 +0000
+++ b/cgi-bin/LJ/User.pm        Wed Jan 06 02:08:20 2010 +0000
@@ -8378,8 +8378,7 @@ sub make_journal
     # signal to LiveJournal.pm that we can't handle this
     # FIXME: Make this properly invoke siteviews all the time -- once all the 
views are ready.
     # Most of this if and tons of messy conditionals can go away once all 
views are done.
-    if ( ( ($stylesys == 1 || $geta->{'style'} eq 'site' || $geta->{'style'} 
eq 'default' ) &&
-            ( { entry=>1, reply=>1, month=>1, tag=>1 }->{$view} || ($view eq 
'lastn' && ($geta->{tag} || $geta->{security})))) || ( $geta->{'format'} eq 
'light' || $geta->{'style'} eq 'light' ) )  {
+    if ( $stylesys == 1 || $geta->{'style'} eq 'site' || $geta->{'format'} eq 
'light' || $geta->{'style'} eq 'light' )  {
         my $fallback = "bml"; # FIXME: Should be S2 once everything's done
 
         # if we are in this path, and they have style=mine set, it means
diff -r ac1192735bd3 -r 00e6eaf8e071 htdocs/misc/siteviews.bml
--- a/htdocs/misc/siteviews.bml Wed Jan 06 01:46:12 2010 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-<?_code
-#
-# misc/siteviews.bml
-#
-# Internal page to run bml code from a pnote through the BML parser
-# without having to duplicate a fair bit of code.
-#
-# Authors:
-#      Andrea Nall <[email protected]>
-#
-# Copyright (c) 2009 by Dreamwidth Studios, LLC.
-#
-# This program is free software; you may redistribute it and/or modify it under
-# the same terms as Perl itself. For a copy of the license, please reference
-# 'perldoc perlartistic' or 'perldoc perlgpl'.
-#
-{
-    my $r = DW::Request->get;
-    my $code = $r->pnote( 'siteview_code' );
-    return BML::redirect($LJ::SITEROOT) unless $code;
-    return $code;
-}
-_code?>
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to