YOUR FEEDBACK
More on the Software Assembly Question - Do Design Patterns Help?
Yanic wrote: Hi, > UML and MDA are being changed to be more data and doc...
SOA World Conference
Virtualization Conference
$50 Savings Expire May 23, 2008... – Register Today!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP COLDFUSION LINKS


tag.cfc 0.1: Write Your Own Code Generator
Write your own code generator

Digg This!

Back when I had some free time, I started working on my own code generator, partly because other code generators create code slightly different from my preferences and partly for the challenge.

I have since gotten too busy to finish it, but I went ahead and finished the kernel component of the system - the one that actually generates the code. To download the component go to www.bryantwebconsulting.com/cfcs.

One advantage of ColdFusion being a tag-based language is that generating code for ColdFusion largely means writing tags.

The best way that I can think to show how tag.cfc works is by example. cf_sebForm.cfc and cf_sebField.cfc are both components that are inherited from tag.cfc. They are each used to generate the code for my cf_sebForm and cf_sebField custom tags.

These components are actually very simple. They extend tag.cfc and each have two methods: vtml() and schema(), which return the VTML for the tag and the XML Schema for the tag, respectively.

Here is some example code using these components to output the code needed for these custom tags:

<cfset sebForm = CreateObject("component","cf_sebForm").init()>
<cfset fields = ArrayNew(1)>

<cfset sebForm.setAttribute("formname","myform")>
<cfset sebForm.setAttribute("librarypath","/lib/")>

<cfset fields[1] = CreateObject("component","cf_sebField").init()>
<cfset fields[1].setAttribute("fieldname","blah")>
<cfset fields[1].setAttribute("label","Hello")>
<cfset fields[1].setAttribute("type","text")>
<cfset fields[2] = CreateObject("component","cf_sebField").init()>
<cfset fields[2].setAttribute("label","Submit")>
<cfset fields[2].setAttribute("type","submit")>
<cfset sebForm.addTag(fields[1])>
<cfset sebForm.addTag(fields[2])>
<cfoutput>
<pre>#HTMLEditFormat(sebForm.write())#</pre>
</cfoutput>

The code that this code would output is the following:

<cf_sebForm formname="myform" librarypath="/lib/">
    <cf_sebField fieldname="blah" type="text" label="Hello" />
    <cf_sebField type="submit" label="Submit" />
</cf_sebForm>

In order for the previous code to be useful, of course, you wouldn't want the values to be hard-coded. You would need to get those values from a form or from data in a database, for example. While tag.cfc doesn't handle that part for you, it will handle most of the last step of code generation once you have gathered that information.

Incidentally, when I was working on my own code generator (a task I hope to return to someday), I used my DataMgr component to get the structure of the database. Since it works the same across multiple databases, it makes for a nice cross-database solution.

You can download tag.cfc from my site. I also have two sets of tag CFCs that inherit from tag.cfc. The first, "CFCs", includes components to generate cfcomponent,cffunction and cfargument. The second, "sebtags", is a set of CFCs used to generate my custom tags.

This code illustrates my best understanding of good OO code, so it should be a good example of such. That being said, if someone can show why it isn't a good example of such, let me know.

Good luck!

About Steve Bryant
Steve Bryant is the founder and CEO of Bryant Web Consulting LLC (www.bryantwebconsulting.com) and teaches ColdFusion at Breakaway Interactive (www.breakawayinteractive.com). He got his BA in philosophy at Oklahoma State University. Steve, one of the top ColdFusion developers in the country, still has no idea how that led to a career in Web development. Steve blogs at steve.coldfusionjournal.com as one of CFDJ's published bloggers.

SYS-CON Italy News Desk wrote: Back when I had some free time, I started working on my own code generator, partly because other code generators create code slightly different from my preferences and partly for the challenge.
read & respond »
SYS-CON India News Desk wrote: Back when I had some free time, I started working on my own code generator, partly because other code generators create code slightly different from my preferences and partly for the challenge.
read & respond »
CFDJ LATEST STORIES . . .
AJAX World – Personal Branding Checklist
This is a checklist of items you need for an all-encompassing personal branding strategy. Personal branding is the process of marketing and selling yourself as a brand in order to gain success in business. Personal branding is a continual process just as knowing yourself is a continual
3rd International Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
What Is ColdFusion in the Age of Java?
As CFML developers start to learn Java and move into the realm of Spring and Hibernate, it is very important to stop and ask 'What Is ColdFusion?'. ColdFusion, since CFMX, has been a J2EE application running within a J2EE server (JRun, JBoss, Tomcat, Websphere, etc.). This is important
Opinion: Give ColdFusion Some Room to Breathe
My personal approach has become to to let ColdFusion do what it does best, and no more. No AJAX generation or any of that silly UI stuff. Leave that to the AJAX frameworks, or Flex, or whatever your UI is going to be on the front-end. That's what the UI tool was designed for, CF wasn't
Viewpoint: Not Every ColdFusion Developer Should Be A Flex Developer
I am going to go ahead and contend that although a good number of ColdFusion developers can grasp and understand Flex very well, there are also a good number of ColdFusion developers who have no business going anywhere near Flex. Why do I say this? I am a big fan of Flex. I use it dail
JavaOne 2008: Sun Talks Up its Late-to-the-Party AIR-Silverlight Rival
At Java One this week Sun has been selling its year -old-but-still-upcoming - and definitely late-to-the-party - Adobe AIR- and Microsoft Silverlight-competitive JavaFX Rich Client environment as a potential revenue-generator capable of putting ads on mobile applications and JavaFX Scri
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE