84af181997-11-14Per Hedbor /* This is a Roxen Challenger(r) module. Copyright (c) Idonex 1997. * Released under GPL * made by Per Hedbor */
f1be801998-02-22Per Hedbor constant cvs_version = "$Id: wizard_tag.pike,v 1.5 1998/02/22 18:19:06 per Exp $";
84af181997-11-14Per Hedbor constant thread_safe=1; #include <module.h> inherit "module"; inherit "wizard"; mixed *register_module() {
276a371997-11-14Per Hedbor  return ({MODULE_PARSER,"Wizard generator", ("Generates wizards<p>\n" "Syntax:<br>\n" "<br>"
f1be801998-02-22Per Hedbor "&lt;wizard [next-label=...] [previous-label=...] [ok-label=...] [cancel-label=...] [page-label=...] name=\"A Name\" cancel=\"url to go to when cancel is pressed\" done=\"url to go to when ok (or cancel, if not 'cancel' option is specified) is pressed\"&gt;<br>"
276a371997-11-14Per Hedbor "&nbsp;&nbsp;&lt;page&gt;<br>" "&nbsp;&nbsp;&nbsp;&nbsp;A page (RXML code, with two extra tags, &lt;var&gt; and &lt;cvar&gt;, see below)<br>" "&nbsp;&nbsp;&lt;/page&gt;<br>" "&nbsp;&nbsp;&lt;page&gt;<br>" "&nbsp;&nbsp;&nbsp;&nbsp;Another page...<br>" "&nbsp;&nbsp;&lt;/page&gt;<br>" "&lt;/wizard&gt;<br>" "<br>" "&lt;var <br>" "&nbsp;&nbsp; <nobr>type=\"string|password|list|text|radio|checkbox|int|float|color|font|toggle|select|select_multiple\"</nobr><br>" "&nbsp;&nbsp; name=\"var_name\"<br>" "&nbsp;&nbsp; options=\"foo,bar,gazonk\" -- (for select and select_multiple) --<br>" "&nbsp;&nbsp; default=\"default value\"<br>" "&nbsp;&nbsp; rows=num and cols=num -- (for text) --<br>" "&nbsp;&nbsp; size=chars -- (for most) --&gt;<br>" "&lt;cvar -- same as var,but the default value is the contents of the container --&gt;<br>" "&lt;/cvar&gt;<br>"),({}),1,});
84af181997-11-14Per Hedbor }
f1be801998-02-22Per Hedbor string internal_page(string t, mapping args, string contents, int l, int ol, mapping f)
84af181997-11-14Per Hedbor {
f1be801998-02-22Per Hedbor  f->pages +=({({contents,ol+l})});
84af181997-11-14Per Hedbor }
f1be801998-02-22Per Hedbor string fix_relative(string file, object id) { if(file != "" && file[0] == '/') return file; file = combine_path(dirname(id->not_query) + "/", file); return file; } string old_pike = ""; object old_wizard = 0;
84af181997-11-14Per Hedbor string tag_wizard(string t, mapping args, string contents, object id) { mapping f = ([ "pages":({}) ]); string pike = ("inherit \"wizard\";\n"
f1be801998-02-22Per Hedbor  "# "+id->misc->defines->line+" \""+id->not_query+"\"\n"
84af181997-11-14Per Hedbor  "string name=\""+(args->name||"unnamed")+"\";\n"); int p;
41d0f91998-02-20Per Hedbor  foreach(glob("*-label", indices(args)), string a) {
f1be801998-02-22Per Hedbor  pike += ("# "+id->misc->defines->line+" \""+id->not_query+"\"\n");
41d0f91998-02-20Per Hedbor  pike += " string "+replace(replace(a,"-","_"),({"(",")","+",">"}), ({"","","",""}))+ " = \""+replace(args[a], ({"\"","\n","\r", "\\"}), ({"\\\"", "\\n", "\\r", "\\\\"}))+"\";\n"; }
f1be801998-02-22Per Hedbor  if(args->ok) { pike += ("# "+id->misc->defines->line+" \""+id->not_query+"\"\n"); pike += ("mixed wizard_done(object id)\n" "{\n" " id->not_query = \""+ fix_relative(replace(args->ok, ({"\"","\n","\r", "\\"}), ({"\\\"", "\\n", "\\r", "\\\\"})),id)+"\";\n" " return roxen->get_file( id );\n" "}\n\n"); } parse_html_lines(contents, ([]), (["page":internal_page]), (int)id->misc->defines->line,f); foreach(f->pages, array q)
84af181997-11-14Per Hedbor  {
f1be801998-02-22Per Hedbor  pike += ("# "+q[1]+" \""+id->not_query+"\"\n");
84af181997-11-14Per Hedbor  pike += ("string page_"+p+"(object id) {" +
f1be801998-02-22Per Hedbor  "return \""+replace(q[0], ({"\"","\n","\r", "\\"}),
84af181997-11-14Per Hedbor  ({"\\\"", "\\n", "\\r", "\\\\"}))+"\";}\n"); p++; }
f1be801998-02-22Per Hedbor  object w; if(pike == old_pike) w = old_wizard; else { werror("compiling:\n"+pike+"\n"); old_wizard = w = compile_string(pike)(); old_pike = pike; } mixed res = w->wizard_for(id,fix_relative(args->cancel||args->done,id));
84af181997-11-14Per Hedbor  if(mappingp(res)) { id->misc->defines[" _error"] = res->error; id->misc->defines[" _extra_heads"] = res->extra_heads;
f1be801998-02-22Per Hedbor  return res->data||(res->file&&res->file->read())||"";
84af181997-11-14Per Hedbor  } return res; } mapping query_container_callers() { return ([ "wizard" : tag_wizard ]); }
b956721998-02-03Per Hedbor void start() { }