1.1 --- a/docs/in-page-updates.html Mon Oct 03 23:04:48 2005 +0000
1.2 +++ b/docs/in-page-updates.html Mon Oct 03 23:05:27 2005 +0000
1.3 @@ -1,12 +1,10 @@
1.4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1.5 -<html xmlns="http://www.w3.org/1999/xhtml">
1.6 -<head>
1.7 +<html xmlns="http://www.w3.org/1999/xhtml"><head>
1.8 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" />
1.9 - <title>Creating Applications: In-Page Updates</title>
1.10 - <meta name="generator"
1.11 - content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.12 - <link href="styles.css" rel="stylesheet" type="text/css" />
1.13 -</head>
1.14 +
1.15 + <title>Creating Applications: In-Page Updates</title><meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.16 + <link href="styles.css" rel="stylesheet" type="text/css" /></head>
1.17 +
1.18 <body>
1.19 <h1>Creating Applications: In-Page Updates</h1>
1.20 <p>One fashionable avenue in Web application design has been that of
1.21 @@ -16,33 +14,26 @@
1.22 such "in-page" or "live" updates.</p>
1.23 <p>Consider the addition of a comment field to our application. Here is
1.24 how the HTML code might look:</p>
1.25 -<pre><div template:element="item"><br /> <p><br /> Some item: <input template:attribute="value" name="{template:this-attribute()}" type="text" value="{$this-value}" /><br /> <input name="remove={template:this-element()}" type="submit" value="Remove" /><br /> </p><br /> <p><br /> Item type:<br /> <select template:element="type" name="{template:list-attribute('type-enum', 'value')}" multiple="multiple"><br /> <option template:element="type-enum" template:expr="@value-is-set" template:expr-attr="selected"<br /> template:value="@value" value="{@value}" /><br /> </select><br /> </p><br /> <span
1.26 - style="font-weight: bold;"><p template:element="options"></span><br
1.27 - style="font-weight: bold;" /><span style="font-weight: bold;"> <span </span><span
1.28 - style="font-weight: bold;">template:element="comment"></span><span
1.29 - style="font-weight: bold;">Comment:</span><br
1.30 - style="font-weight: bold;" /><span style="font-weight: bold;"> <textarea template:attribute="value" name="{template:this-attribute()}" cols="40" rows="3"></span><br
1.31 - style="font-weight: bold;" /><span style="font-weight: bold;"> <span template:value="$this-value" template:effect="replace">Some comment</span></span><br
1.32 - style="font-weight: bold;" /><span style="font-weight: bold;"> </textarea><br /> </span><br
1.33 - style="font-weight: bold;" /></span><span style="font-weight: bold;"> </p></span><br /> <p><br /> Itself containing more items:<br /> </p><br /> <p template:element="subitem"><br /> Sub-item: <input template:attribute="subvalue" name="{template:this-attribute()}" type="text" value="{$this-value}" /><br /> <input name="remove2={template:this-element()}" type="submit" value="Remove" /><br /> </p><br /> <p><br /> <input name="add2={template:this-element()}" type="submit" value="Add subitem" /><br /> </p><br /></div></pre>
1.34 -<p>The newly-added <code>textarea</code> field will not be
1.35 -presented in the application in its current state; this is due to the
1.36 -lack of any <code>options</code> or <code>comment</code> elements
1.37 +<pre><div template:element="item"><br /> <p><br /> Some item: <input template:attribute-field="value" name="..." type="text" value="..." /><br /> <input name="..." template:selector-field="remove" type="submit" value="Remove" /><br /> </p><br /> <p><br /> Item type:<br /> <select template:multiple-choice-list-field="type,type-enum,value" name="..." multiple="multiple"><br /> <option template:multiple-choice-list-value="type-enum,value,selected" value="..." /><br /> </select><br /> </p><br /> <span style="font-weight: bold;"><p template:element="options"></span><br style="font-weight: bold;" /><span style="font-weight: bold;"> <span </span><span style="font-weight: bold;">template:element="comment"></span><span style="font-weight: bold;">Comment:</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> <textarea template:attribute-area="value,insert" name="..." cols="40" rows="3"></span><br style="font-weight: bold;" /><span style="font-weight: bold;"> Some comment</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> </textarea><br /> </span><br style="font-weight: bold;" /></span><span style="font-weight: bold;"> </p></span><br /> <p><br /> Itself containing more items:<br /> </p><br /> <p template:element="subitem"><br /> Sub-item: <input template:attribute-field="subvalue" name="..." type="text" value="..." /><br /> <input name="..." template:selector-field="remove2" type="submit" value="Remove" /><br /> </p><br /> <p><br /> <input name="..." template:selector-field="add2,subitem" type="submit" value="Add subitem" /><br /> </p><br /></div></pre>
1.38 +<p>Here, a <code>textarea</code> element has been added with a special <code>template:attribute-area</code> annotation being used to state that the contents of the element are to be mapped to the <code>value</code> attribute, and that the attribute contents are to be inserted inside the <code>textarea</code> element (replacing the <code>Some Comment</code> text).</p><p>The newly-added <code>textarea</code> field might actually be
1.39 +presented in the application in its current state, despite the lack of any <code>options</code> or <code>comment</code>
1.40 +elements
1.41 manipulated by the
1.42 -application, and such template changes are actually quite safe to make.
1.43 -So, we must now do some additional work to add such <code>options</code>
1.44 -and <code>comment</code>
1.45 -elements in our application.</p>
1.46 -<p>One approach is to extend our transformation which adds the
1.47 -different type values so that these new elements are
1.48 -introduced as well. In the Web resource, we can make the following
1.49 -change:</p>
1.50 -<pre> transform_resources = {<br /> "types" : ["structure_multivalue_types.xsl", "structure_comments.xsl"]<br /> }</pre>
1.51 -<p>What this does is to state that when we carry out the <code>types</code>
1.52 -transformation, two stylesheets are employed, one before the other,
1.53 -such that the type values are first added using the first stylesheet
1.54 -(and the additional reference document containing the type values) and
1.55 -that the comments are then added using the second stylesheet.</p>
1.56 +application, due to the document initialisation mechanism employed by
1.57 +the application. However, what would be more interesting is the
1.58 +possibility of only showing the comment field if something else in the
1.59 +document had a certain value or state.</p>
1.60 +<p>Let us imagine that if the type of an item was set to "Personal",
1.61 +the comment field would appear and permit the recording of some text
1.62 +for that item. One approach that would make this possible is to
1.63 +add a transformation which checks the type values set for each of the
1.64 +items and removes the <code>options</code> and <code>comment</code> elements for items which do not qualify. In the Web resource, we make the following
1.65 +changes:</p>
1.66 +<pre> transform_resources = {<br /> "comments" : ["structure_comments.xsl"]<br /> }</pre>
1.67 +<p>What this does is to state that when we carry out the <code>comments</code>
1.68 +transformation, the specified stylesheet is employed, filtering out the
1.69 +comments for non-qualifying items and preserving them for qualifying
1.70 +items.</p><p>Further down in the code, we add a transformation:</p><pre> # After the document initialisation...<br /><br /> # Add the comments.<br /><br /> comments_xsl_list = self.prepare_transform("comments")<br /> structure = self.get_result(comments_xsl_list, structure)</pre>
1.71 <p>This new stylesheet works according to the following principles:</p>
1.72 <ol>
1.73 <li>Descend into the form data structure, copying all elements,
1.74 @@ -67,9 +58,8 @@
1.75 </ol>
1.76 </li>
1.77 </ol>
1.78 -<p>Since this stylesheet is used after the type value transformation,
1.79 -we may (and even must) take advantage of the results of that
1.80 -transformation, including noting that selected values on <code>type-enum</code>
1.81 +<p>Since this stylesheet is used after the document initialisation,
1.82 +we may (and even must) take advantage of the results of that activity, including noting that selected values on <code>type-enum</code>
1.83 elements are marked with the <code>value-is-set</code> attribute.</p>
1.84 <p>The stylesheet source code can be found in <code>examples/Common/VerySimple/Resources/structure_comments.xsl</code>.</p>
1.85 <h2>Limitations and Enhancements</h2>
1.86 @@ -90,9 +80,7 @@
1.87 can be added and removed, regardless of whether such a field existed
1.88 there before. The above template code needs modifying slightly to
1.89 permit this:</p>
1.90 -<pre> <span style="font-weight: bold;"><p template:element="options" template:id="comment-node" id="{template:this-element()}"></span><br
1.91 - style="font-weight: bold;" /><span style="font-weight: bold;"> <span template:element="comment"></span>Comment:<br /> <textarea template:attribute="value" name="{template:this-attribute()}" cols="40" rows="3"><br /> <span template:value="$this-value" template:effect="replace">Some comment</span><br /> </textarea><br /> <span
1.92 - style="font-weight: bold;"></span></span><br /> </p></pre>
1.93 +<pre> <span style="font-weight: bold;"><p template:element="options" template:id="comment-node" id="{template:this-element()}"></span><br style="font-weight: bold;" /><span style="font-weight: bold;"> <span template:element="comment"></span>Comment:<br /> <textarea template:attribute-area="value,insert" name="..." cols="40" rows="3"><br /> Some comment<br /> </textarea><br /> <span style="font-weight: bold;"></span></span><br /> </p></pre>
1.94 <p>Here, we have added this region definition to the paragraph
1.95 surrounding the comment field, annotating the paragraph with the
1.96 following attributes:</p>
1.97 @@ -119,21 +107,13 @@
1.98 <p>Since we rely on JavaScript support in the browser, the following
1.99 references to scripts must also be added to the template, as shown in
1.100 the following excerpt:</p>
1.101 -<pre><head><br /> <title>Example</title><br /> <span
1.102 - style="font-weight: bold;"><script type="text/javascript" src="scripts/sarissa.js"> </script></span><br
1.103 - style="font-weight: bold;" /><span style="font-weight: bold;"> <script type="text/javascript" src="scripts/XSLForms.js"> </script></span><br /></head></pre>
1.104 +<pre><head><br /> <title>Example</title><br /> <span style="font-weight: bold;"><script type="text/javascript" src="scripts/sarissa.js"> </script></span><br style="font-weight: bold;" /><span style="font-weight: bold;"> <script type="text/javascript" src="scripts/XSLForms.js"> </script></span><br /></head></pre>
1.105 <p>These special script files can be found in <code>examples/Common/VerySimple/Resources/scripts</code>.</p>
1.106 <p>Now we can concentrate on adding the event which triggers an in-page
1.107 update. Since it is the type values that cause each comment field to be
1.108 added or removed, we add an event attribute on the form field
1.109 responsible for displaying the type values:</p>
1.110 -<pre> <p><br /> Item type:<br /> <select template:element="type" name="{template:list-attribute('type-enum', 'value')}" multiple="multiple"<br /> <span
1.111 - style="font-weight: bold;">onchange="requestUpdate(</span><br
1.112 - style="font-weight: bold;" /><span style="font-weight: bold;"> 'comments',</span><br
1.113 - style="font-weight: bold;" /><span style="font-weight: bold;"> '{template:list-attribute('type-enum', 'value')}',</span><br
1.114 - style="font-weight: bold;" /><span style="font-weight: bold;"> '{template:other-elements(../options)}',</span><br
1.115 - style="font-weight: bold;" /><span style="font-weight: bold;"> '{template:child-attribute('value', template:child-element('comment', 1, template:other-elements(../options)))}',</span><br
1.116 - style="font-weight: bold;" /><span style="font-weight: bold;"> '/structure/item/options')"</span>><br /> <option template:element="type-enum" template:expr="@value-is-set" template:expr-attr="selected"<br /> template:value="@value" value="{@value}" /><br /> </select><br /> </p></pre>
1.117 +<pre> <p><br /> Item type:<br /> <select template:multiple-choice-list-field="type,type-enum,value" name="..." multiple="multiple"<br /> <span style="font-weight: bold;">onchange="requestUpdate(</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> 'comments',</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> '{template:list-attribute('type-enum', 'value')}',</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> '{template:other-elements(../options)}',</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> '{template:child-attribute('value', template:child-element('comment', 1, template:other-elements(../options)))}',</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> '/structure/item/options')"</span>><br /> <option template:multiple-choice-list-value="type-enum,value,selected" value="..." /><br /> </select><br /> </p></pre>
1.118 <p>This complicated string calls a special update request JavaScript
1.119 function which triggers the in-page update, and it specifies the
1.120 following things:</p>
1.121 @@ -190,17 +170,10 @@
1.122 pages from our application. Some standard WebStack resources can be
1.123 used to help with this, and we add some imports at the top of our
1.124 source file:</p>
1.125 -<pre>#!/usr/bin/env python<br /><br />"A very simple example application."<br /><br />import WebStack.Generic<br />import XSLForms.Resources<br />import XSLForms.Utils<br />import os<br /><br /><span
1.126 - style="font-weight: bold;"># Site map imports.</span><br
1.127 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.128 - style="font-weight: bold;">from WebStack.Resources.ResourceMap import MapResource</span><br
1.129 - style="font-weight: bold;" /><span style="font-weight: bold;">from WebStack.Resources.Static import DirectoryResource</span></pre>
1.130 +<pre>#!/usr/bin/env python<br /><br />"A very simple example application."<br /><br />import WebStack.Generic<br />import XSLForms.Resources<br />import XSLForms.Utils<br />import os<br /><br /><span style="font-weight: bold;"># Site map imports.</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;">from WebStack.Resources.ResourceMap import MapResource</span><br style="font-weight: bold;" /><span style="font-weight: bold;">from WebStack.Resources.Static import DirectoryResource</span></pre>
1.131 <p>Then, we define the resource class as <a href="Web-resource.html">before</a>,
1.132 but with an additional attribute:</p>
1.133 -<pre># Resource classes.<br /><br />class VerySimpleResource(XSLForms.Resources.XSLFormsResource):<br /><br /> "A very simple resource providing a hierarchy of editable fields."<br /><br /> resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")<br /> encoding = "utf-8"<br /> template_resources = {<br /> "structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl")<br /> }<br /> transform_resources = {<br /> "types" : ["structure_multivalue_types.xsl", "structure_comments.xsl"]<br /> }<br /> document_resources = {<br /> "types" : "structure_types.xml"<br /> }<br /><span
1.134 - style="font-weight: bold;"> in_page_resources = {</span><br
1.135 - style="font-weight: bold;" /><span style="font-weight: bold;"> "comments" : ("structure_output_comments.xsl", "comment-node")</span><br
1.136 - style="font-weight: bold;" /><span style="font-weight: bold;"> }</span></pre>
1.137 +<pre># Resource classes.<br /><br />class VerySimpleResource(XSLForms.Resources.XSLFormsResource):<br /><br /> "A very simple resource providing a hierarchy of editable fields."<br /><br /> resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")<br /> encoding = "utf-8"<br /> template_resources = {<br /> "structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl")<br /> }<br /> init_resources = {<br /> "structure" : ("structure_multivalue_template.xhtml", "structure_input.xsl")<br /> }<br /> transform_resources = {<br /> "comments" : ["structure_comments.xsl"]<br /> }<br /> document_resources = {<br /> "types" : "structure_types.xml"<br /> }<br /><span style="font-weight: bold;"> in_page_resources = {</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> "comments" : ("structure_output_comments.xsl", "comment-node")</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> }</span></pre>
1.138 <p>This new attribute provides information about the in-page request to
1.139 retrieve comment regions of the Web form, and it consists of the
1.140 stylesheet filename that will be generated to produce the page
1.141 @@ -208,31 +181,17 @@
1.142 we defined above.</p>
1.143 <p>The <code>respond_to_form</code> method now also includes some
1.144 additional code:</p>
1.145 -<pre> def respond_to_form(self, trans, form):<br /><br /> """<br /> Respond to a request having the given transaction 'trans' and the given<br /> 'form' information.<br /> """<br /><br /> <span
1.146 - style="font-weight: bold;">in_page_resource = self.get_in_page_resource(trans)</span><br
1.147 - style="font-weight: bold;" /><span style="font-weight: bold;"> parameters = form.get_parameters()</span><br /> documents = form.get_documents()<br /></pre>
1.148 +<pre> def respond_to_form(self, trans, form):<br /><br /> """<br /> Respond to a request having the given transaction 'trans' and the given<br /> 'form' information.<br /> """<br /><br /> <span style="font-weight: bold;">in_page_resource = self.get_in_page_resource(trans)</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> parameters = form.get_parameters()</span><br /> documents = form.get_documents()<br /></pre>
1.149 <p>Here, we find out whether an in-page update is requested, along with
1.150 the raw parameters of the request, some of which will be used later on
1.151 in the method.</p>
1.152 <p>The discovery of the form data structure and the addition and
1.153 removal of elements happens as before, as does the merging of type
1.154 values and the comment field, if applicable:</p>
1.155 -<pre> # Ensure the presence of a document.<br /><br /> if documents.has_key("structure"):<br /> structure = documents["structure"]<br /> else:<br /> structure = form.new_instance("structure")<br /><br /> # Add and remove elements according to the selectors found.<br /><br /> selectors = form.get_selectors()<br /> XSLForms.Utils.remove_elements(selectors.get("remove2"))<br /> XSLForms.Utils.add_elements(selectors.get("add2"), "subitem")<br /> XSLForms.Utils.remove_elements(selectors.get("remove"))<br /> XSLForms.Utils.add_elements(selectors.get("add"), "item")<br /><br /> # Transform, adding enumerations/ranges.<br /><br /> types_xsl_list = self.prepare_transform("types")<br /> types_xml = self.prepare_document("types")<br /> structure = self.get_result(types_xsl_list, structure, references={"types" : types_xml})</pre>
1.156 +<pre> # Ensure the presence of a document.<br /><br /> if documents.has_key("structure"):<br /> structure = documents["structure"]<br /> else:<br /> structure = form.new_instance("structure")<br /><br /> # Add and remove elements according to the selectors found.<br /><br /> selectors = form.get_selectors()<br /> XSLForms.Utils.remove_elements(selectors.get("remove2"))<br /> XSLForms.Utils.add_elements(selectors.get("add2"), "subitem")<br /> XSLForms.Utils.remove_elements(selectors.get("remove"))<br /> XSLForms.Utils.add_elements(selectors.get("add"), "item")<br /><br /> # Initialise the document, adding enumerations/ranges.<br /><br /> structure_xsl = self.prepare_initialiser("structure")<br /> types_xml = self.prepare_document("types")<br /> structure = self.get_result([structure_xsl], structure, references={"type" : types_xml})<br /><br /> # Add the comments.<br /><br /> comments_xsl_list = self.prepare_transform("comments")<br /> structure = self.get_result(comments_xsl_list, structure)<br /></pre>
1.157 <p>The significant changes begin when presenting the result of the
1.158 request processing:</p>
1.159 -<pre> # Start the response.<br /><br /> trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))<br /><br /><span
1.160 - style="font-weight: bold;"> # Define the stylesheet parameters.</span><br
1.161 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.162 - style="font-weight: bold;"> stylesheet_parameters = {}</span><br
1.163 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.164 - style="font-weight: bold;"> # Ensure that an output stylesheet exists.</span><br
1.165 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.166 - style="font-weight: bold;"> if in_page_resource in self.in_page_resources.keys():</span><br
1.167 - style="font-weight: bold;" /><span style="font-weight: bold;"> trans_xsl = self.prepare_fragment("structure", in_page_resource)</span><br
1.168 - style="font-weight: bold;" /><span style="font-weight: bold;"> element_path = parameters.get("element-path", [""])[0]</span><br
1.169 - style="font-weight: bold;" /><span style="font-weight: bold;"> stylesheet_parameters["element-path"] = element_path</span><br
1.170 - style="font-weight: bold;" /><span style="font-weight: bold;"> else:</span><br
1.171 - style="font-weight: bold;" /><span style="font-weight: bold;"> trans_xsl = self.prepare_output("structure")</span></pre>
1.172 +<pre> # Start the response.<br /><br /> trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))<br /><br /><span style="font-weight: bold;"> # Define the stylesheet parameters.</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;"> stylesheet_parameters = {}</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;"> # Ensure that an output stylesheet exists.</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;"> if in_page_resource in self.in_page_resources.keys():</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> trans_xsl = self.prepare_fragment("structure", in_page_resource)</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> element_path = parameters.get("element-path", [""])[0]</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> stylesheet_parameters["element-path"] = element_path</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> else:</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> trans_xsl = self.prepare_output("structure")</span></pre>
1.173 <p>Instead of just obtaining a stylesheet for the <code>structure</code>
1.174 document, we instead check to see if an in-page update is being
1.175 requested and, if so, prepare the stylesheet representing the fragment
1.176 @@ -242,33 +201,12 @@
1.177 stylesheet when making the final Web page output.</p>
1.178 <p>Finally, we send the output to the user but employing the additional
1.179 stylesheet parameters to configure the result:</p>
1.180 -<pre><span style="font-weight: bold;" /> # Complete the response.<br /><br /> self.send_output(trans, [trans_xsl], structure<span
1.181 - style="font-weight: bold;">, stylesheet_parameters</span>)</pre>
1.182 +<pre><span style="font-weight: bold;"> # Complete the response.<br /><br /> self.send_output(trans, [trans_xsl], structure<span style="font-weight: bold;">, stylesheet_parameters</span>)</span></pre>
1.183 <p>In order to introduce the infrastructure mentioned above which
1.184 separates requests for Web pages from requests for JavaScript files, we
1.185 need to provide a more sophisticated implementation of the <code>get_site</code>
1.186 function:</p>
1.187 -<pre><span style="font-weight: bold;"># Site map initialisation.</span><br
1.188 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.189 - style="font-weight: bold;">def get_site():</span><br
1.190 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.191 - style="font-weight: bold;"> "Return a simple Web site resource."</span><br
1.192 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.193 - style="font-weight: bold;"> # Get the main resource and the directory used by the application.</span><br
1.194 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.195 - style="font-weight: bold;"> very_simple_resource = VerySimpleResource()</span><br
1.196 - style="font-weight: bold;" /><span style="font-weight: bold;"> directory = very_simple_resource.resource_dir</span><br
1.197 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.198 - style="font-weight: bold;"> # Make a simple Web site.</span><br
1.199 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.200 - style="font-weight: bold;"> resource = MapResource({</span><br
1.201 - style="font-weight: bold;" /><span style="font-weight: bold;"> # Static resources:</span><br
1.202 - style="font-weight: bold;" /><span style="font-weight: bold;"> "scripts" : DirectoryResource(os.path.join(directory, "scripts"), {"js" : "text/javascript"}),</span><br
1.203 - style="font-weight: bold;" /><span style="font-weight: bold;"> # Main page and in-page resources:</span><br
1.204 - style="font-weight: bold;" /><span style="font-weight: bold;"> None : very_simple_resource</span><br
1.205 - style="font-weight: bold;" /><span style="font-weight: bold;"> })</span><br
1.206 - style="font-weight: bold;" /><br style="font-weight: bold;" /><span
1.207 - style="font-weight: bold;"> return resource</span></pre>
1.208 +<pre><span style="font-weight: bold;"># Site map initialisation.</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;">def get_site():</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;"> "Return a simple Web site resource."</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;"> # Get the main resource and the directory used by the application.</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;"> very_simple_resource = VerySimpleResource()</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> directory = very_simple_resource.resource_dir</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;"> # Make a simple Web site.</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;"> resource = MapResource({</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> # Static resources:</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> "scripts" : DirectoryResource(os.path.join(directory, "scripts"), {"js" : "text/javascript"}),</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> # Main page and in-page resources:</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> None : very_simple_resource</span><br style="font-weight: bold;" /><span style="font-weight: bold;"> })</span><br style="font-weight: bold;" /><br style="font-weight: bold;" /><span style="font-weight: bold;"> return resource</span></pre>
1.209 <p>What this does is to create a resource for the application, as
1.210 before, but then to place the resource into a special WebStack resource
1.211 which examines the path or URL on the incoming requests and directs
1.212 @@ -285,5 +223,4 @@
1.213 script file; otherwise it gets a Web page showing either all of the
1.214 form (if a normal request is received), or a part of the form (if an
1.215 in-page request is received).</p>
1.216 -</body>
1.217 -</html>
1.218 +</body></html>
1.219 \ No newline at end of file