[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Using XML::RSS as a BBEdit Perl Filter



Brian,

My $0.02:
BBEdit filter gives the perl script the selected text as STDIN.
@myinput = <>; -- if there is @ARGV is empty, will simply read from STDIN.
So, perhaps you could open the file for editing, clover-A to select all
the text of the file you wish to process, and invoke the filter from
BBEdit -- which *should* then show up as @myinput (as long as the
INPUT RECORD SEPARATOR is correct).

-L


At 9:50 AM -0700 10/25/99, Brian McNett wrote:
>Okay, as usual, I begin with my normal daftness disclaimer.  My
>abnormally broad blind-spot prevents me from seeing the solution even
>after reading the documentation.
>
>I'm working on adding RSS (that's Netscape's Rich Site Summary) to my
>site.  There's a nice online tutorial:
>
>http://www.webreference.com/perl/tutorial/8/
>
>And the scripts there work (after a fashion) as MacPerl droplets without
>modification.
>
>However, I spend my entire day inside BBEdit, and shifting back to the
>finder just to parse a single file doesn't cut it.
>
>Now, the script that creates the RSS file works like a charm as a BBEdit
>Perl Filter.  Just comment out the line which saves the file, and drop
>the resulting script into the "Perl Filters" folder.
>
>However, the script that parses the RSS file into HTML expect a file name
>or url as an argument from the command line.  Not only is there no
>command line on the Mac, but in droplet form I can't use a URL as an
>argument (obvious reason ":").
>
>BBEdit seems to pass the current selection/file as an array to the perl
>filter being used.
>
>That means  that I can't just:
>
>$rss->parse($my_input);
>
>So I'm stuck.  The script below is BROKEN, mostly because I'm not clear
>on how to set up the input.  I can't (obviously) just pass the array as
>I'm doing here.
>
>#!perl -w
># my_rss2html - converts an RSS file to HTML
># Modified for use as BBEdit Filter
># Brian McNett 10/24/1999
># orig. by Jonathan Eisenzopf. v1.0 19990901
># See http://www.webreference.com/perl for more information
># modified slightly for Mycoinfo.
>
># INCLUDES
>use strict;
>use XML::RSS;
>
>my @infile = <>;
>
># create new instance of XML::RSS
>my $rss = new XML::RSS;
>
>    # parse the RSS file
>    $rss->parse(@infile);
>
># print the HTML channel
>&print_html($rss);
>
># SUBROUTINES
>sub print_html {
>    my $rss = shift;
>       if ($rss->{'image'}->{'link'}) {
>print <<HTML;
><table bgcolor="#333366" border="0" width="184"><tr><td>
><table cellspacing="1" cellpadding="2" bgcolor="#FFFFFF" border=0
>width="100%">
><tr>
><td valign="middle" align="center" bgcolor="#3366CC">
><center><a href="$rss->{'image'}->{'link'}"><img
>src="$rss->{'image'}->{'url'}" alt="$rss->{'image'}->{'title'}" border="0"
>HTML
>
>    print " width=\"$rss->{'image'}->{'width'}\""
>	    if $rss->{'image'}->{'width'};
>	print " height=\"$rss->{'image'}->{'height'}\""
>	    if $rss->{'image'}->{'height'};
>	print "></a></center>\n";
>    }
>
>print <<'HTML';
></td>
></tr>
><tr>
><td>
>HTML
>
>    # print the channel items
>    foreach my $item (@{$rss->{'items'}}) {
>	next unless defined($item->{'title'}) && defined($item->{'link'});
>	print "<font size='-1'><li><a
>href=\"$item->{'link'}\">$item->{'title'}</a></font><br>\n";
>    }
>
>    # if there's a textinput element
>    if ($rss->{'textinput'}->{'title'}) {
>	print <<HTML;
><form method="get" action="$rss->{'textinput'}->{'link'}">
>$rss->{'textinput'}->{'description'}<br>
><input type="text" name="$rss->{'textinput'}->{'name'}"><br>
><input type="submit" value="$rss->{'textinput'}->{'title'}">
></form>
>HTML
>    }
>
>    # if there's a copyright element
>    if ($rss->{'channel'}->{'copyright'}) {
>	print <<HTML;
><p align='right'><sub>$rss->{'channel'}->{'copyright'}</sub></p>
>HTML
>    }
>
>    print <<HTML;
></td>
></tr>
></table>
></td>
></tr>
></table>
>HTML
>}
>
>__END__
>
>XML::RSS is a sub-class of XML::Parser, so you'll need both if you want
>to help out with this.  It's probably DEAD simple, given my peculiar
>combination of genius and cluelessness alluded to in the disclaimer above.
>
>--B
>
># Brian McNett                                      Fungal Parataxonomy
># Webmaster, Staff Writer               Mycology Information (Mycoinfo)
>#                              **The World's First Mycology E-Journal**
># <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/>
># First they ignore you. Then they laugh at you. Then they fight you.
># Then you win.                                     --Mohandas Gandhi
>
>
># ===== Want to unsubscribe from this list?
># ===== Send mail with body "unsubscribe" to macperl-request@macperl.org

--
Regards, Larry F. Allen-Tonar        (larryat@cts.com) +1 760/746-6464 (voice)
         Principal Designer                              +1 760/746-0766 (FAX,
         P.O. Box 463072                                         upon request)
         Escondido, CA  92046-3072
"Futuaris nisi irrisus ridebis.", Carlton in _The Road to Mars_ by Eric Idle

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org