1 ! Copyright (C) 2008, 2009 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 io.streams.string assocs call
6 quotations xml.data xml.writer xml.syntax ;
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 -- )
37 : get-title ( -- string )
45 : add-style ( string -- )
46 "\n" style get push-all
49 : get-style ( -- string )
57 : add-atom-feed ( title url -- )
58 2array atom-feeds get push ;
60 : get-atom-feeds ( -- xml )
65 type="application/atom+xml"
71 : write-atom-feeds ( -- )
72 get-atom-feeds write-xml ;
74 SYMBOL: nested-template?
78 : call-next-template ( -- )
79 next-template get write ;
81 M: f call-template* drop call-next-template ;
83 : with-boilerplate ( child master -- )
85 title [ <box> or ] change
86 style [ SBUF" " clone or ] change
87 atom-feeds [ V{ } like ] change
100 : template-convert ( template output -- )
101 utf8 [ call-template ] with-file-writer ;