Last active
May 3, 2016 13:29
-
-
Save roryl/95f6bd166627abb425a4 to your computer and use it in GitHub Desktop.
Lucee Dynamic Evaluation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
this.mappings["/temp"] = "ram://"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
function add(one, two, three){ | |
return arguments.one + arguments.two + arguments.three; | |
} | |
//Can be an array which will resolve positionally | |
args = [ | |
"5", | |
"10", | |
"2" | |
]; | |
result = add(argumentCollection=args); | |
echo(result); | |
echo("<br />"); | |
//Can also use a struct, which will resolve to named arguments | |
args = { | |
"one":"5", | |
"two":"10", | |
"three":"2" | |
}; | |
result = add(argumentCollection=args); | |
echo(result); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
time = evaluate(de("the time is #now()#")); | |
writeDump(time); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
iterations = 10; | |
savecontent variable = "template" { | |
echo("<cfoutput>") | |
for(i=1; i <= iterations; i++){ | |
echo("The Time is ##now()## <br />"); | |
echo("<cfset sleep(50)>") | |
} | |
echo("</cfoutput>"); | |
} | |
fileId = "#createUUID()#.cfm"; | |
fileWrite("ram://#fileId#", template); | |
// writeDump(template); | |
</cfscript> | |
<cfinclude template="/temp/#fileid#" /> | |
<pre> | |
<cfoutput> | |
#template# | |
</cfoutput> | |
</pre> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myVar = "test"; | |
myStruct = {test:"foo", test2:"bar"} | |
echo(myStruct[myVar]); //outputs "foo" | |
echo(myStruct["test2"]); //outputs "bar" | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myVar = "test"; | |
"#myVar#" = "foo"; //set test = "foo" by evaluating myVar | |
echo(test); //outputs foo | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* My xUnit Test | |
*/ | |
component extends="testbox.system.BaseSpec"{ | |
/*********************************** LIFE CYCLE Methods ***********************************/ | |
// executes before all test cases | |
function beforeTests(){ | |
} | |
// executes after all test cases | |
function afterTests(){ | |
} | |
// executes before every test case | |
function setup( currentMethod ){ | |
} | |
// executes after every test case | |
function teardown( currentMethod ){ | |
} | |
/*********************************** TEST CASES BELOW ***********************************/ | |
function checkAllSyntaxTest(){ | |
var files = directoryList(""); | |
for(file IN files){ | |
if(!file CONTAINS ".cfc"){ | |
include template="#getFileFromPath(file)#"; | |
} | |
} | |
} | |
function dynamicVariableTest(){ | |
savecontent variable="myContent" { | |
include template="dynamic_variable.cfm"; | |
} | |
expect(myContent).toBe("foo"); | |
} | |
function evaluateTest(){ | |
savecontent variable="myContent" { | |
include template="evaluate.cfm"; | |
} | |
expect(myContent).toBe("foo"); | |
} | |
function dynamicStructTest(){ | |
savecontent variable="myContent" { | |
include template="dynamic_struct_keys.cfm"; | |
} | |
expect(myContent).toBe("foobar"); | |
} | |
function getVariableTest(){ | |
savecontent variable="myContent" { | |
include template="get_variable.cfm"; | |
} | |
expect(myContent).toBe("test"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myVar = "test"; | |
evaluate("#myVar# = 'foo'"); //set test = "foo" by evaluating myVar | |
echo(test); //outputs foo | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myVar = "test"; | |
echo(getVariable("myVar")); //outputs test | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment