62 lines
2.1 KiB
Plaintext
62 lines
2.1 KiB
Plaintext
output file "CSV2HTML"
|
|
|
|
include "Tlbx WebKit.incl"
|
|
|
|
_window = 1
|
|
begin enum output 1
|
|
_webView
|
|
end enum
|
|
|
|
void local fn BuildWindow
|
|
CGRect r = fn CGRectMake( 0, 0, 600, 220 )
|
|
window _window, @"Rosetta Code CSV to HTML", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
|
|
|
|
r = fn CGRectMake( 20, 20, 560, 180 )
|
|
wkwebview _webView, r,, _window
|
|
end fn
|
|
|
|
local fn CSV2HTML as CFStringRef
|
|
NSUInteger i, count
|
|
|
|
CFStringRef csvStr = @"Character,Speech\n¬
|
|
The multitude,The messiah! Show us the messiah!\n¬
|
|
Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!\n¬
|
|
The multitude,Who are you\n¬
|
|
Brians mother,I'm his mother; that's who!\n¬
|
|
The multitude,Behold his mother! Behold his mother!"
|
|
|
|
CFArrayRef linesArray = fn StringComponentsSeparatedByString( csvStr, @"\n" )
|
|
CFMutableStringRef htmlStr = fn MutableStringWithCapacity(0)
|
|
MutableStringAppendString( htmlStr, @"<table style=\"background:#eee;\">\n" )
|
|
MutableStringAppendString( htmlStr, @"<tr bgcolor=wheat><th>Character</th><th>Speech</th></tr>" )
|
|
MutableStringAppendString( htmlStr, @"<caption>From Monty Python's \"The Life of Brian\"</caption>\n" )
|
|
count = len( linesArray )
|
|
for i = 1 to count - 1
|
|
CFStringRef tempStr = linesArray[i]
|
|
CFArrayRef tempArr = fn StringComponentsSeparatedByString( tempStr, @"," )
|
|
MutableStringAppendString( htmlStr, @"<tr>\n" )
|
|
MutableStringAppendString( htmlStr, fn StringWithFormat( @"<td style=\"width:120px;\"><b>%@</b></td>>\n", tempArr[0] ) )
|
|
MutableStringAppendString( htmlStr, fn StringWithFormat( @"<td><i>%@</i></td>\n", tempArr[1] ) )
|
|
MutableStringAppendString( htmlStr, @"</tr>\n" )
|
|
next
|
|
MutableStringAppendString( htmlStr, @"</table><br></br>" )
|
|
end fn = fn StringWithString( htmlStr )
|
|
|
|
local fn LoadHTML2WebView
|
|
CFStringRef htmlStr = fn CSV2HTML
|
|
fn WKWebViewLoadHTMLString( _webView, htmlStr, NULL )
|
|
end fn
|
|
|
|
void local fn DoDialog( ev as long, tag as long, wnd as long, obj as CFTypeRef )
|
|
select (ev)
|
|
case _windowWillClose : end
|
|
end select
|
|
end fn
|
|
|
|
on dialog fn DoDialog
|
|
|
|
fn BuildWindow
|
|
fn LoadHTML2WebView
|
|
|
|
HandleEvents
|