- qpscanner/lexicon/cf/switch.cfm
- v0.7.3.2
- 1 KB
- 41
1<cfscript>
2 // example custom verb that compiles to a <cfswitch> 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:case>
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 // expression is required:
28 if (not structKeyExists(fb_.verbInfo.attributes,"expression")) {
29 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
30 "Required attribute is missing",
31 "The attribute 'expression' is required, for a 'switch' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
32 }
33 //
34 // start mode:
35 fb_appendLine('<' & 'cfswitch expression="#fb_.verbInfo.attributes.expression#">');
36 } else {
37 //
38 // end mode:
39 fb_appendLine('<' & '/cfswitch>');
40 }
41</cfscript>