Commits

Shlomi Fish  committed 270b32e

Get rid of trailing space in the output.

  • Participants
  • Parent commits 52d6afd

Comments (0)

Files changed (22)

File XML-Grammar-Fortune/module/Changes

+0.0509      Wed  1 May 18:57:14 IDT 2013
+        - Got rid of trailing space in the output.
+
 0.0508      Tue 23 Apr 14:52:43 IDT 2013
         - Change the repository URL to the new bitbucket one.
 

File XML-Grammar-Fortune/module/contrib/convert-irc-log-to-fortune-xml.pl

 
 =head1 DESCRIPTION
 
-This is a script to convert an XChat conversation to part of the 
+This is a script to convert an XChat conversation to part of the
 Fortune-XML (see L<XML::Grammar::Fortune> ). It reads stuff on ARGV.
 
 =cut
         else
         {
             my ($real_nick) = ($nick =~ m{<([^>]+)>});
-            push @messages, 
+            push @messages,
                 {'type' => "say", 'nick' => $real_nick, 'msg' => $msg};
         }
     }
     elsif (m{^[^\-]* ---\t(\S+) is now known as (\S+)})
     {
         my ($old_nick, $new_nick) = ($1, $2);
-        push @messages, 
+        push @messages,
             {'type' => "change_nick", 'old' => $old_nick, 'new' => $new_nick};
     }
     else
 {
     if ($m->{'type'} eq "say")
     {
-        print qq{<saying who="} . $m->{nick} . qq{">} . 
+        print qq{<saying who="} . $m->{nick} . qq{">} .
             esc($m->{msg}) . qq{</saying>\n};
     }
     elsif ($m->{'type'} eq "raw")

File XML-Grammar-Fortune/module/extradata/fortune-xml-to-html.xslt

             <xsl:when test="screenplay">
                 <xsl:apply-templates select="screenplay" mode="screenplay_wrapper"/>
             </xsl:when>
-            
-        </xsl:choose> 
+
+        </xsl:choose>
     </div>
 </xsl:template>
 
                 <xsl:when test="name(.) = 'leaves'">
                     <xsl:text>←</xsl:text>
                 </xsl:when>
-            </xsl:choose> 
+            </xsl:choose>
             <xsl:value-of select="@who" />
-        </td>        
+        </td>
         <td class="text">
             <xsl:value-of select="." />
         </td>
                     <xsl:otherwise>
                         <xsl:value-of select="name(.)" />
                     </xsl:otherwise>
-                </xsl:choose> 
+                </xsl:choose>
             </b>
         </td>
         <td class="value">
 <xsl:template match="para" mode="screenplay">
     <p>
         <xsl:if test="local-name(..) = 'saying'">
-            <strong class="sayer"><xsl:value-of select="../@character" />:</strong> 
-            <xsl:text> </xsl:text>
+            <strong class="sayer">
+                <xsl:value-of select="../@character" />
+                <xsl:text>: </xsl:text>
+            </strong>
         </xsl:if>
         <xsl:if test="local-name(..) = 'description' and ../child::para[position()=1] = .">
             <xsl:text>[</xsl:text>

File XML-Grammar-Fortune/module/inc/Test/Run/Builder.pm

         Test::Run::CmdLine::Iface->new(
             {
                 'test_files' => [glob("t/*.t")],
-            }   
+            }
             # 'backend_params' => $self->_get_backend_params(),
         );
 
 
 sub ACTION_tags
 {
-    return 
+    return
         system(qw(
             ctags -f tags --recurse --totals
     		--exclude=blib/ --exclude=t/lib

File XML-Grammar-Fortune/module/inc/XML/Grammar/Builder.pm

     my $package = shift;
     my %args = @_;
     my @extradata_files;
-    
+
     my $builder = $package->SUPER::new(
         share_dir => 'extradata',
         auto_configure_requires => 1,

File XML-Grammar-Fortune/module/lib/XML/Grammar/Fortune/ToText.pm

 has '_input' => (is => 'rw', init_arg => 'input', required => 1,);
 has '_output' => (is => 'rw', init_arg => 'output', required => 1,);
 has '_this_line' => (isa => 'Str', is => 'rw', default => '', );
+has '_buf' => (isa => 'ScalarRef[Str]', is => 'rw',
+    default => sub { my $s = ''; return \$s; });
 
 =head1 NAME
 
 {
     my $self = shift;
 
-    print {$self->_output()} @_;
+    ${$self->_buf()} .= join('', @_);
 
     return;
 }
         }
     );
 
+    my $buf = ${$self->_buf()};
+
+    $buf =~ s/[ \t]+$//gms;
+
+    print { $self->_output() } $buf;
+
     return;
 }
 
 
     # Intent: format the text.
     # Trim leading and trailing nelines.
-    $text =~ s{\A\n+}{}ms;
-    $text =~ s{\n+\z}{}ms;
+    # $text =~ s{\A\n+}{}ms;
+    # $text =~ s{\n+\z}{}ms;
 
     # Convert a sequence of spaces to a single space.
     $text =~ s{\s+}{ }gms;
 {
     my ($self, $para) = @_;
 
+    my $first_text = 1;
+
     foreach my $node ($para->childNodes())
     {
         if ($node->nodeType() == XML_ELEMENT_NODE())
         }
         elsif ($node->nodeType() == XML_TEXT_NODE())
         {
-            $self->_append_to_this_line(
-                $self->_get_formatted_node_text($node)
-            );
+            my $text = $self->_get_formatted_node_text($node);
+
+            if ($first_text)
+            {
+                $text =~ s/\A\s+//;
+            }
+
+            $self->_append_to_this_line( $text );
         }
     }
+    continue
+    {
+        $first_text = 0;
+    }
 }
 
 sub _render_quote_list

File XML-Grammar-Fortune/module/t/data/text-results/raw-fort-empty-info-1.txt

-The American Lottery - all you need is a dollar and a dream. We will 
-take the dollar, but you can keep the dream. 
+The American Lottery - all you need is a dollar and a dream. We will
+take the dollar, but you can keep the dream.
 
     Shlomi Fish

File XML-Grammar-Fortune/module/t/data/xhtml-results/irc-convos-and-raw-fortunes-1.xhtml

 <div class="fortune">
 <h3 id="the-american-lottery">The American Lottery</h3>
 <pre class="raw">
-The American Lottery - all you need is a dollar and a dream. We will 
-take the dollar, but you can keep the dream. 
+The American Lottery - all you need is a dollar and a dream. We will
+take the dollar, but you can keep the dream.
 
 Shlomi Fish
 </pre>

File XML-Grammar-Fortune/module/t/data/xhtml-results/raw-fort-empty-info-1.xhtml

 <body>
 <div class="fortune">
 <h3 id="the-american-lottery">The American Lottery</h3>
-<pre class="raw">The American Lottery - all you need is a dollar and a dream. We will 
-take the dollar, but you can keep the dream. 
+<pre class="raw">The American Lottery - all you need is a dollar and a dream. We will
+take the dollar, but you can keep the dream.
 
 Shlomi Fish
 </pre>

File XML-Grammar-Fortune/module/t/data/xhtml-results/screenplay-fort-sample-1.xhtml

 <div class="screenplay">
 <div class="description">
 <p>[
-David and 
-<a href="http://en.wikipedia.org/wiki/Goliath">Goliath</a> 
+David and
+<a href="http://en.wikipedia.org/wiki/Goliath">Goliath</a>
 are standing by each other.
 ]</p>
 </div>
 <div class="saying">
-<p><strong class="sayer">David:</strong> 
+<p><strong class="sayer">David: </strong>
 I will kill you.<br/>
 I will kill you.<br/>
 You will not survive.<br/>
 </p>
 </div>
 <div class="saying">
-<p><strong class="sayer">Goliath:</strong> 
+<p><strong class="sayer">Goliath: </strong>
 no way, you little idiot!
 </p>
 </div>
 <div class="saying">
-<p><strong class="sayer">David:</strong> 
+<p><strong class="sayer">David: </strong>
 yes way!
 </p>
 </div>

File XML-Grammar-Fortune/module/t/data/xhtml-results/screenplay-fort-sample-2-with-italics.xhtml

 <div class="screenplay">
 <div class="description">
 <p>[
-David and 
-<a href="http://en.wikipedia.org/wiki/Goliath">Goliath</a> 
+David and
+<a href="http://en.wikipedia.org/wiki/Goliath">Goliath</a>
 are standing by each other.
 ]</p>
 </div>
 <div class="saying">
-<p><strong class="sayer">David:</strong> 
+<p><strong class="sayer">David: </strong>
 I will kill you, as written in <em class="italics">Treasure Island</em>.<br/>
 I will kill you.<br/>
 You will not <strong class="bold">survive</strong>.<br/>
 </p>
 </div>
 <div class="saying">
-<p><strong class="sayer">Goliath:</strong> 
+<p><strong class="sayer">Goliath: </strong>
 no way, you little idiot!
 </p>
 </div>
 <div class="saying">
-<p><strong class="sayer">David:</strong> 
+<p><strong class="sayer">David: </strong>
 yes way!
 </p>
 </div>

File XML-Grammar-Fortune/module/t/data/xml/irc-conversation-2-with-slash-me.xml

             </meta>
             <irc>
                 <body>
-                    <saying who="rindolf">sussman: for the record, I think the 
-                        build system is the ultimate proof that python code 
+                    <saying who="rindolf">sussman: for the record, I think the
+                        build system is the ultimate proof that python code
                         can be as bad as Perl one.</saying>
                     <me_is who="clkao">giggles</me_is>
                     <saying who="jackr">hehe</saying>
                     <saying who="rindolf">hopes he's not starting a flamewar</saying>
-                    <saying who="clkao">btw, freebsd svn port maintainer was 
-                        complaining about unable to do --with-swig specifying 
+                    <saying who="clkao">btw, freebsd svn port maintainer was
+                        complaining about unable to do --with-swig specifying
                         only perl or pythong bindings to build..</saying>
 
-                    <me_is who="cmpilato">notes that the topic of this channel 
+                    <me_is who="cmpilato">notes that the topic of this channel
                         is Subversion.</me_is>
-                    <saying who="clkao">(so he refused to include the option 
+                    <saying who="clkao">(so he refused to include the option
                         for building either bindings in the port!)</saying>
-                    <saying who="rindolf">I once saw a perl5 code written in 
+                    <saying who="rindolf">I once saw a perl5 code written in
                         perl4 style. Now that was hideous.</saying>
                     <saying who="fitz">complicated != bad</saying>
-                    <saying who="fitz">"Building is complicated--that's why 
+                    <saying who="fitz">"Building is complicated--that's why
                         build systems are complicated." --kfogel</saying>
                 </body>
                 <info>

File XML-Grammar-Fortune/module/t/data/xml/irc-conversation-3-with-join-unjoin.xml

             </meta>
             <irc>
                 <body>
-                    <saying who="rindolf">sussman: for the record, I think the 
-                        build system is the ultimate proof that python code 
+                    <saying who="rindolf">sussman: for the record, I think the
+                        build system is the ultimate proof that python code
                         can be as bad as Perl one.</saying>
                     <me_is who="clkao">giggles</me_is>
                     <saying who="jackr">hehe</saying>

File XML-Grammar-Fortune/module/t/data/xml/irc-convos-and-raw-fortunes-1.xml

             </meta>
             <raw>
                 <body><text><![CDATA[
-The American Lottery - all you need is a dollar and a dream. We will 
-take the dollar, but you can keep the dream. 
+The American Lottery - all you need is a dollar and a dream. We will
+take the dollar, but you can keep the dream.
 
     Shlomi Fish
 ]]></text>

File XML-Grammar-Fortune/module/t/data/xml/raw-fort-empty-info-1.xml

                 <title>The American Lottery</title>
             </meta>
             <raw>
-                <body><text><![CDATA[The American Lottery - all you need is a dollar and a dream. We will 
-take the dollar, but you can keep the dream. 
+                <body><text><![CDATA[The American Lottery - all you need is a dollar and a dream. We will
+take the dollar, but you can keep the dream.
 
     Shlomi Fish
 ]]></text>

File XML-Grammar-Fortune/module/t/data/xml/screenplay-fort-sample-1.xml

 <body>
 <description>
 <para>
-David and 
-<ulink url="http://en.wikipedia.org/wiki/Goliath">Goliath</ulink> 
+David and
+<ulink url="http://en.wikipedia.org/wiki/Goliath">Goliath</ulink>
 are standing by each other.
 </para>
 </description>

File XML-Grammar-Fortune/module/t/data/xml/screenplay-fort-sample-2-long-line.xml

 <body>
 <description>
 <para>
-David and 
-<ulink url="http://en.wikipedia.org/wiki/Goliath">Goliath</ulink> 
+David and
+<ulink url="http://en.wikipedia.org/wiki/Goliath">Goliath</ulink>
 are standing by each other.
 </para>
 </description>

File XML-Grammar-Fortune/module/t/data/xml/screenplay-fort-sample-2-with-italics.xml

 <body>
 <description>
 <para>
-David and 
-<ulink url="http://en.wikipedia.org/wiki/Goliath">Goliath</ulink> 
+David and
+<ulink url="http://en.wikipedia.org/wiki/Goliath">Goliath</ulink>
 are standing by each other.
 </para>
 </description>

File XML-Grammar-Fortune/module/t/data/xml/screenplay-fort-sample-3-with-inlinedesc.xml

 <body>
 <description>
 <para>
-David and 
-<ulink url="http://en.wikipedia.org/wiki/Goliath">Goliath</ulink> 
+David and
+<ulink url="http://en.wikipedia.org/wiki/Goliath">Goliath</ulink>
 are standing by each other.
 </para>
 </description>

File XML-Grammar-Fortune/module/t/to-xhtml-using-api.t

 use strict;
 use warnings;
 
-use Test::More tests => 26;
+use Test::More tests => 39;
 use Test::Differences;
 use Test::XML::Ordered qw(is_xml_ordered);
 
         );
 
         # TEST*$num_texts
+        unlike (
+            $results_buffer, qr/[ \t]$/ms, "No trailing space for '$fn_base'",
+        );
+
+        # TEST*$num_texts
         is_xml_ordered(
             [ string => normalize_xml($results_buffer), @common, ],
             [ location => "./t/data/xhtml-results/$fn_base.xhtml", @common, ],
             "Testing for Good XSLTing of '$fn_base'",
         );
+
+
     }
 
 }

File XML-Grammar-Fortune/module/t/to-xhtml.t

 {
     my $unicode = shift;
 
-    # Remove leading space (indentation), which seems to vary between 
+    # Remove leading space (indentation), which seems to vary between
     # different versions of XML-LibXSLT and/or libxslt
     $unicode =~ s{^[ \t]+}{}gms;
 

File XML-Grammar-Fortune/module/t/xml-validate.t

     ));
 
 my $rngschema = XML::LibXML::RelaxNG->new(
-        location => "./extradata/fortune-xml.rng" 
-    );
+    location => "./extradata/fortune-xml.rng"
+);