]> gitweb.factorcode.org Git - factor.git/blob - basis/lcs/diff2html/diff2html.factor
b244ddd45cb553a4aea128c863ea93cd09a7955a
[factor.git] / basis / lcs / diff2html / diff2html.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel lcs sequences strings xml.syntax
4 xml.writer ;
5 IN: lcs.diff2html
6
7 GENERIC: diff-line ( obj -- xml )
8
9 : item-string ( item -- string )
10     item>> [ CHAR: no-break-space 1string ] when-empty ;
11
12 M: retain diff-line
13     item-string
14     [XML <td class="retain"><-></td> XML]
15     dup [XML <tr><-><-></tr> XML] ;
16
17 M: insert diff-line
18     item-string [XML
19         <tr>
20             <td> </td>
21             <td class="insert"><-></td>
22         </tr>
23     XML] ;
24
25 M: delete diff-line
26     item-string [XML
27         <tr>
28             <td class="delete"><-></td>
29             <td> </td>
30         </tr>
31     XML] ;
32
33 : htmlize-diff ( diff -- xml )
34     [ diff-line ] map
35     [XML
36         <table width="100%" class="comparison">
37             <tr><th>Old</th><th>New</th></tr>
38             <->
39         </table>
40     XML] ;