Prev | Current Page 774 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


First the quotation service is implemented using Neko. The class QuotationService is very basic:
When the script is executed, Neko opens a text file that contains all of the quotations, reads them all, and
picks one up randomly. After that, it formats the quotation in an HTML fragment and sends it as the
response to the request. To see how to compile and work with Neko on the server side, see Chapter 9 .
import neko.io.File;
typedef Quotation = { author : String, quotation : String }
class QuotationService
{
public static function main()
{
var q = pickRandom(loadQuotations());
neko.Lib.print(toHtmlFragment(q));
}
private static function toHtmlFragment(q)
{
var b = new StringBuf();
b.add(??? < q > ??™);
b.add(q.quotation);
b.add(??? < /q > ( < em > ??™);
b.add(q.author);
b.add(??? < /em > )??™);
return b.toString();
}
private static function loadQuotations()
{
var c = StringTools.trim(File.getContent(???quotations.txt???));
var q = new Array();
for(line in c.split(???\n???))
{
var p = line.


Pages:
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786