Created
August 16, 2019 11:44
Installing User Defined Functions (UDF) As An Extension For Built-In Functions (BIF) In Lucee 5.3.2.77
This file contains 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> | |
// The {lucee-server} placeholder brings us to the "context" directory for the | |
// server. But, for the deployment of extensions, we need to go up one level to find | |
// the "deploy" directory. | |
deployPath = expandPath( "{lucee-server}/../deploy/" ); | |
// To deploy our extension, we need to place our LEX file in the deploy directory. | |
lexPath = ( deployPath & "TruthyFalsy.lex" ); | |
// The cool thing is, we can Zip / Compress the local extension directory directly | |
// into the server's deploy directory in our CommandBox instance. Woot woot! | |
compress( "zip", "./extension", lexPath, false ); | |
// ------------------------------------------------------------------------------- // | |
// ------------------------------------------------------------------------------- // | |
// Since it takes some time (up to a minute according to a video I watched) for the | |
// LEX file to get installed, we need to increase the request timeout before we start | |
// monitoring the file-system for changes. | |
cfsetting( requestTimeout = ( 2 * 60 ) ); | |
echo( "Waiting for <code>.lex</code> file to be installed " ); | |
// Lucee monitors the deploy directory for changes, and then moves the new files out | |
// of the deploy directory. As such, we can use the existence of our LEX file as a | |
// way to determine when the extension has been installed in the server. | |
while ( fileExists( lexPath ) ) { | |
echo( "<strong>.</strong> " ); | |
cfflush(); | |
sleep( 500 ); | |
} | |
// ------------------------------------------------------------------------------- // | |
// ------------------------------------------------------------------------------- // | |
// At this point, the LEX file has been installed; however, it appears that the Lucee | |
// service SOMETIMES needs to be restarted (based on my testing). I am not sure why | |
// this is inconsistently required. | |
echo( "<p> The <code>.lex</code> file has been deployed. </p>" ); | |
echo( "<p> You may need to <strong>" ); | |
echo( "<a href='./restart.cfm' target='_blank'>restart the Lucee service</a>" ); | |
echo( "</strong> in order to see the changes.</p>" ); | |
</cfscript> |
This file contains 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
/extension/ | |
/extension/functions/ | |
/extension/functions/isfalsy.cfm | |
/extension/functions/istruthy.cfm | |
/extension/META-INF/ | |
/extension/META-INF/MANIFEST.MF |
This file contains 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> | |
/** | |
* I determine if the given value is a Falsy (according to JavaScript rules). | |
* | |
* See JavaScript definition on the Mozilla Developer Network (MDN): | |
* https://developer.mozilla.org/en-US/docs/Glossary/Falsy | |
* | |
* @value I am the value being tested. | |
*/ | |
public boolean function isFalsy( any value ) { | |
if ( isNull( value ) ) { | |
return( true ); | |
} | |
if ( ! isSimpleValue( value ) ) { | |
return( false ); | |
} | |
if ( isInstanceOf( value, "java.lang.String" ) ) { | |
return( ! value.len() ); | |
} | |
if ( isBoolean( value ) || isNumeric( value ) ) { | |
return( ! value ); | |
} | |
return( false ); | |
} | |
</cfscript> |
This file contains 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> | |
/** | |
* I determine if the given value is a Truthy (according to JavaScript rules). A | |
* Truthy value is any value that is not explicitly designated as a Falsy. | |
* | |
* See JavaScript definition on the Mozilla Developer Network (MDN): | |
* https://developer.mozilla.org/en-US/docs/Glossary/Truthy | |
* | |
* @value I am the value being tested. | |
*/ | |
public boolean function isTruthy( any value ) { | |
if ( isNull( value ) ) { | |
return( false ); | |
} | |
return( ! isFalsy( value ) ); | |
} | |
</cfscript> |
This file contains 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
Manifest-Version: 1.0 | |
id: "b6304293-81fa-4bcf-a6aa4bf9bd673697" | |
version: "1.0.0.0" | |
name: "TruthyFalsy" | |
description: "Decision functions based on JavaScript's notion of Truthy and Falsy values." | |
category: "Decision Logic" |
This file contains 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
<p> | |
<strong>Restarting</strong> the Lucee server context.... | |
</p> | |
<cfflush /> | |
<cfadmin | |
action = "restart" | |
type = "server" | |
password = "commandbox" | |
/> | |
<p> | |
Restart complete. | |
</p> |
This file contains 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> | |
// These should all be true. | |
echoLine( isFalsy( nullValue() ) === true ); | |
echoLine( isFalsy( false ) === true ); | |
echoLine( isFalsy( "" ) === true ); | |
echoLine( isFalsy( 0 ) === true ); | |
// These should all be false. | |
echoLine( isFalsy( 1 ) === false ); | |
echoLine( isFalsy( "0" ) === false ); | |
echoLine( isFalsy( [] ) === false ); | |
echoLine( isFalsy( {} ) === false ); | |
echoLine( isFalsy( now() ) === false ); | |
// These should all be true. | |
echoLine( isTruthy( {} ) === true ); | |
echoLine( isTruthy( [] ) === true ); | |
echoLine( isTruthy( "0" ) === true ); | |
echoLine( isTruthy( true ) === true ); | |
echoLine( isTruthy( 1 ) === true ); | |
echoLine( isTruthy( now() ) === true ); | |
// These should all be false. | |
echoLine( isTruthy( nullValue() ) === false ); | |
echoLine( isTruthy( false ) === false ); | |
echoLine( isTruthy( 0 ) === false ); | |
echoLine( isTruthy( "" ) === false ); | |
// ------------------------------------------------------------------------------- // | |
// ------------------------------------------------------------------------------- // | |
public void function echoLine( required any value ) { | |
echo( value & "<br />" ); | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment