Skip to content

Instantly share code, notes, and snippets.

@roryl
Last active May 3, 2016 13:29
Show Gist options
  • Save roryl/95f6bd166627abb425a4 to your computer and use it in GitHub Desktop.
Save roryl/95f6bd166627abb425a4 to your computer and use it in GitHub Desktop.
Lucee Dynamic Evaluation
component {
this.mappings["/temp"] = "ram://";
}
<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>
<cfscript>
time = evaluate(de("the time is #now()#"));
writeDump(time);
</cfscript>
<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>
<cfscript>
myVar = "test";
myStruct = {test:"foo", test2:"bar"}
echo(myStruct[myVar]); //outputs "foo"
echo(myStruct["test2"]); //outputs "bar"
</cfscript>
<cfscript>
myVar = "test";
"#myVar#" = "foo"; //set test = "foo" by evaluating myVar
echo(test); //outputs foo
</cfscript>
/**
* 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");
}
}
<cfscript>
myVar = "test";
evaluate("#myVar# = 'foo'"); //set test = "foo" by evaluating myVar
echo(test); //outputs foo
</cfscript>
<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