By Peter Bell

Illudium and CFML templating

Kyle Hayes just pointed out that Brian Rinaldi has just added CFML support for templating in his Illudium generator. It will be interesting to see if this feature ends up being used - I certainly think it is a great idea and am glad Brian took the time to give this a try.

On a connected note, Brian uses <% for his generation time tags, and I think I like that better than the < < in CF template, so I'm going to change the default characters in CF template to Brians syntax - thanks Brian!

Comments
This is definitely great news! Im going to be updating my public Fusebox templates to this format as well. Im moving this weekend but hopefully sometime next week I can get them out the door.
# Posted By Russ Johnson | 6/29/07 5:45 PM
Thanks for pointing that out Peter. Hmmmm... gives me a thought or too.
# Posted By Terrence P Ryan | 6/30/07 11:35 PM
@Russ, Cool - let me know how that goes.

@Terrence, well if you like it you could always include CF Template (or just the idea like Brian did) in Squidhead!
# Posted By Peter Bell | 7/1/07 9:58 AM
Hi Peter, just hijacking this thread to let people know that they can see the generator in action this Thursday 5th July via a http://cfFrameworks.com workshop. Hope you don't mind.
# Posted By Nick Tong | 7/1/07 10:51 AM
@Nick,

Not in the slightest. Please everyone check out the presentation by Brian - it should be great!
# Posted By Peter Bell | 7/1/07 9:00 PM
Peter, if you don't have a problem with that, It's exacly what I would love to do.
# Posted By Terrence P Ryan | 7/1/07 9:41 PM
Out of curiosity, why the preference for "<%" over "<<" ?

I like the << as it is quicker to type. Of course, it just takes getting used to the other way, but I was wondering if the reasoning is because Ruby on Rails, JSPs, and others have gone the <% way?

If so, if you tried to use this in those environments, would that potentially cause any trouble?
# Posted By Sammy Larbi | 7/4/07 2:14 PM
I also preferred << as it was quicker to type. Brian preferred <% and I was open to that as an approach especially because of the similarity with other templating languages, but of course, you raise a really good point - I might be better to chose tokens that are NOT used by other mainstream languages so I can easily gen Ruby, etc.

Any suggestions? << and >> works well for tags. What about variables? Right now I'm using %, but that requires you to escape all percentages, so <% would have to be written as <%% which is no fun. Any thoughts? Don't want to use $ as that'd make PHP hard, deployment languages would be CF, Ruby, and possibly PHP, C# with ASP.NET and/or Java. I *might* have to go to a 2 character variable token.

Any thoughts or inputs appreciated!
# Posted By Peter Bell | 7/5/07 11:57 AM
I've actually been using <%VAR%> since version 6 and it's worked really well. If your thinking about quick key taps what about <.VAR.>
# Posted By Nick Tong | 7/5/07 12:20 PM
Well, The only nice thing about << is that I think it's harder to find anything faster than a double tap on the same key without having to change shift preferences, and as he notes, generating some stuff (I think some Ruby templating and from what I can remember ASP.NET as well) would not work with <% as generation time tokens as they use those for runtime purposes.

Of course, no biggie for CF only, but am trying to have something more general for my own use. Big issue I have is what token to use for variables now. I am using % which works fine until you start generating ASP.NET but then it is a pain. Any thoughts?
# Posted By Peter Bell | 7/5/07 12:25 PM
Well, I haven't seen /exactly/ what's going on, so it may not even be an issue. If can't think of anything that uses double angled brackets, but <% may not be so bad if you are building a language agnostic system in language X that can target language X, Y, or Z, you know what they meant and you just convert it accordingly - you just need to be sure you're not using tokens from language X.

But if they are allowed to use target language constructs, that is when it gets tricky I would think.

(Off the top of my head, as often is the case)
# Posted By Sammy Larbi | 7/5/07 12:30 PM
Here is the use case. I want my templating language to be able to gen to n-languages including CF, ASP.NET, Java, Ruby and PHP. I need unique tokens for identifying tags and variables in the templating language that aren't in any of the source languages.

Simple example, can't use <> for tags as used by cf. <<>> works fine.

Can't use #VarName# or $VarName for vars as used by CF and PHP respectively. Trying to figure out what to use. % was OK for CF, but I don't think it'll work out for ASP.NET (it would, but only if they escaped the token in the ASP.NET code which makes that code less readable).

My backup is a dual token - something like %%, but I'd rather have a single character that just isn't used very often as a token in templating or scripting languages but that is still fairly easy to find on a keyboard. Any thoughts?
# Posted By Peter Bell | 7/5/07 12:37 PM
I thought ASP.NET forced you into <%=varName%> ... but that could be JSP (or both) and Ruby on Rails does the same I think.

But I was thinking if the generator is in CF, then you should be able to take %varName% and convert it at generation time to the specific platform. That is what I meant when I thought there may be no issue.

Given what you just said, I'm having trouble finding it now.
# Posted By Sammy Larbi | 7/5/07 12:43 PM
The problem is that your template may need to have runtime variables as well, so they need to be within the template. Let's say I want to generate the following (simplified - it won't run and is very hackable) CF code:

<cfquery name="GetUser">
SELECT FirstName,LastName
FROM tbl_User
WHERE UserID = #form.UserID#
</cfquery>

I might have gen time variables to generate this for each business object, so I might have a template like:

<cfquery name="Get%ObjectName%">
SELECT %PropertyNameList%
FROM %TableName%
WHERE %IDPropertyName% = #form.%IDPropertyName%#
</cfquery>

Workflow of CF Template:
Transform %% (escaped %) into unique string so don't process it
Transform << >> and % into unique strings
Transform < > and # into something innocuous
Transform whatever I turned << >> and % into < > and #
Save to file, and process
Turn whatever I turned < > and # into back into those.
Turn whatever I turned %% into back into a single %

This works fine for CF, but if I had a token in the target language, I'd have to escape it everywhere so <% form.UserID %> would have to be <%% form.UserID %%> otherwise it'd turn the % into #, process it and get a generation time error. Escaping token in target language would be harder for developers to read, so I'm looking for a token for my generation time variables that is seldom found as a token or as part of a token in the target language.
Make sense?
# Posted By Peter Bell | 7/5/07 1:14 PM
Duhhh... !! (on my part)

I was thinking more generic, where you have your own templating language that would convert to any language. I guess I let my imagination go wild. =)

Point taken.

In that case, what about surrounding with colons? Ruby uses the colon to denote a symbol type, but you could use regex like :\w(\w\d)*: ... that may need some work, of course. I think $ should work like that as well, but either could make things hard to read if you were using the target language that has those tokens.

This is getting difficult. What about a high-valued ascii character? ยท is my favorite (250) It might be bad at first, but its something you can easily learn, and its only one of them. Of course, using double whatever's may work better.
# Posted By Sammy Larbi | 7/5/07 1:40 PM
Yeah, transliterating to any target 3GL is more than I want to do. Apart from anything else, that'd be re-inventing the wheel - there are plenty, and the base language already have those constructs, so I want to keep my generated templates as thin a layer as possible over the target languages.

I don't love high value ASCII - anything I can't immediately see on any keyboard on any computer in any language set is a little more esoteric than I want to do. That only leaves so many options. I like wider characters like % or # or even $ as it is easier to read. Maybe ~ would be an option, although I don't love it visually - you don't usually see many tildas in code (in languages I've looked at - anyway). I suppose a ? has a certain logic to it - ?Value? replaces the string with the (currently unknown) value - I might be able to get into that although it seems a little strange at first. There are many tokens I might be able to use with some smart regexs, but I would want to think them through very carefully. Double characters are acceptable but a little unwieldy (maybe the least bad alternative).

Any more thoughts?
# Posted By Peter Bell | 7/5/07 2:42 PM
Ruby lets you use ! and ? in method names. And I'm 90% sure I've seen ~ denote something in some language ... perhaps a regex but the language escapes me.

I'm so used to using alt-250 (on the keypad) that I can type it pretty much in stream (at least as quickly as I can think about what needs to come next). But, I realize the learning curve needs to be relatively low for things to be useful to the masses. Not even the best among us will fight /against/ something for too long before we determine its not worth it and move on to something else.
# Posted By Sammy Larbi | 7/5/07 3:06 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.