Merge branch 'master' of git://factorcode.org/git/factor

db4
Doug Coleman 2009-03-31 16:06:01 -05:00
commit 70d04c04e0
3 changed files with 18 additions and 15 deletions

View File

@ -35,9 +35,9 @@ HELP: download-feed
{ $values { "url" url } { "feed" feed } } { $values { "url" url } { "feed" feed } }
{ $description "Downloads a feed from a URL using the " { $link "http.client" } "." } ; { $description "Downloads a feed from a URL using the " { $link "http.client" } "." } ;
HELP: string>feed HELP: parse-feed
{ $values { "string" string } { "feed" feed } } { $values { "sequence" "a string or a byte array" } { "feed" feed } }
{ $description "Parses a feed in string form." } ; { $description "Parses a feed." } ;
HELP: xml>feed HELP: xml>feed
{ $values { "xml" xml } { "feed" feed } } { $values { "xml" xml } { "feed" feed } }
@ -58,7 +58,7 @@ $nl
{ $subsection <entry> } { $subsection <entry> }
"Reading feeds:" "Reading feeds:"
{ $subsection download-feed } { $subsection download-feed }
{ $subsection string>feed } { $subsection parse-feed }
{ $subsection xml>feed } { $subsection xml>feed }
"Writing feeds:" "Writing feeds:"
{ $subsection feed>xml } { $subsection feed>xml }

View File

@ -1,4 +1,4 @@
USING: syndication io kernel io.files tools.test io.encodings.utf8 USING: syndication io kernel io.files tools.test io.encodings.binary
calendar urls xml.writer ; calendar urls xml.writer ;
IN: syndication.tests IN: syndication.tests
@ -8,7 +8,7 @@ IN: syndication.tests
: load-news-file ( filename -- feed ) : load-news-file ( filename -- feed )
#! Load an news syndication file and process it, returning #! Load an news syndication file and process it, returning
#! it as an feed tuple. #! it as an feed tuple.
utf8 file-contents string>feed ; binary file-contents parse-feed ;
[ T{ [ T{
feed feed

View File

@ -1,11 +1,11 @@
! Copyright (C) 2006 Chris Double, Daniel Ehrenberg. ! Copyright (C) 2006 Chris Double, Daniel Ehrenberg.
! Portions copyright (C) 2008 Slava Pestov. ! Portions copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: xml.traversal kernel assocs math.order USING: xml.traversal kernel assocs math.order strings sequences
strings sequences xml.data xml.writer xml.data xml.writer io.streams.string combinators xml
io.streams.string combinators xml xml.entities.html io.files io xml.entities.html io.files io http.client namespaces make
http.client namespaces make xml.syntax hashtables xml.syntax hashtables calendar.format accessors continuations
calendar.format accessors continuations urls present ; urls present byte-arrays ;
IN: syndication IN: syndication
: any-tag-named ( tag names -- tag-inside ) : any-tag-named ( tag names -- tag-inside )
@ -106,12 +106,15 @@ TUPLE: entry title url description date ;
{ "feed" [ atom1.0 ] } { "feed" [ atom1.0 ] }
} case ; } case ;
: string>feed ( string -- feed ) GENERIC: parse-feed ( sequence -- feed )
[ string>xml xml>feed ] with-html-entities ;
M: string parse-feed [ string>xml xml>feed ] with-html-entities ;
M: byte-array parse-feed [ bytes>xml xml>feed ] with-html-entities ;
: download-feed ( url -- feed ) : download-feed ( url -- feed )
#! Retrieve an news syndication file, return as a feed tuple. #! Retrieve an news syndication file, return as a feed tuple.
http-get nip string>feed ; http-get nip parse-feed ;
! Atom generation ! Atom generation