1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel fry io io.encodings.utf8 io.files
4 debugger prettyprint continuations namespaces boxes sequences
5 arrays strings html.elements io.streams.string
6 quotations xml.data xml.writer ;
11 GENERIC: call-template* ( template -- )
13 M: string call-template* write ;
15 M: callable call-template* call ;
17 M: xml call-template* write-xml ;
19 M: object call-template* output-stream get stream-copy ;
21 ERROR: template-error template error ;
23 M: template-error error.
24 "Error while processing template " write
25 [ template>> short. ":" print nl ]
29 : call-template ( template -- )
30 [ call-template* ] [ \ template-error boa rethrow ] recover ;
34 : set-title ( string -- )
38 title get value>> write ;
42 : add-style ( string -- )
43 "\n" style get push-all
47 style get >string write ;
51 : add-atom-feed ( title url -- )
52 2array atom-feeds get push ;
54 : write-atom-feeds ( -- )
56 <link "alternate" =rel "application/atom+xml" =type
57 first2 [ =title ] [ =href ] bi*
61 SYMBOL: nested-template?
65 : call-next-template ( -- )
66 next-template get write-html ;
68 M: f call-template* drop call-next-template ;
70 : with-boilerplate ( child master -- )
72 title [ <box> or ] change
73 style [ SBUF" " clone or ] change
74 atom-feeds [ V{ } like ] change
87 : template-convert ( template output -- )
88 utf8 [ call-template ] with-file-writer ;