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 |
1 #!/usr/local/bin/fscript
2 (NSBundle bundleWithPath:'/Library/Frameworks/AGRegex7.framework') load.
3 sys out println:'Content-type: text/html\n\n'.
4 template := (NSString stringWithContentsOfFile:'template.html').
5
6 tabs := (AGRegex regexWithPattern:'\t').
7 leftBrackets := AGRegex regexWithPattern:'<'.
8 backSlash := AGRegex regexWithPattern:'\\\\'.
9 tableRows := AGRegex regexWithPattern:'ROWS'.
10 preCode := AGRegex regexWithPattern:'CODE'.
11 preTemplate := AGRegex regexWithPattern:('TEMP'++'LATE').
12
13 codeBlock := [ :codeLine | l := l + 1. (l stringValue) ++ ' ' ++ codeLine ++ '\n'. ].
14
15 rows := [ :i |
16 '<tr class="data"><td>' ++ (i stringValue) ++ '</td>' ++
17 '<td>' ++ ((i raisedTo:2.5) stringValue) ++ '</td></tr>'.
18 ] value:@(15 iota).
19 template := tableRows replaceWithString:(rows \ #++) inString:template.
20
21 l := 0.
22 codeFile := (NSString stringWithContentsOfFile:'test.fs').
23 codeLines := (codeBlock value:@(codeFile componentsSeparatedByString:'\n')) \ #++.
24 codeLines := leftBrackets replaceWithString:'<' inString:codeLines.
25 codeLines := backSlash replaceWithString:'\' inString:codeLines.
26 template := preCode replaceWithString:codeLines inString:template.
27
28 l := 0.
29 templateFile := (NSString stringWithContentsOfFile:'template.html').
30 codeLines := (codeBlock value:@(templateFile componentsSeparatedByString:'\n')) \ #++.
31 codeLines := leftBrackets replaceWithString:'<' inString:codeLines.
32 template := preTemplate replaceWithString:codeLines inString:template.
33
34 template := tabs replaceWithString:' ' inString:template.
35 sys out println:template.
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>