Procházet zdrojové kódy

Work on #130: allow (rudimentary) posts within posts

Still need 100% raw posts so we can build the page structure as posts.
George S. Baugh před 4 roky
rodič
revize
2110a4d6ee
3 změnil soubory, kde provedl 53 přidání a 13 odebrání
  1. 28 1
      lib/Trog/Routes/HTML.pm
  2. 7 0
      www/styles/screen.css
  3. 18 12
      www/templates/posts.tx

+ 28 - 1
lib/Trog/Routes/HTML.pm

@@ -782,7 +782,7 @@ Display multi or single posts, supports RSS and pagination.
 
 =cut
 
-sub posts ($query, $render_cb) {
+sub posts ($query, $render_cb, $direct=0) {
     #Process the input URI to capture tag/id
     my (undef, $tag, $id) = split(/\//, $query->{route});
 
@@ -822,6 +822,25 @@ sub posts ($query, $render_cb) {
 
     my $processor = Text::Xslate->new(
         path   => $template_dir,
+        function => {
+            render_it => sub {
+                my ($template_string, $options) = @_;
+                return Text::Xslate->new(
+                    # Prevent a recursive descent.  If the renderer is hit again, just do nothing
+                    # XXX unfortunately if the post tries to include itself, it will die.
+                    function => {
+                        embed => sub {
+                            my ($this_id, $style) = @_;
+                            $style //= 'embed';
+                            return Text::Xslate::mark_raw(Trog::Routes::HTML::posts(
+                                { route => "/post/$this_id", style => $style },
+                                sub {},
+                            1));
+                        },
+                    },
+                )->render_string($template_string,$options);
+            },
+        },
     );
 
     # Themed header/footer for about page -- TODO maybe make this generic so we can have MESSAGE FROM JIMBO WALES everywhere
@@ -859,8 +878,15 @@ sub posts ($query, $render_cb) {
     my $now_year = (localtime(time))[5] + 1900;
     my $oldest_year = $now_year - 20; #XXX actually find oldest post year
 
+    # Handle post style.
+    if ($query->{style}) {
+        undef $header;
+        undef $footer;
+    }
+
     my $content = $processor->render('posts.tx', {
         title     => $query->{title},
+        style     => $query->{style},
         posts     => \@posts,
         like      => $query->{like},
         in_series => exists $query->{in_series} || !!($query->{route} =~ m/\/series\/\d*$/),
@@ -878,6 +904,7 @@ sub posts ($query, $render_cb) {
         years     => [reverse($oldest_year..$now_year)],
         months    => [0..11],
     });
+    return $content if $direct;
     return Trog::Routes::HTML::index($query, $render_cb, $content, $styles);
 }
 

+ 7 - 0
www/styles/screen.css

@@ -405,3 +405,10 @@ p.posteditortitle {
     z-index: 100;
     text-decoration: none;
 }
+
+/* embed style for posts */
+.embed {
+    border: inset;
+    margin: 2rem;
+    padding: 1rem;
+}

+ 18 - 12
www/templates/posts.tx

@@ -13,7 +13,9 @@
 : if ( $header ) {
     <: $header | mark_raw :>
 : }
+: if (!$style) {
 <hr class="divider" />
+: }
 : for $posts -> $post {
     : if ( $post.aclname && $in_series ) {
     :     next;
@@ -42,22 +44,24 @@
             <p class="midtitle"><: $post.title :></p>
         </a>
     : } else {
-        <div class="post">
+        <div class="post <: $style :>">
             : if (!$post.is_profile) {
             <h3 class='blogtitles'>
                 <a ><a href='<: $post.href :>' ><: $post.title :></a>
                 <a class="undecorated" href='/posts/<: $post.id :>'>🔗</a>
-                : if ( $post.version_max && !$rss ) {
-                <form method="GET" action="/posts/<: $post.id :>" style="float:right;">
-                    <select id="<: $post.id :>-<: $post.version :>-version" name="version" class="coolbutton">
-                        : for [0..$post.version_max] -> $version {
-                            <option value="<: $version :>" <: if ($post.version == $version ) { :>selected<: } :> >v<: $version :></option>
-                        : }
-                    </select>
-                </form>
+                : if (!$style) {
+                    : if ( $post.version_max && !$rss ) {
+                    <form method="GET" action="/posts/<: $post.id :>" style="float:right;">
+                        <select id="<: $post.id :>-<: $post.version :>-version" name="version" class="coolbutton">
+                            : for [0..$post.version_max] -> $version {
+                                <option value="<: $version :>" <: if ($post.version == $version ) { :>selected<: } :> >v<: $version :></option>
+                            : }
+                        </select>
+                    </form>
+                    : }
+                    <span id="<: $post.id :>-<: $post.version :>-time" class="responsive-hide" style="float:right;"><: $post.created :></span>
+                    <a class='postericon <: $post.user :>' title='Posted by <: $post.user :>'>&nbsp;</a>
                 : }
-                <span id="<: $post.id :>-<: $post.version :>-time" class="responsive-hide" style="float:right;"><: $post.created :></span>
-                <a class='postericon <: $post.user :>' title='Posted by <: $post.user :>'>&nbsp;</a>
             </h3>
             : }
             : if ( !$post.video_href && !$post.is_image && !$post.is_video && !$post.is_profile && $post.preview ) {
@@ -103,7 +107,7 @@
                     : if ( $post.is_profile ) {
                     <h3><: $post.title :></h3>
                     : }
-                    <: $post.data | mark_raw :>
+                    <: render_it($post.data) | mark_raw  :>
                 </div>
             : }
             : if( $post.is_profile ) {
@@ -142,7 +146,9 @@
             </script>
             : }
         </div>
+        : if ($posts.size() > 1) {
         <hr class="divider" />
+        : }
     : }
 : }
 : if ( $rss || $older ) {