[Bps-public-commit] rt-extension-announce branch, support-html-content-as-banner, updated. 1.00-4-ge45b416

Craig Kaiser craig at bestpractical.com
Wed Aug 28 13:10:24 EDT 2019


The branch, support-html-content-as-banner has been updated
       via  e45b416a3a6a0fe27bbe1d66370ad43921b24cd8 (commit)
      from  ee93d117f97c0f8d001469acfc991b900dc2b297 (commit)

Summary of changes:
 META.yml                                           |  1 +
 Makefile.PL                                        |  2 +
 README                                             |  5 +++
 .../Elements/PageLayout/BeforeBody                 | 50 ++++++++++++++++++++++
 lib/RT/Extension/Announce.pm                       |  5 +++
 static/css/announce.css                            |  9 ++++
 6 files changed, 72 insertions(+)

- Log -----------------------------------------------------------------
commit e45b416a3a6a0fe27bbe1d66370ad43921b24cd8
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Wed Aug 28 09:56:03 2019 -0400

    Allow the number of lines displayed in the RT announce banner to be configured

diff --git a/META.yml b/META.yml
index 83d7405..0b65c8a 100644
--- a/META.yml
+++ b/META.yml
@@ -22,6 +22,7 @@ no_index:
     - static
     - xt
 requires:
+  Mojo::Dom: 0
   perl: 5.8.3
 resources:
   license: http://opensource.org/licenses/gpl-license.php
diff --git a/Makefile.PL b/Makefile.PL
index 52c7822..c4a6850 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -2,6 +2,8 @@ use inc::Module::Install;
 
 RTx 'RT-Extension-Announce';
 
+requires 'Mojo::Dom';
+
 repository('https://github.com/bestpractical/rt-extension-announce');
 
 my ($lp) = ($INC{'RT.pm'} =~ /^(.*)[\\\/]/);
diff --git a/README b/README
index e7a409e..7eab172 100644
--- a/README
+++ b/README
@@ -117,6 +117,11 @@ CONFIGURATION
     If set to true, the banner content will be set to 'text/html' and allow
     HTML rendering.
 
+  $RTAnnounceLineCountLimit
+    Set the number of lines that should be displayed in the RT announce
+    banner, if the displayed lines exceed the line limit a scroll box
+    feature will be available.
+
 AUTHOR
     Best Practical Solutions, LLC <modules at bestpractical.com>
 
diff --git a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
index cfd3fee..571e320 100644
--- a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
+++ b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
@@ -78,12 +78,62 @@
     $content =~ s/\s+$//g; # Remove trailing space
     $content .= chr(8230); # Ellipsis character
   }
+
+  use Mojo::Dom;
+  my $dom = Mojo::DOM->new( $content );
+
+  my @lines;
+  if ( $show_html ) {
+    for my $line ( split("\n", $dom->all_text ) ) {
+      # We do not care about strings with only white space
+      next unless $line =~ /\S/;
+
+      # Find the HTML element matching our text, not just the text component
+      my $match = $dom->find('*')->grep(sub { $_->all_text =~ /$line/ })->first;
+      next unless $match;
+
+      # We want the HTML string from the component not just the parsed text content
+      push @lines, $match->to_string;
+
+      # Remove this content from our DOM object
+      $dom = $match->strip;
+    }
+  } else {
+    # Split just on line breaks
+    @lines = split ( "\n", $content );
+  }
+  my $line_count_limit = RT::Config->Get('RTAnnounceLineCountLimit');
+
+  if ( $line_count_limit && scalar @lines > $line_count_limit && $show_html ) {
+    my $dom_ellipsis = Mojo::DOM->new();
+
+    my $count = 0;
+    for my $line ( @lines ) {
+      if ( $count eq $line_count_limit ) {
+        # Placeholder element to be replaced with overflow CSS div
+        $dom_ellipsis = $dom_ellipsis->append_content( '<p id="RTAnnounceOverflowStart">' );
+      }
+      $dom_ellipsis = $dom_ellipsis->append_content( $line );
+      $count = $count + 1;
+    }
+    # Wrap our content in a scrollable div since we have more lines than we want to display
+    $content = $dom_ellipsis->content;
+
+    # Replace our placeholder element with the overflow div
+    $content =~ s/\<p id="RTAnnounceOverflowStart"\>\<\/p\>/\<div class="RTAnnounceBannerOverflow overflow-ellipsis"\>/;
+
+    # Close the overflow div at the end of the content
+    $content .= '</div>';
+  }
+
 </%perl>
+<div class="RTAnnounceScrollable">
 % if ( $show_html ) {
   <% $content |n %>
 % } else {
   <% $content %>
 % }
+</div>
 %if( $show_ticket_links{$ticket->Id} ){
  (<a class="announcements_detail" href="<% RT->Config->Get('WebPath') %>/Ticket/Display.html?id=<% $ticket->Id %>">more</a>)
 %}
diff --git a/lib/RT/Extension/Announce.pm b/lib/RT/Extension/Announce.pm
index 44bc8c3..afdb509 100644
--- a/lib/RT/Extension/Announce.pm
+++ b/lib/RT/Extension/Announce.pm
@@ -224,6 +224,11 @@ the regular privileged RT page.
 
 If set to true, the banner content will be set to 'text/html' and allow HTML rendering.
 
+=head2 C<$RTAnnounceLineCountLimit>
+
+Set the number of lines that should be displayed in the RT announce banner, if the displayed lines exceed
+the line limit a scroll box feature will be available.
+
 =head1 AUTHOR
 
 Best Practical Solutions, LLC E<lt>modules at bestpractical.comE<gt>
diff --git a/static/css/announce.css b/static/css/announce.css
index 022eac9..1052ec5 100644
--- a/static/css/announce.css
+++ b/static/css/announce.css
@@ -82,3 +82,12 @@ table.announce td.date {
   font-size: smaller;
   color: #777;
 }
+
+.RTAnnounceBannerOverflow {
+  height: 0px;
+  white-space: nowrap;
+}
+
+.RTAnnounceScrollable {
+  overflow: auto;
+}

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list