Some simple test table:
| x | y = x2.5 |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 5.656854249492381 |
| 3 | 15.5884572681199 |
| 4 | 32 |
| 5 | 55.90169943749474 |
| 6 | 88.18163074019441 |
| 7 | 129.6418142421649 |
| 8 | 181.0193359837562 |
| 9 | 243 |
| 10 | 316.227766016838 |
| 11 | 401.3115996330034 |
| 12 | 498.8306325798367 |
| 13 | 609.3381655534142 |
| 14 | 733.3648478076925 |
| 15 | 871.4212528966688 |
| 16 | 1024 |
| 17 | 1191.577525803504 |
| 18 | 1374.615582626648 |
| 19 | 1573.562518618183 |
| 20 | 1788.854381999832 |
| 21 | 2020.915881475525 |
| 22 | 2270.16122775454 |
| 23 | 2536.994875832429 |
| 24 | 2821.812183686221 |
| 25 | 3125 |
| 26 | 3446.937191188722 |
| 27 | 3787.995116153135 |
| 28 | 4148.538055749278 |
| 29 | 4528.923602800118 |
| 30 | 4929.503017546495 |
| 31 | 5350.621552679651 |
| 32 | 5792.618751480198 |
| 33 | 6255.828722079913 |
| 34 | 6740.580390441168 |
| 35 | 7247.197734297029 |
| 36 | 7776 |
| 37 | 8327.301903978263 |
| 38 | 8901.413820287202 |
| 39 | 9498.641955563964 |
| 40 | 10119.28851253881 |
| 41 | 10763.65184312462 |
| 42 | 11432.02659199147 |
| 43 | 12124.7038314344 |
| 44 | 12841.97118825611 |
1 #!/usr/local/bin/fscript
2 sys out println:'Content-type: text/html\n\n'.
3
4 template := (NSString stringWithContentsOfFile:'template.html').
5
6 tabs := FSRegex regexWithPattern:'\t'.
7 returns := FSRegex regexWithPattern:'\n'.
8 ROWS := FSRegex regexWithPattern:'ROWS'.
9 CODE := FSRegex regexWithPattern:'CODE'.
10 TEMBLATE := FSRegex regexWithPattern:('TEMP'++'LATE').
11
12 rows := [ :x | |y highlight|
13 y := x raisedTo:2.5.
14 highlight := (y=(y intValue) ifTrue:[' highlight'] ifFalse:['']).
15 '<tr class="data' ++ highlight ++ '"><td>' ++ (x stringValue) ++
16 '</td><td>' ++ (y stringValue) ++ '</td></tr>'. ].
17
18 codeWithLineNumbers := [ :line :number |
19 (number<10 ifTrue:[' '] ifFalse:['']) ++ (number stringValue) ++ ' ' ++ line ++ '\n'. ].
20
21 screenReady := [ :code |
22 ((FSRegex regexWithPattern:'\\\\') replaceWithString:'\' inString:
23 ((FSRegex regexWithPattern:'<' ) replaceWithString:'<' inString:code)). ].
24
25 displayFile := [ :name | |fileLines|
26 fileLines := returns splitString:(NSString stringWithContentsOfFile:name).
27 fileLines := (codeWithLineNumbers value:@fileLines value:@((fileLines count) iota + 1)).
28 screenReady value:(fileLines \ #++). ].
29
30 template :=
31 (tabs replaceWithString:' ' inString:
32 (TEMBLATE replaceWithString:(displayFile value:'template.html') inString:
33 (CODE replaceWithString:(displayFile value:'test3.fs') inString:
34 (ROWS replaceWithString:((rows value:@(45 iota)) \ #++) inString:template)))).
35
36 sys out println:template.
37
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
5 <head>
6 <title>F-Script test</title>
7 <style type="text/css">
8 body { font-size:11px; }
9 p { font-size:14px; }
10 pre { background:#cfc; border:1px dashed green; margin-left:170px; padding:10px; }
11 table { background:#99c; border:2px solid #236; margin-top:20px; }
12 #headrow { background:#f9dda8; font-size:14px; }
13 .data { background:white }
14 .codeHead { text-align:center; font-weight:bold; font-size:14px; }
15 .highlight { background:#eef; color:blue; }
16 </style>
17 </head>
18 <body>
19 <div style="float:left">
20 <p>Some simple test table:</p>
21 <table border="0" cellspacing="1" cellpadding="3">
22 <tr id="headrow"><th valign="bottom">x</th><th>y = x<sup>2.5</sup></th></tr>
23 ROWS
24 </table>
25 </div>
26
27 <div class="codeHead">F-Script code that made this page:</div>
28 <pre>CODE</pre>
29
30 <div class="codeHead">HTML Template file used:</div>
31 <pre>TEMPLATE</pre>
32 </body>
33 </html>