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