Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Nadel bennadel

View GitHub Profile
@bennadel
bennadel / InspectTagsACF.cfm
Last active May 16, 2021
GetBaseTagData() Works Differently In Adobe ColdFusion 2018 And Lucee CFML 5.3.7.47
View InspectTagsACF.cfm
<cfscript>
writeOutput( "<h1> Adobe ColdFusion </h1>" );
tagNames = getBaseTagList().listToArray();
// In Adobe ColdFusion, the second getBaseTagData() argument tells the runtime which
// INSTANCE of a tag to return. As such, since we have multiple tags with the same
// name, we have to keep track of how many times we've seen with a given name so that
// we can skip over those instances.
@bennadel
bennadel / test.cfm
Created May 14, 2021
Using The Elvis / Null Coalescing Operator To Loop Past Array Boundaries In Lucee CFML 5.3.7.47
View test.cfm
<cfscript>
letters = [ "A", "B", "C", "D", "E" ];
linkedLetters = letters.map(
( letter, i ) => {
return([
current: letter,
// We can use the null-coalescing operator to safely wrap around the
@bennadel
bennadel / snippet-1.html
Created May 9, 2021
Creating Page-Breaks In CFDocument Without Using CFDocumentItem In Lucee CFML 5.3.7.47
View snippet-1.html
<style type="text/css">
div.start-on-new-page {
page-break-before: always ;
}
</style>
@bennadel
bennadel / test.cfm
Created May 9, 2021
CFSaveContent Trim And Append Attributes In Lucee CFML 5.3.7.47
View test.cfm
<!---
In Lucee CFML, the CFSaveContent tag offers two additional attributes:
* trim - removes leading / trailing whitespace.
* append - adds the content to an existing variable.
--->
<cfsavecontent variable="data" trim="true">
Roses are red,
</cfsavecontent>
@bennadel
bennadel / snippet-1.cfm
Created May 8, 2021
Collecting HTML Class Name Attributes In Template Rendering In Lucee CFML 5.3.7.47
View snippet-1.cfm
<cfloop index="local.scheduleDay" array="#rc.scheduleDays#">
<li class="m-schedule__item #( scheduleDay.isActiveDeployment ? 'm-schedule__item--deployment' : '' )# #( scheduleDay.isToday ? 'm-schedule__item--today' : '' )# #( scheduleDay.isFuture ? 'm-schedule__item--future' : '' )# #( scheduleDay.isBlocked ? 'm-schedule__item--blocked' : '' )#">
<!--- truncated --->
</li>
</cfloop>
@bennadel
bennadel / snippet-1.cfm
Created May 7, 2021
Using Both SrcFile And CFDocumentItem In The Same CFDocument Tag In Lucee CFML 5.3.7.47
View snippet-1.cfm
<cfscript>
document
format = "pdf"
filename = "my-doc.pdf"
overwrite = true
{
```
<p>
@bennadel
bennadel / MyTag.cfm
Last active May 5, 2021
Validating And Documenting Complex Object Structures With CFParam In Lucee CFML 5.3.7.47
View MyTag.cfm
<cfscript>
// For safety and DOCUMENTATION (regarding which values are needed within this
// template), validate the general structure of the attributes.
param name="attributes.project" type="struct";
param name="attributes.project.id" type="numeric";
param name="attributes.project.name" type="string";
param name="attributes.project.createdAt" type="date";
param name="attributes.project.owner" type="struct";
param name="attributes.project.owner.id" type="numeric";
@bennadel
bennadel / Application-v1.cfc
Created May 3, 2021
Setting Global, Default Tag Attributes With "this.tag" In Lucee CFML 5.3.7.47
View Application-v1.cfc
component
output = false
hint = "I define the application settings and event-handlers."
{
this.name = "TestingGlobalTagAttributes";
this.applicationTimeout = createTimeSpan( 0, 0, 10, 0 );
this.sessionManagement = false;
this.tag = {};
@bennadel
bennadel / snippet-1.cfm
Created May 2, 2021
Using ColdFusion Custom Tags To Create An HTML Email DSL In Lucee CFML 5.3.7.47, Part XIV
View snippet-1.cfm
<cfscript>
/**
* I split the given base-tag list, returning the array of tag-names.
*
* @value I am the list of tags-names being split.
*/
public array function splitBaseTagList( required string value )
cachedWithin = "request"
{
@bennadel
bennadel / CsvParser.cfc
Created Apr 30, 2021
Modernizing My CSV (Comma Separated Value) Parser In Lucee CFML 5.3.7.47
View CsvParser.cfc
component
output = false
hint = "I provide methods for parsing CSV (Comma Separated Values) inputs and files."
{
this.COMMA = ",";
this.TAB = chr( 9 );
// If this delimiter is passed-in, the parser will examine a portion of the input and
// try to determine, roughly, which delimiter is being used in the data.
this.GUESS_DELIMITER = "";