120 lines
3.4 KiB
Text
120 lines
3.4 KiB
Text
/* NetRexx */
|
|
options replace format comments java crossref symbols nobinary
|
|
|
|
parse arg inFileName .
|
|
if inFileName = '' | inFileName = '.' then inFileName = './data/Brian.csv'
|
|
csv = RREadFileLineByLine01.scanFile(inFileName)
|
|
|
|
header = htmlHeader()
|
|
pre = htmlCsvText(csv, inFileName)
|
|
table = htmlCsvTable(csv, inFileName)
|
|
footer = htmlFooter()
|
|
|
|
say header
|
|
say pre
|
|
say table
|
|
say footer
|
|
|
|
return
|
|
|
|
method htmlHeader() public static returns Rexx
|
|
html = '<?xml version="1.0" encoding="UTF-8"?>\n' -
|
|
|| '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n' -
|
|
|| '<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">\n' -
|
|
|| '<head>\n' -
|
|
|| '<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>\n' -
|
|
|| '<title>RCsv2Html</title>\n' -
|
|
|| '<style type="text/css">\n' -
|
|
|| '<!--\n' -
|
|
|| '/* <![DATA[ */\n' -
|
|
|| 'body {\n' -
|
|
|| ' font-family: "Verdana", "Geneva", "Helvetica Neue", "Helvetica", "DejaVu Sans", "Arial", sans-serif;\n' -
|
|
|| '}\n' -
|
|
|| 'table, th, td {\n' -
|
|
|| ' border: 1px solid black;\n' -
|
|
|| ' border-collapse: collapse;\n' -
|
|
|| ' padding: 0.25em;\n' -
|
|
|| ' font-size: 85%;\n' -
|
|
|| '}\n' -
|
|
|| 'th {\n' -
|
|
|| ' color: white;\n' -
|
|
|| ' background-color: green;\n' -
|
|
|| '}\n' -
|
|
|| 'p.classname {\n' -
|
|
|| ' font-size: inherit;\n' -
|
|
|| '}\n' -
|
|
|| '/* ]] */\n' -
|
|
|| '//-->\n' -
|
|
|| '</style>\n' -
|
|
|| '</head>\n' -
|
|
|| '<body>\n' -
|
|
|| '<h1>Rosetta Code – NetRexx Sample Output</h2>\n' -
|
|
|| '<h2><a href="http://rosettacode.org/wiki/CSV_to_HTML_translation">CSV to HTML translation</a></h2>\n' -
|
|
|| ''
|
|
|
|
return html
|
|
|
|
method htmlFooter() public static returns Rexx
|
|
html = '</body>\n' -
|
|
|| '</html>\n' -
|
|
|| ''
|
|
return html
|
|
|
|
method htmlCsvText(csv, fileName = '.') public static returns Rexx
|
|
html = '<h3>Contents of CSV <code>'fileName'</code></h3>\n' -
|
|
|| '<pre>\n' -
|
|
|| ''
|
|
loop row = 1 to csv[0]
|
|
html = html || csv[row]'\n'
|
|
end row
|
|
html = html -
|
|
|| '</pre>\n' -
|
|
|| ''
|
|
return html
|
|
|
|
method htmlCsvTable(csv, fileName = '.') public static returns Rexx
|
|
html = '<table>\n' -
|
|
|| '<caption>Translation of CSV <code>'fileName'</code></caption>\n' -
|
|
|| '<thead>\n' -
|
|
|| ''
|
|
html = html -
|
|
|| htmlCsvTableRow(csv[1], 'th')'\n' -
|
|
|| '</thead>\n' -
|
|
|| '<tbody>\n' -
|
|
|| ''
|
|
loop r_ = 2 to csv[0]
|
|
html = html -
|
|
|| htmlCsvTableRow(csv[r_])'\n' -
|
|
|| ''
|
|
end r_
|
|
html = html -
|
|
|| '</tbody>\n' -
|
|
|| '</table>\n' -
|
|
|| ''
|
|
return html
|
|
|
|
method htmlCsvTableRow(row, tag = 'td') public static returns Rexx
|
|
row = row.strip('t')
|
|
row = row.changestr('&', '&') -- need to do this one first to avoid double translation
|
|
row = row.changestr('"', '"')
|
|
row = row.changestr("'", ''')
|
|
row = row.changestr('<', '<')
|
|
row = row.changestr('>', '>')
|
|
elmts = ''
|
|
elmts[0] = 0
|
|
e_ = 0
|
|
loop while row.length() > 0
|
|
parse row elmt ',' row
|
|
e_ = e_ + 1; elmts[0] = e_; elmts[e_] = elmt
|
|
end
|
|
html = '<tr>\n' -
|
|
|| ''
|
|
loop e_ = 1 to elmts[0]
|
|
html = html -
|
|
|| '<'tag'>'elmts[e_]'</'tag'>\n' -
|
|
|| ''
|
|
end e_
|
|
html = html -
|
|
|| '</tr>\n' -
|
|
|| ''
|
|
return html
|