Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > cd38b09e3cb8d6c675b02d30393e68af > files > 51

kaya-doc-0.5.2-8.fc14.noarch.rpm

program HTMLtest;

import HTMLDocument;

Void main() {

  // create a new HTML document
  doc = new(HTML4Strict,"Hello World!");

  // add some document meta data
  addDocumentMetaData(doc,"generator","KayHTML");
  addDocumentLink(doc,Rev("author"),"mailto:author@example.invalid");
  addDocumentStylesheet(doc,[MTscreen,MTprojection],"http://www.example.com/styles.css");
  
  // add a heading to the document
  heading = addHeading(doc.body,1,"Hello World!");
  // set a CSS style on the heading
  setClass(heading,"first");

  // add a paragraph to the text
  paragraph = addParagraph(doc.body,"This is a simple HTML document. It can also include special characters such as α, α, α or "+Char(945)+".");
  //paragraph = addParagraph(doc.body,"This is a simple HTML document α α α.");

  // apply some emphasis to parts of the paragraph and make some of it
  // a hyperlink.
  em = addInlineElementAt(paragraph,Emphasis,10,15);
  link = addInlineElementAt(paragraph,Hyperlink("http://www.w3.org/TR/html4/"),8,30);

  // add an ordered list
  listitems = ["First list item",
	       "Second list item",
	       "Third list item",
	       "Fourth list item",
	       "Fifth list item"];
  olist = addList(doc.body,Ordered,5,listitems);
  // get the fourth <li>
  fourthitem = getListItem(olist,3); // zero-indexed
  // and emphasise some of the text.
  strong = addInlineElementAt(fourthitem,StrongEmphasis,0,5);
  // we can nest lists, too
  ulist = addList(fourthitem,Unordered,2,["4a","4b"]);
  // can add items into lists later at arbitrary position
  pusheditem = addListItem(olist,3,"3.5th list item");
  // images can be added too
  image = addImage(pusheditem,ImageData("http://www.example.com/image.png","(NEW!)",Specified(15,10)));
  linebreak = addLineBreak(pusheditem);
  // this is an alternative way to construct inline sections
  note = appendInlineElement(pusheditem,SmallerText,"This item's text should be renumbered");

  
  // add a table (the complicated way)
  table = addTable(doc.body,"Table 1: Fish population 1989-1990");
  // create a head section for it
  thead = getTableHeader(table);
  headerrow = addTableRow(thead);
  // add a body section and add two rows to that.
  tbody = addTableBodySection(table);
  row1 = addTableRow(tbody);
  row2 = addTableRow(tbody);
  // add two columns (we need at least one row in the table to do this
  // without bugs at the moment, though we should implement
  // <col(group)> to fix that up)
  addTableColumns(table,2);

  // make the header cells table headers and add some header text
  addString(makeHeaderCell(thead,0,0),"Year");
  addString(makeHeaderCell(thead,0,1),"Population");
  // now add some data cell contents (all cells start off as data cells)
  addString(getTableCell(tbody,0,0),"1989");
  addString(getTableCell(tbody,0,1),"312");
  addString(getTableCell(tbody,1,0),"1990");
  addString(getTableCell(tbody,1,1),"304");
  
  // add a table (the easy way)
  itd = InitialTableData([["Year","Average River Depth (m)"]],[[]],[[["1989","2.7"],["1990","2.6"]]]);
  table2 = initialiseTable(doc.body,itd,"Table 2: River Depth 1989-1990");
  
  // add a form
  form = addLocalForm(doc.body);
  // define a fieldset
  fs1 = addFieldset(form,"Personal information");
  // add some basic fields
  in1 = addLabelledInput(fs1,"Your name:",InputText,"name","",30);
  in2 = addLabelledInput(fs1,"Your email:",InputText,"email","",30);
  in3 = addLabelledInput(fs1,"Your password:",InputPassword,"pwd","",30);
  // create another fieldset to hold some checkbox options
  mlists = [SelectOption("kaya-devel@compsoc.dur.ac.uk","kd",true),
	    SelectOption("html-help@example.org.invalid","hh",false),
	    SelectOption("bugs@example.net.invalid","bugs",false)];
  fs2 = addOptionList(form,"Mailing lists to subscribe to","mlists",mlists,true);
  // add a text area to the fieldset
  tabox = addLabelledTextarea(fs2,"othermls","Are there any other mailing lists you think we should include?");
  // another fieldset
  fs3 = addFieldset(form,"Terms and conditions");
  // a select box with optgroups
  options = [("",[SelectOption("I have already agreed to the T&Cs","done",false)]),
	     ("Selective agreement to T&Cs",
	      [SelectOption("Minimum only","min",false),
	       SelectOption("Minimum and voluntary code of conduct","vcc",false),
	       SelectOption("Minimum and public contact details","pcd",false)]),
	     ("",[SelectOption("I agree to all T&Cs","all",true)])];
  selector = addSelectElement(fs3,"tandc",0,options);
  // add the submit button
  in4 = addRemoteControlInput(fs3,InputSubmit,"","Register");
  

  // make a document footer
  separator = addHorizontalRule(doc.body);
  address = addAddress(doc.body,"Email author@example.invalid to contact the author");

  // convert the document to a string and print it
  putStrLn(string(doc));

}