factor/basis/furnace/syndication/syndication.factor

55 lines
1.4 KiB
Factor
Raw Normal View History

2010-03-13 03:13:34 -05:00
! Copyright (C) 2008, 2010 Slava Pestov.
2008-06-02 16:00:03 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-11-24 21:26:11 -05:00
USING: accessors kernel sequences fry combinators syndication
http.server.responses http.server.redirection furnace.actions
2010-03-13 03:13:34 -05:00
furnace.utilities io.encodings.utf8 ;
2008-06-05 02:56:06 -04:00
IN: furnace.syndication
2008-06-02 16:00:03 -04:00
2008-06-05 02:48:31 -04:00
GENERIC: feed-entry-title ( object -- string )
GENERIC: feed-entry-date ( object -- timestamp )
GENERIC: feed-entry-url ( object -- url )
GENERIC: feed-entry-description ( object -- description )
M: object feed-entry-description drop f ;
GENERIC: >entry ( object -- entry )
M: entry >entry ;
M: object >entry
<entry>
swap {
[ feed-entry-title >>title ]
[ feed-entry-date >>date ]
[ feed-entry-url >>url ]
[ feed-entry-description >>description ]
} cleave ;
: process-entries ( seq -- seq' )
20 short head-slice [
>entry clone
[ adjust-url ] change-url
2008-06-05 02:48:31 -04:00
] map ;
2008-06-02 16:00:03 -04:00
: <feed-content> ( body -- response )
feed>xml "application/atom+xml" <content>
"UTF-8" >>content-charset
utf8 >>content-encoding ;
2008-06-02 16:00:03 -04:00
TUPLE: feed-action < action title url entries ;
2008-06-02 16:00:03 -04:00
2008-06-05 02:48:31 -04:00
: <feed-action> ( -- action )
2008-06-02 16:00:03 -04:00
feed-action new-action
2008-06-05 02:48:31 -04:00
dup '[
feed new
2008-09-10 23:11:40 -04:00
_
[ title>> call >>title ]
[ url>> call adjust-url >>url ]
[ entries>> call process-entries >>entries ]
tri
2008-06-05 02:48:31 -04:00
<feed-content>
] >>display ;