]> gitweb.factorcode.org Git - factor.git/blob - basis/lcs/diff2html/diff2html.factor
Merge qualified, alias, symbols, constants into core
[factor.git] / basis / lcs / diff2html / diff2html.factor
1 ! Copyright (C) 2008 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: lcs html.elements kernel ;
4 FROM: accessors => item>> ;
5 FROM: io => write ;
6 FROM: sequences => each if-empty ;
7 FROM: xml.entities => escape-string ;
8 IN: lcs.diff2html
9
10 GENERIC: diff-line ( obj -- )
11
12 : write-item ( item -- )
13     item>> [ " " ] [ escape-string ] if-empty write ;
14
15 M: retain diff-line
16     <tr>
17         dup [
18             <td "retain" =class td>
19                 write-item
20             </td>
21         ] bi@
22     </tr> ;
23
24 M: insert diff-line
25     <tr>
26         <td> </td>
27         <td "insert" =class td>
28             write-item
29         </td>
30     </tr> ;
31
32 M: delete diff-line
33     <tr>
34         <td "delete" =class td>
35             write-item
36         </td>
37         <td> </td>
38     </tr> ;
39
40 : htmlize-diff ( diff -- )
41     <table "100%" =width "comparison" =class table>
42         <tr> <th> "Old" write </th> <th> "New" write </th> </tr>
43         [ diff-line ] each
44     </table> ;