factor/basis/furnace/syndication/syndication.factor

53 lines
1.4 KiB
Factor
Raw Normal View History

2008-06-02 16:00:03 -04:00
! Copyright (C) 2008 Slava Pestov.
! 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
furnace.utilities ;
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> ;
2008-06-05 02:48:31 -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
_
2008-06-05 02:48:31 -04:00
[ title>> call >>title ]
[ url>> call adjust-url >>url ]
2008-06-05 02:48:31 -04:00
[ entries>> call process-entries >>entries ]
tri
<feed-content>
] >>display ;