Changeset 103
- Timestamp:
- 06/02/05 22:30:01 (4 years ago)
- Files:
-
- trunk/doc/dsp-reference/tags.html (modified) (2 diffs)
- trunk/dsp/DSPGrammar.d (modified) (1 diff)
- trunk/dsp/DSPProcessor.d (modified) (2 diffs)
- trunk/dsp/StandardTagLibrary.d (modified) (2 diffs)
- trunk/dsp/TagLibrary.d (modified) (2 diffs)
- trunk/dsp/servlet/DSPResponse.d (modified) (8 diffs)
- trunk/dsp/servlet/DSPServlet.d (modified) (1 diff)
- trunk/dsp/servlet/IDSPResponse.d (modified) (2 diffs)
- trunk/dsp/servlet/RuntimeTag.d (modified) (2 diffs)
- trunk/dsp/tags/Attribute.d (modified) (2 diffs)
- trunk/dsp/tags/all.d (modified) (2 diffs)
- trunk/dspconf/dsp_attribute.dsp (modified) (1 diff)
- trunk/dspconf/index.dsp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/doc/dsp-reference/tags.html
r102 r103 437 437 438 438 <h3>Syntax:</h3> 439 <pre class='syntax'><dsp:tag <i>[attributes]</i> > <i>[dsp: attribute]</i> </dsp:tag></pre>439 <pre class='syntax'><dsp:tag <i>[attributes]</i> > <i>[dsp:default]</i> </dsp:tag></pre> 440 440 <pre class='syntax'><dsp:tag <i>[attributes]</i> /></pre> 441 441 … … 443 443 <p> 444 444 <ul> 445 <li><u>file</u> - <b>( required)</b> a file to use as a servlet. May be any file within the445 <li><u>file</u> - <b>(string, required)</b> a file to use as a servlet. May be any file within the 446 446 <a href='concepts.html#app-filespace'>application's file space</a>. May also be qualified with 447 447 a <a href='concepts.html#named-servlet'>servlet name</a> if the file is a DSP servlet.</li> 448 448 449 <li><u>name</u> - the complete name of the tag that will represent this servlet. May be a complete449 <li><u>name</u> - <b>(string, required)</b> the complete name of the tag that will represent this servlet. May be a complete 450 450 XML tag name including a namespace (e.g. "x:formatter" or "dsp:resource"). If the target file 451 451 is a DSP servlet, DSP will also map every named servlet on the end of the specified name, 452 452 separated by a colon (e.g. "x:formatter:bold").</li> 453 453 454 <li><u>dependency</u> - specifies if this generates an454 <li><u>dependency</u> - <b>(string)</b> specifies if this generates an 455 455 <a href='concepts.html#dependencies'>external dependency</a> to the file indicated in 'file'. 456 456 Valid values are "true" and "false", which is the default if this attribute is not specified.</li> trunk/dsp/DSPGrammar.d
r102 r103 104 104 } 105 105 106 public static char[] resetWriter(){ 107 return writer ~ " = response.getWriter()"; 108 } 109 106 110 /* 107 111 public static char[] expressionEscape(char[] from,char[] to){ trunk/dsp/DSPProcessor.d
r102 r103 104 104 with(context){ 105 105 switch(generator.getContentMode()){ 106 case ServletGenerator.LiteralContentMode: 106 case ServletGenerator.LiteralContentMode: 107 107 // real DSP tag - attempt to deduce its type and handle it 108 108 if(name.startsWith(DSPGrammar.preamble)){ 109 109 tags.startTag(context,name[DSPGrammar.preamble.length .. $],attribs,isEmpty); 110 } 111 else if(tags.isCustomTag(name)){ 112 tags.startCustomTag(context,name,attribs,isEmpty); 110 113 } 111 114 … … 150 153 tags.endTag(context,name[DSPGrammar.preamble.length .. $],attribs,isEmpty); 151 154 } 155 else if(tags.isCustomTag(name)){ 156 tags.endCustomTag(context,name,attribs,isEmpty); 157 } 152 158 153 159 // a plain XML/HTML tag - close it up trunk/dsp/StandardTagLibrary.d
r102 r103 39 39 tags["in"] = new InCode(); 40 40 tags["code"] = new Code(); 41 tags["output"] = new Output(); 41 42 tags["page"] = new Page(); 42 43 tags["servlet"] = new Servlet(); … … 45 46 tags["capture"] = new Capture(); 46 47 tags["attribute"] = new Attribute(); 48 tags["tag"] = new Tag(); 49 tags["default"] = new Default(); 50 tags["argument"] = new Argument(); 47 51 } 48 52 } trunk/dsp/TagLibrary.d
r97 r103 32 32 private import dsp.DSPGrammar; 33 33 private import dsp.DSPTag; 34 private import dsp.Register; 34 35 private import dsp.ServletCompilationContext; 35 36 36 37 class TagLibrary{ 37 38 DSPTag[char[]] tags; 39 char[][char[]] customTags; 38 40 39 41 public this(){ … … 56 58 getTag(name).endTag(context,name,attribs,isEmpty); 57 59 } 60 61 void addCustomTag(char[] name){ 62 customTags[name] = name; 63 } 64 65 bit isCustomTag(char[] name){ 66 return !((name in customTags) is null); 67 } 68 69 public void startCustomTag(ServletCompilationContext context,char[] name,XMLAttributes attribs,bit isEmpty){ 70 with(context){ 71 generator.appendBody("response.startTag(" ~ DSPGrammar.runtimeString(name) ~ ");" ~ DSPGrammar.newline); 72 generator.appendBody(DSPGrammar.resetWriter ~ ";" ~ DSPGrammar.newline); 73 74 foreach(char[] attrName,char[] value; attribs){ 75 Register expr = generator.evaluateExpression(value); 76 generator.appendBody("response.setTagAttribute(" ~ DSPGrammar.runtimeString(attrName) ~ "," ~ expr.box() ~ ");" ~ DSPGrammar.newline); 77 expr.retire(); 78 } 79 generator.appendBody("response.endTagAttributes();" ~ DSPGrammar.newline); 80 } 81 } 82 83 public void endCustomTag(ServletCompilationContext context,char[] name,XMLAttributes attribs,bit isEmpty){ 84 context.generator.appendBody("response.endTag(request," ~ DSPGrammar.runtimeString(name) ~ "); " ~ DSPGrammar.resetWriter ~ ";" ~ DSPGrammar.newline); 85 } 58 86 } trunk/dsp/servlet/DSPResponse.d
r102 r103 31 31 private import dsp.servlet.RuntimeTag; 32 32 private import dsp.servlet.DSPServlet; 33 private import dsp.DSPException; 33 34 34 35 private import mango.servlet.ServletResponse; … … 46 47 RuntimeTag[char[]][] customTagScopeStack; 47 48 RuntimeTag[] tagStack; 49 RuntimeTag currentTagDecl; 48 50 DSPServlet servlet; 49 51 … … 100 102 101 103 char[] data = cast(char[])dspWriter.getBuffer().getContent(); 102 printf("popWriter: [%.*s]\n",data);104 debug printf("popWriter: [%.*s]\n",data); 103 105 dspWriter = oldWriter; 104 106 … … 118 120 } 119 121 120 private RuntimeTag popCurrentTag(){ 122 private void popCurrentTag(){ 123 assert(tagStack.length > 0); 121 124 tagStack.length = tagStack.length-1; 122 125 } 123 126 124 127 void startTagScope(){ 125 128 RuntimeTag[char[]] newScope; … … 136 139 } 137 140 138 RuntimeTag addTag(IDSPRequest request,char[] tagname,char[] filename){139 RuntimeTag tag ;141 void startTagDeclaration(IDSPRequest request,char[] tagname,char[] filename){ 142 RuntimeTag tag = new RuntimeTag(); 140 143 // get the appropriate servlet handle from the servlet 141 144 tag.handle = servlet.getServletHandleForFile(request,filename); 142 145 143 146 customTagScopeStack[$-1][tagname] = tag; 147 currentTagDecl = tag; 148 } 149 150 void endTagDeclaration(){ 151 currentTagDecl = null; 152 } 153 154 void setTagDefault(char[] name,Box value){ 155 if(currentTagDecl is null){ 156 throw new DSPException("cannot set a custom tag default outside of a dsp:tag declaration"); 157 } 158 currentTagDecl.attributes[name] = value; 144 159 } 145 160 146 161 void startTag(char[] tagname){ 147 162 RuntimeTag tag = findTag(tagname); 148 pushCurrentTag(tag .clone());149 150 if(! tag.isNull){163 pushCurrentTag(tag); 164 165 if(!(tag is null)){ 151 166 pushWriter(); 152 167 } … … 158 173 void setTagAttribute(char[] name,Box value){ 159 174 RuntimeTag tag = getCurrentTag(); 160 if(! tag.isNull){175 if(!(tag is null)){ 161 176 tag.attributes[name] = value; 162 177 } … … 167 182 168 183 void endTagAttributes(){ 169 if(! getCurrentTag().isNull){184 if(!(getCurrentTag() is null)){ 170 185 dspWriter.put(">"); 171 186 } … … 174 189 void endTag(IDSPRequest request,char[] tagname){ 175 190 RuntimeTag tag = getCurrentTag(); 176 if(! tag.isNull){191 if(!(tag is null)){ 177 192 DSPAttributes attributes = request.attributes; 178 193 char[] content = request.content; trunk/dsp/servlet/DSPServlet.d
r102 r103 278 278 279 279 if(path.getExtension() == "dsp"){ 280 return &((new LibraryDynamicHandle(this,path, request.getPathInfo)).handle);280 return &((new LibraryDynamicHandle(this,path,path.toString())).handle); 281 281 } 282 282 trunk/dsp/servlet/IDSPResponse.d
r99 r103 26 26 module dsp.servlet.IDSPResponse; 27 27 28 private import dsp.servlet.RuntimeTag;29 28 private import dsp.servlet.IDSPRequest; 30 29 private import dsp.servlet.DSPServlet; … … 51 50 void endTagScope(); 52 51 53 RuntimeTag addTag(IDSPRequest request,char[] tagname,char[] filename); 52 void startTagDeclaration(IDSPRequest request,char[] tagname,char[] filename); 53 void endTagDeclaration(); 54 void setTagDefault(char[] name,Box value); 55 54 56 void startTag(char[] tagname); 55 57 void setTagAttribute(char[] name,Box value); trunk/dsp/servlet/RuntimeTag.d
r99 r103 29 29 private import dsp.servlet.ServiceHandle; 30 30 31 structRuntimeTag{32 DSPAttributes attributes;33 ServiceHandleDelegate handle;31 class RuntimeTag{ 32 public DSPAttributes attributes; 33 public ServiceHandleDelegate handle; 34 34 35 35 RuntimeTag clone(){ … … 40 40 return tag; 41 41 } 42 43 bit isNull(){44 return handle is null;45 }46 42 } trunk/dsp/tags/Attribute.d
r102 r103 51 51 if(varname == null){ 52 52 //TODO: verify that 'name' is a valid name 53 generator.appendBody(type ~ " " ~ name ~ " = unbox!(" ~ type ~ ")(get(request.attributes, `" ~ name ~ "`," ~ value.box() ~ "));" ~ DSPGrammar.newline);53 generator.appendBody(type ~ " " ~ name ~ " = unbox!(" ~ type ~ ")(get(request.attributes," ~ DSPGrammar.runtimeString(name) ~ "," ~ value.box() ~ "));" ~ DSPGrammar.newline); 54 54 } 55 55 else{ 56 generator.appendBody(varname ~ " = unbox!(" ~ type ~ ")(get(request.attributes, `" ~ name ~ "`," ~ value.box() ~ "));" ~ DSPGrammar.newline);56 generator.appendBody(varname ~ " = unbox!(" ~ type ~ ")(get(request.attributes," ~ DSPGrammar.runtimeString(name) ~ "," ~ value.box() ~ "));" ~ DSPGrammar.newline); 57 57 } 58 58 … … 80 80 if(varname == null){ 81 81 //TODO: verify that 'name' is a valid name 82 generator.appendBody(type ~ " " ~ name ~ "= unbox!(" ~ type ~ ")(get(request.attributes, `" ~ name ~ "`,response.popWriter());" ~ DSPGrammar.newline);82 generator.appendBody(type ~ " " ~ name ~ "= unbox!(" ~ type ~ ")(get(request.attributes," ~ DSPGrammar.runtimeString(name) ~ ",box(response.popWriter()));" ~ DSPGrammar.newline); 83 83 } 84 84 else{ 85 generator.appendBody(varname ~ " = unbox!(" ~ type ~ ")(get(request.attributes, `" ~ name ~ "`,response.popWriter());" ~ DSPGrammar.newline);85 generator.appendBody(varname ~ " = unbox!(" ~ type ~ ")(get(request.attributes," ~ DSPGrammar.runtimeString(name) ~ ",box(response.popWriter()));" ~ DSPGrammar.newline); 86 86 } 87 87 trunk/dsp/tags/all.d
r102 r103 29 29 import dsp.tags.InCode; 30 30 import dsp.tags.OutCode; 31 import dsp.tags.Output; 31 32 import dsp.tags.Page; 32 33 import dsp.tags.Servlet; … … 35 36 import dsp.tags.Capture; 36 37 import dsp.tags.Attribute; 38 import dsp.tags.Tag; 39 import dsp.tags.Default; 40 import dsp.tags.Argument; trunk/dspconf/dsp_attribute.dsp
r102 r103 7 7 8 8 <dsp:attribute name='test1' value='nothing' /> 9 9 10 <!--dsp:attribute name='test2' value='123' type='int'/--> 10 11 11 12 <p>test1: <b>'#test1#'</b></p> 12 13 <!--p>test2: <b>'#test2#'</b></p--> 13 14 <p> 15 <?dsp 16 if(request.attributes is null){ 17 response.getWriter << "No Attributes"; 18 } 19 else if(request.attributes.length == 0){ 20 response.getWriter << "Empty Attributes"; 21 } 22 else{ 23 response.getWriter << request.attributes.length << " total attributes <br />"; 24 foreach(char[] name,Box value; request.attributes){ 25 if(value.data != null) 26 response.getWriter << name << "=" << unbox!(char[])(value) << "<br />"; 27 } 28 } 29 ?> 30 </p> 14 31 </body> 15 32 </html> trunk/dspconf/index.dsp
r102 r103 9 9 <li><a href='dsp_capture.dsp'>dsp:capture</a></li> 10 10 <li><a href='dsp_attribute.dsp'>dsp:attribute</a></li> 11 <li><a href='dsp_tag.dsp'>dsp:tag</a></li> 12 <li><a href='dsp_default.dsp'>dsp:default</a></li> 13 <li><a href='dsp_argument.dsp'>dsp:argument</a></li> 14 <li><a href='custom_tag.dsp'>Custom Tag</a></li> 11 15 </ul> 12 16 </body>
