]> gitweb.factorcode.org Git - factor.git/blob - basis/furnace/syndication/syndication.factor
Updating code for make and fry changes
[factor.git] / basis / furnace / syndication / syndication.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel sequences fry
4 combinators syndication
5 http.server.responses http.server.redirection
6 furnace furnace.actions ;
7 IN: furnace.syndication
8
9 GENERIC: feed-entry-title ( object -- string )
10
11 GENERIC: feed-entry-date ( object -- timestamp )
12
13 GENERIC: feed-entry-url ( object -- url )
14
15 GENERIC: feed-entry-description ( object -- description )
16
17 M: object feed-entry-description drop f ;
18
19 GENERIC: >entry ( object -- entry )
20
21 M: entry >entry ;
22
23 M: object >entry
24     <entry>
25         swap {
26             [ feed-entry-title >>title ]
27             [ feed-entry-date >>date ]
28             [ feed-entry-url >>url ]
29             [ feed-entry-description >>description ]
30         } cleave ;
31
32 : process-entries ( seq -- seq' )
33     20 short head-slice [
34         >entry clone
35         [ adjust-url relative-to-request ] change-url
36     ] map ;
37
38 : <feed-content> ( body -- response )
39     feed>xml "application/atom+xml" <content> ;
40
41 TUPLE: feed-action < action title url entries ;
42
43 : <feed-action> ( -- action )
44     feed-action new-action
45         dup '[
46             feed new
47                 _
48                 [ title>> call >>title ]
49                 [ url>> call adjust-url relative-to-request >>url ]
50                 [ entries>> call process-entries >>entries ]
51                 tri
52             <feed-content>
53         ] >>display ;