PageRenderTime 25ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/unmaintained/tangle/html/html.factor

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