* tests/adirtest.prg
* tests/ainstest.prg
* tests/and_or.prg
* tests/array16.prg
* tests/arrayidx.prg
* tests/arrays.prg
* tests/arrindex.prg
* tests/atest.prg
* tests/base64.prg
* tests/byref.prg
* tests/calling.prg
* tests/cdow.prg
* tests/clasinit.prg
* tests/clasname.prg
* tests/classch.prg
* tests/classes.prg
* tests/clsdata.prg
* tests/cmphello.prg
* tests/codebl.prg
* tests/curdirt.prg
* tests/cursrtst.prg
* tests/dates.prg
* tests/dates2.prg
* tests/dates3.prg
* tests/debugtst.prg
* tests/delimtst.prg
* tests/devtest.prg
* tests/dirtest.prg
* tests/disptest.prg
* tests/docase.prg
* tests/dosshell.prg
* tests/dttest.prg
* tests/dupvars.prg
* tests/dynobj.prg
* tests/dynsym.prg
* tests/exittest.prg
* tests/extend1.prg
* tests/fib.prg
* tests/fornext.prg
* tests/fortest.prg
* tests/funcarr.prg
* tests/hbdoctst.prg
* tests/hsxtest.prg
* tests/ifelse.prg
* tests/inifiles.prg
* tests/initexit.prg
* tests/inkeytst.prg
* tests/inline_c.prg
* tests/inline.prg
* tests/iotest.prg
* tests/iotest2.prg
* tests/ipclnt.prg
* tests/ipsvr.prg
* tests/longstr.prg
* tests/mathtest.prg
* tests/memvar.prg
* tests/multiarg.prg
* tests/nums.prg
* tests/objarr.prg
* tests/objasign.prg
* tests/objects.prg
* tests/os.prg
* tests/overload.prg
* tests/parexpr.prg
* tests/passref.prg
* tests/procname.prg
* tests/recursiv.prg
* tests/returns.prg
* tests/round.prg
* tests/sdf_test.prg
* tests/seconds.prg
* tests/set_num.prg
* tests/set_test.prg
* tests/sound.prg
* tests/statfun.prg
* tests/statics.prg
* tests/statics1.prg
* tests/statics2.prg
* tests/strdelim.prg
* tests/stripem.prg
* tests/t1.prg
* tests/test.prg
* tests/testerro.prg
* tests/testfor.prg
* tests/testget.prg
* tests/testhtml.prg
* tests/testid.prg
* tests/testop.prg
* tests/teststr.prg
* tests/testtok.prg
* tests/testvars.prg
* tests/tflock.prg
* tests/tstalias.prg
* tests/version.prg
* tests/videotst.prg
* tests/while.prg
* tests/wvtext.prg
! various cleanups and fixes after running almost all of them
* ChangeLog
* changed hbqt new repository to its new location:
http://sourceforge.net/projects/qtcontribs/
156 lines
4.0 KiB
Plaintext
156 lines
4.0 KiB
Plaintext
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
*
|
|
* testhtml.prg
|
|
* Harbour Test of a HTML-Generator class.
|
|
*
|
|
* Tips: - Use ShowResults to make dynamic html (to test dynamic
|
|
* results, put the exe file on CGI-BIN dir or equivalent);
|
|
* - Use SaveToFile to make static html page
|
|
*
|
|
**/
|
|
|
|
PROCEDURE Main()
|
|
|
|
LOCAL oHTML := THTML():New()
|
|
|
|
oHTML:SetTitle( "Harbour Power Demonstration" )
|
|
oHTML:AddHead( "Harbour" )
|
|
oHTML:AddPara( "<b>Harbour</b> is xBase at its best. Have a taste today!", "LEFT" )
|
|
oHTML:AddPara( "<b>L i n k s</b>", "CENTER" )
|
|
oHTML:AddLink( "http://harbour-project.org", "Meet the Harbour power!" )
|
|
oHTML:Generate()
|
|
|
|
// Uncomment the following if you don't have a Web Server to test
|
|
// this sample
|
|
|
|
// oHTML:SaveToFile( "test.htm" )
|
|
|
|
// If the above is uncommented, you may comment this line:
|
|
|
|
oHTML:ShowResult()
|
|
|
|
RETURN
|
|
|
|
FUNCTION THTML()
|
|
|
|
STATIC oClass
|
|
|
|
IF oClass == NIL
|
|
oClass := HBClass():New( "THTML" )
|
|
|
|
oClass:AddData( "cTitle" ) // Page Title
|
|
oClass:AddData( "cBody" ) // HTML Body Handler
|
|
oClass:AddData( "cBGColor" ) // Background Color
|
|
oClass:AddData( "cLinkColor" ) // Link Color
|
|
oClass:AddData( "cvLinkColor" ) // Visited Link Color
|
|
oClass:AddData( "cContent" ) // Page Content Handler
|
|
|
|
oClass:AddMethod( "New", @New() ) // New Method
|
|
oClass:AddMethod( "SetTitle", @SetTitle() ) // Set Page Title
|
|
oClass:AddMethod( "AddHead", @AddHead() ) // Add <H1> Header
|
|
oClass:AddMethod( "AddLink", @AddLink() ) // Add Hyperlink
|
|
oClass:AddMethod( "AddPara", @AddPara() ) // Add Paragraph
|
|
oClass:AddMethod( "Generate", @Generate() ) // Generate HTML
|
|
oClass:AddMethod( "SaveToFile", @SaveToFile() ) // Saves Content to File
|
|
oClass:AddMethod( "ShowResult", @ShowResult() ) // Show Result - SEE Fcn
|
|
|
|
oClass:Create()
|
|
ENDIF
|
|
|
|
RETURN oClass:Instance()
|
|
|
|
STATIC FUNCTION New()
|
|
|
|
LOCAL Self := QSelf()
|
|
|
|
::cTitle := "Untitled"
|
|
::cBGColor := "#FFFFFF"
|
|
::cLinkColor := "#0000FF"
|
|
::cvLinkColor := "#FF0000"
|
|
::cContent := ""
|
|
::cBody := ""
|
|
|
|
RETURN Self
|
|
|
|
STATIC FUNCTION SetTitle( cTitle )
|
|
|
|
LOCAL Self := QSelf()
|
|
|
|
::cTitle := cTitle
|
|
|
|
RETURN Self
|
|
|
|
STATIC FUNCTION AddLink( cLinkTo, cLinkName )
|
|
|
|
LOCAL Self := QSelf()
|
|
|
|
::cBody := ::cBody + ;
|
|
"<a href='" + cLinkTo + "'>" + cLinkName + "</a>"
|
|
|
|
RETURN Self
|
|
|
|
STATIC FUNCTION AddHead( cDescr )
|
|
|
|
LOCAL Self := QSelf()
|
|
|
|
// Why this doesn't work?
|
|
// ::cBody += ...
|
|
// ???
|
|
|
|
::cBody := ::cBody + ;
|
|
"<h1>" + cDescr + "</h1>"
|
|
|
|
RETURN NIL
|
|
|
|
STATIC FUNCTION AddPara( cPara, cAlign )
|
|
|
|
LOCAL Self := QSelf()
|
|
|
|
cAlign := iif( cAlign == NIL, "Left", cAlign ) // Added Patrick Mast 2000-06-17
|
|
|
|
::cBody := ::cBody + ;
|
|
"<p align='" + cAlign + "'>" + hb_eol() + ;
|
|
cPara + hb_eol() + ;
|
|
"</p>"
|
|
|
|
RETURN Self
|
|
|
|
STATIC FUNCTION Generate()
|
|
|
|
LOCAL Self := QSelf()
|
|
|
|
::cContent := ;
|
|
"<html><head>" + hb_eol() + ;
|
|
"<title>" + ::cTitle + "</title>" + hb_eol() + ;
|
|
"<body link='" + ::cLinkColor + "' " + ;
|
|
"vlink='" + ::cvLinkColor + "'>" + + hb_eol() + ;
|
|
::cBody + hb_eol() + ;
|
|
"</body></html>"
|
|
|
|
RETURN Self
|
|
|
|
STATIC FUNCTION ShowResult()
|
|
|
|
LOCAL Self := QSelf()
|
|
|
|
OutStd( ;
|
|
;// "HTTP/1.0 200 OK" + hb_eol() + ;
|
|
"CONTENT-TYPE: TEXT/HTML" + hb_eol() + hb_eol() + ;
|
|
::cContent )
|
|
|
|
RETURN Self
|
|
|
|
STATIC FUNCTION SaveToFile( cFile )
|
|
|
|
LOCAL Self := QSelf()
|
|
LOCAL hFile := FCreate( cFile )
|
|
|
|
FWrite( hFile, ::cContent )
|
|
FClose( hFile )
|
|
|
|
RETURN Self
|