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 io.streams.string
6 quotations xml.data xml.writer xml.literals ;
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 ( -- )
59 type="application/atom+xml"
65 SYMBOL: nested-template?
69 : call-next-template ( -- )
70 next-template get write ;
72 M: f call-template* drop call-next-template ;
74 : with-boilerplate ( child master -- )
76 title [ <box> or ] change
77 style [ SBUF" " clone or ] change
78 atom-feeds [ V{ } like ] change
91 : template-convert ( template output -- )
92 utf8 [ call-template ] with-file-writer ;