]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/tangle/html/html.factor
2ec6b526092826d7e875d55c65040a7bb081b1ae
[factor.git] / unmaintained / tangle / html / html.factor
1 ! Copyright (C) 2008 Alex Chapman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors html.elements io io.streams.string kernel namespaces semantic-db sequences strings tangle.path ;
4 IN: tangle.html
5
6 TUPLE: element attributes ;
7
8 TUPLE: ulist < element items ;
9 : <ulist> ( items -- element )
10     H{ } clone swap ulist boa ;
11
12 TUPLE: link < element href text ;
13 : <link> ( href text -- element )
14     H{ } clone -rot link boa ;
15
16 GENERIC: >html ( element -- str )
17
18 M: string >html ( str -- str ) ;
19
20 M: link >html ( link -- str )
21     [ <a dup href>> =href a> text>> write </a> ] with-string-writer ;
22
23 M: node >html ( node -- str )
24     dup node>path [
25         swap node-content <link> >html
26     ] [
27         node-content
28     ] if* ;
29
30 M: ulist >html ( ulist -- str )
31     [
32         <ul> items>> [ <li> >html write </li> ] each </ul>
33     ] with-string-writer ;