Changeset 103

Show
Ignore:
Timestamp:
06/02/05 22:30:01 (4 years ago)
Author:
pragma
Message:

6/02/05
- added dsp:output
- added dsp:tag
- added dsp:argument
- added dsp:default
- added custom tag support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/doc/dsp-reference/tags.html

    r102 r103  
    437437 
    438438        <h3>Syntax:</h3> 
    439         <pre class='syntax'>&lt;dsp:tag <i>[attributes]</i> &gt; <i>[dsp:attribute]</i> &lt;/dsp:tag&gt;</pre> 
     439        <pre class='syntax'>&lt;dsp:tag <i>[attributes]</i> &gt; <i>[dsp:default]</i> &lt;/dsp:tag&gt;</pre> 
    440440        <pre class='syntax'>&lt;dsp:tag <i>[attributes]</i> /&gt;</pre> 
    441441 
     
    443443        <p> 
    444444            <ul> 
    445                 <li><u>file</u> - <b>(required)</b> a file to use as a servlet. May be any file within the 
     445                <li><u>file</u> - <b>(string, required)</b> a file to use as a servlet. May be any file within the 
    446446                <a href='concepts.html#app-filespace'>application's file space</a>.  May also be qualified with 
    447447                a <a href='concepts.html#named-servlet'>servlet name</a> if the file is a DSP servlet.</li> 
    448448 
    449                 <li><u>name</u> - the complete name of the tag that will represent this servlet.  May be a complete 
     449                <li><u>name</u> - <b>(string, required)</b> the complete name of the tag that will represent this servlet.  May be a complete 
    450450                XML tag name including a namespace (e.g. "x:formatter" or "dsp:resource").  If the target file 
    451451                is a DSP servlet, DSP will also map every named servlet on the end of the specified name, 
    452452                separated by a colon (e.g. "x:formatter:bold").</li> 
    453453 
    454                 <li><u>dependency</u> - specifies if this generates an 
     454                <li><u>dependency</u> - <b>(string)</b> specifies if this generates an 
    455455                <a href='concepts.html#dependencies'>external dependency</a> to the file indicated in 'file'. 
    456456                Valid values are "true" and "false", which is the default if this attribute is not specified.</li> 
  • trunk/dsp/DSPGrammar.d

    r102 r103  
    104104    } 
    105105     
     106    public static char[] resetWriter(){ 
     107        return writer ~ " = response.getWriter()"; 
     108    }    
     109     
    106110    /* 
    107111    public static char[] expressionEscape(char[] from,char[] to){ 
  • trunk/dsp/DSPProcessor.d

    r102 r103  
    104104        with(context){ 
    105105            switch(generator.getContentMode()){ 
    106             case ServletGenerator.LiteralContentMode: 
     106            case ServletGenerator.LiteralContentMode:   
    107107                // real DSP tag - attempt to deduce its type and handle it 
    108108                if(name.startsWith(DSPGrammar.preamble)){ 
    109109                    tags.startTag(context,name[DSPGrammar.preamble.length .. $],attribs,isEmpty); 
     110                } 
     111                else if(tags.isCustomTag(name)){ 
     112                    tags.startCustomTag(context,name,attribs,isEmpty); 
    110113                } 
    111114 
     
    150153                tags.endTag(context,name[DSPGrammar.preamble.length .. $],attribs,isEmpty); 
    151154            } 
     155            else if(tags.isCustomTag(name)){ 
     156                tags.endCustomTag(context,name,attribs,isEmpty); 
     157            }            
    152158 
    153159            // a plain XML/HTML tag - close it up 
  • trunk/dsp/StandardTagLibrary.d

    r102 r103  
    3939        tags["in"] = new InCode(); 
    4040        tags["code"] = new Code();   
     41        tags["output"] = new Output(); 
    4142        tags["page"] = new Page(); 
    4243        tags["servlet"] = new Servlet(); 
     
    4546        tags["capture"] = new Capture(); 
    4647        tags["attribute"] = new Attribute(); 
     48        tags["tag"] = new Tag(); 
     49        tags["default"] = new Default(); 
     50        tags["argument"] = new Argument(); 
    4751    } 
    4852} 
  • trunk/dsp/TagLibrary.d

    r97 r103  
    3232private import dsp.DSPGrammar; 
    3333private import dsp.DSPTag; 
     34private import dsp.Register; 
    3435private import dsp.ServletCompilationContext; 
    3536 
    3637class TagLibrary{ 
    3738    DSPTag[char[]] tags; 
     39    char[][char[]] customTags; 
    3840     
    3941    public this(){ 
     
    5658        getTag(name).endTag(context,name,attribs,isEmpty); 
    5759    } 
     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    }    
    5886} 
  • trunk/dsp/servlet/DSPResponse.d

    r102 r103  
    3131private import dsp.servlet.RuntimeTag; 
    3232private import dsp.servlet.DSPServlet; 
     33private import dsp.DSPException; 
    3334 
    3435private import mango.servlet.ServletResponse; 
     
    4647    RuntimeTag[char[]][] customTagScopeStack; 
    4748    RuntimeTag[] tagStack; 
     49    RuntimeTag currentTagDecl; 
    4850    DSPServlet servlet; 
    4951     
     
    100102         
    101103        char[] data = cast(char[])dspWriter.getBuffer().getContent(); 
    102         printf("popWriter: [%.*s]\n",data); 
     104        debug printf("popWriter: [%.*s]\n",data); 
    103105        dspWriter = oldWriter; 
    104106         
     
    118120    } 
    119121     
    120     private RuntimeTag popCurrentTag(){ 
     122    private void popCurrentTag(){ 
     123        assert(tagStack.length > 0); 
    121124        tagStack.length = tagStack.length-1; 
    122125    } 
    123      
     126        
    124127    void startTagScope(){ 
    125128        RuntimeTag[char[]] newScope; 
     
    136139    } 
    137140     
    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()
    140143        // get the appropriate servlet handle from the servlet 
    141144        tag.handle = servlet.getServletHandleForFile(request,filename); 
    142145         
    143146        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; 
    144159    } 
    145160         
    146161    void startTag(char[] tagname){ 
    147162        RuntimeTag tag = findTag(tagname); 
    148         pushCurrentTag(tag.clone()); 
    149          
    150         if(!tag.isNull){ 
     163        pushCurrentTag(tag); 
     164         
     165        if(!(tag is null)){ 
    151166            pushWriter(); 
    152167        } 
     
    158173    void setTagAttribute(char[] name,Box value){ 
    159174        RuntimeTag tag = getCurrentTag(); 
    160         if(!tag.isNull){ 
     175        if(!(tag is null)){ 
    161176            tag.attributes[name] = value; 
    162177        } 
     
    167182     
    168183    void endTagAttributes(){ 
    169         if(!getCurrentTag().isNull){ 
     184        if(!(getCurrentTag() is null)){ 
    170185            dspWriter.put(">"); 
    171186        } 
     
    174189    void endTag(IDSPRequest request,char[] tagname){ 
    175190        RuntimeTag tag = getCurrentTag(); 
    176         if(!tag.isNull){ 
     191        if(!(tag is null)){ 
    177192            DSPAttributes attributes = request.attributes; 
    178193            char[] content = request.content; 
  • trunk/dsp/servlet/DSPServlet.d

    r102 r103  
    278278         
    279279        if(path.getExtension() == "dsp"){ 
    280             return &((new LibraryDynamicHandle(this,path,request.getPathInfo)).handle); 
     280            return &((new LibraryDynamicHandle(this,path,path.toString())).handle); 
    281281        } 
    282282         
  • trunk/dsp/servlet/IDSPResponse.d

    r99 r103  
    2626module dsp.servlet.IDSPResponse; 
    2727 
    28 private import dsp.servlet.RuntimeTag; 
    2928private import dsp.servlet.IDSPRequest; 
    3029private import dsp.servlet.DSPServlet; 
     
    5150    void endTagScope(); 
    5251     
    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     
    5456    void startTag(char[] tagname); 
    5557    void setTagAttribute(char[] name,Box value); 
  • trunk/dsp/servlet/RuntimeTag.d

    r99 r103  
    2929private import dsp.servlet.ServiceHandle; 
    3030 
    31 struct RuntimeTag{ 
    32     DSPAttributes attributes; 
    33     ServiceHandleDelegate handle; 
     31class RuntimeTag{ 
     32    public DSPAttributes attributes; 
     33    public ServiceHandleDelegate handle; 
    3434     
    3535    RuntimeTag clone(){ 
     
    4040        return tag; 
    4141    } 
    42      
    43     bit isNull(){ 
    44         return handle is null; 
    45     } 
    4642} 
  • trunk/dsp/tags/Attribute.d

    r102 r103  
    5151                if(varname == null){ 
    5252                    //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); 
    5454                } 
    5555                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); 
    5757                } 
    5858                 
     
    8080                if(varname == null){ 
    8181                    //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); 
    8383                } 
    8484                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); 
    8686                } 
    8787                 
  • trunk/dsp/tags/all.d

    r102 r103  
    2929import dsp.tags.InCode; 
    3030import dsp.tags.OutCode; 
     31import dsp.tags.Output; 
    3132import dsp.tags.Page; 
    3233import dsp.tags.Servlet; 
     
    3536import dsp.tags.Capture; 
    3637import dsp.tags.Attribute; 
     38import dsp.tags.Tag; 
     39import dsp.tags.Default; 
     40import dsp.tags.Argument; 
  • trunk/dspconf/dsp_attribute.dsp

    r102 r103  
    77     
    88    <dsp:attribute name='test1' value='nothing' /> 
     9     
    910    <!--dsp:attribute name='test2' value='123' type='int'/--> 
    1011     
    1112    <p>test1: <b>'#test1#'</b></p> 
    1213    <!--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> 
    1431</body> 
    1532</html> 
  • trunk/dspconf/index.dsp

    r102 r103  
    99        <li><a href='dsp_capture.dsp'>dsp:capture</a></li> 
    1010        <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> 
    1115    </ul> 
    1216</body>