|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP COLDFUSION LINKS The CF Blogsphere
tag.cfc 0.1: Write Your Own Code Generator
Write your own code generator
By: Steve Bryant
Jan. 25, 2006 06:15 PM
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.
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()> The code that this code would output is the following:
<cf_sebForm formname="myform" librarypath="/lib/"> 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!
CFDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||