/* * SPL - The SPL Programming Language * Copyright (C) 2004, 2005 Clifford Wolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * webspltut05.webspl: An example from the WebSPL Tutorial */ load "wsf"; load "wsf_display"; load "wsf_menu"; load "file"; load "encode_js"; object Editpage WsfComponent { var filename; method get_html() { var data = file_read(filename); return <>

Edit page `${xml::filename =~ s/\.html$//R}':


; } method main() { task_co_return(); if (declared cgi.param.remove) { file_delete(filename); create_menu(); page.root.child_set("content", new WsfComponent()); } else { file_write(filename, cgi.param.data); dirty = 1; } } method init(_filename) { filename = _filename; return *WsfComponent.init(); } } object Newpage WsfComponent { method get_html() { return <>

Create a new page:

Filename:

Page Title:

; } method main() { task_co_return(); var pagetitle = xml::cgi.param.pagetitle; var filename = xml::cgi.param.filename; filename =~ s/^(.*\/|)\.*//; filename =~ s/(? : : : : ${xml::pagetitle} : : :

${xml::pagetitle}

: : EOT; file_write(filename, html); create_menu(); page.root.child_set("content", new Editpage(filename)); } } function create_menu() { var menu; menu["Pages"] = ({ var pages; var ls = file_list("."); foreach i (ls) if ( ls[i] =~ /^(?P(?P.*)\.html)$/ ) { import $$; pages[title] = function() { page.root.child_set("content", new Editpage(filename)); }; } return pages; }); menu["New Page"] = function() { page.root.child_set("content", new Newpage()); }; page.root.child_set("menu", new WsfMenu(menu)); } // hide login logic because it is covered in a different tutorial section #file-as-code webspltut06.spl var page = new WsfDocument(); page.root = new WsfComponent(); create_menu(); page.main();