root / framework / trunk / extensions / lexicon / cf / defaultcase.cfm

Revision 122, 1.4 kB (checked in by scorfield, 3 years ago)

Addresses #19 by adding try/catch, switch/case/defaultcase and updating the skeleton code to use them.

Line 
1<cfscript>
2        // example custom verb that compiles to a <cfdefaultcase> tag
3        // usage:
4        // 1. add the lexicon declaration to your circuit file:
5        //    <circuit xmlns:cf="cf/">
6        // 2. use the verb in a fuseaction:
7        //    <cf:switch expression="#someExpr#">
8        //    <cf:case value="someValue">
9        //        ... some code ...
10        //    </cf:catch>
11        //    <cf:case value="anotherValue|andAnother" delimiters="|">
12        //        ... more code ...
13        //    </cf:case>
14        //    <cf:defaultcase>
15        //        ... default code ...
16        //    </cf:defaultcase>
17        //    </cf:switch>
18        //
19        // how this works:
20        // a. validate the attributes passed in (fb_.verbInfo.attributes)
21        // b. in start mode, generate the required CFML
22        // c. in end mode, generate the required CFML
23        //
24        if (fb_.verbInfo.executionMode is "start") {
25                //
26                // validate attributes:
27                // parent tag must be a switch verb in the same lexicon:
28                if (not structKeyExists(fb_.verbInfo,"parent") or
29                                fb_.verbInfo.parent.lexicon is not fb_.verbInfo.lexicon or
30                                fb_.verbInfo.parent.lexiconVerb is not "switch") {
31                        fb_throw("fusebox.badGrammar.invalidNesting",
32                                                "Verb is invalid in this context",
33                                                "The verb 'defaultcase' does not appear directly nested within a 'switch' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
34                }
35                //
36                // start mode:
37                fb_appendLine('<' & 'cfdefaultcase>');
38        } else {
39                //
40                // end mode:
41                fb_appendLine('<' & '/cfdefaultcase>');
42        }
43</cfscript>
Note: See TracBrowser for help on using the browser.