RE: template reader/parser sort of thing :)
I recently wrote a weblog app which used custom (Movable Type-style) markup tags to indicate points to insert data into an HTML template. When first viewed, this would all be compiled into a regular cfm file to improve performance. Soon after writing this I found the flexibility limitations e.g. handling attributes was a pain, inability to embed cfm if I wanted to. I ended up replacing with a cfimport and tag library as described below, which means all the functionality is inherent to CF, no template compilation, and the markup is easier, even for non-CF folk. Fundamentally though, the code is much much easier to maintain. My solution: all the visual design is handled by CSS. The template is little more than a series of tags indicating which elements to include and the attributes to pass, plus a few divs. -Original Message- From: Barney Boisvert [mailto:[EMAIL PROTECTED] Sent: Tuesday, 2 March 2004 7:16 a.m. To: CF-Talk Subject: RE: template reader/parser sort of thing :) Though you can't compute a taglib path at runtime, it's done at compile time, so that wouldn't of much use if the skinning needs to be dynamic. You'd have to use them the other way (where the template is skin specific, and the tags are the commonn stuff). Cheers, barneyb > -Original Message- > From: Nathan Strutz [mailto:[EMAIL PROTECTED] > Sent: Monday, March 01, 2004 11:04 AM > To: CF-Talk > Subject: RE: template reader/parser sort of thing :) > > Actually I really like this idea, but modified a bit... > a taglib > of custom display tags, where from depends on the skin you > want to use, then > . > This is native > functionality to coldfusion, and not nearly as much code as > the XSLT samples > given in this thread. > > -nathan strutz > > > -Original Message- > From: Bryan F. Hogan [mailto:[EMAIL PROTECTED] > Sent: Monday, March 01, 2004 7:23 AM > To: CF-Talk > Subject: Re: template reader/parser sort of thing :) > > > To make it a little easier to work with I would suggest > using tag like > syntax instead of comment syntax. > > > > > > Then use regular expressions to parse the page into a > structure replace > your tags with the appropriate data, write the page to disk > or memory, > and then save the unparsed page as a template. > > Ryan Mitchell wrote: > > > Hello > > > > I'm working on a project that i would like to make > skinnable... i'm not > > just talking css skinnable i mean like proper skinnable. > > > > I was wanting to use a file as a template that contained > some variation > > of comments eg <[EMAIL PROTECTED] links ---@> or something to that > effect, which are > > then replaced by finding the appropriate entry in a > structure of items > > to be replaced... > > > > Has anyone done this before? What happens when you have > an arrangement > > like this... > > > > > > > > > > > > > > > > > > > > ie nested bits needing replaced. > > > > Any wise thoughts? Things to watch out for? > > > > Thanks, > > Ryan > > > _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: template reader/parser sort of thing :)
Though you can't compute a taglib path at runtime, it's done at compile time, so that wouldn't of much use if the skinning needs to be dynamic. You'd have to use them the other way (where the template is skin specific, and the tags are the commonn stuff). Cheers, barneyb > -Original Message- > From: Nathan Strutz [mailto:[EMAIL PROTECTED] > Sent: Monday, March 01, 2004 11:04 AM > To: CF-Talk > Subject: RE: template reader/parser sort of thing :) > > Actually I really like this idea, but modified a bit... > a taglib > of custom display tags, where from depends on the skin you > want to use, then > . > This is native > functionality to coldfusion, and not nearly as much code as > the XSLT samples > given in this thread. > > -nathan strutz > > > -Original Message- > From: Bryan F. Hogan [mailto:[EMAIL PROTECTED] > Sent: Monday, March 01, 2004 7:23 AM > To: CF-Talk > Subject: Re: template reader/parser sort of thing :) > > > To make it a little easier to work with I would suggest > using tag like > syntax instead of comment syntax. > > > > > > Then use regular expressions to parse the page into a > structure replace > your tags with the appropriate data, write the page to disk > or memory, > and then save the unparsed page as a template. > > Ryan Mitchell wrote: > > > Hello > > > > I'm working on a project that i would like to make > skinnable... i'm not > > just talking css skinnable i mean like proper skinnable. > > > > I was wanting to use a file as a template that contained > some variation > > of comments eg <[EMAIL PROTECTED] links ---@> or something to that > effect, which are > > then replaced by finding the appropriate entry in a > structure of items > > to be replaced... > > > > Has anyone done this before? What happens when you have > an arrangement > > like this... > > > > > > > > > > > > > > > > > > > > ie nested bits needing replaced. > > > > Any wise thoughts? Things to watch out for? > > > > Thanks, > > Ryan > > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: template reader/parser sort of thing :)
Actually I really like this idea, but modified a bit... a taglib of custom display tags, where from depends on the skin you want to use, then . This is native functionality to coldfusion, and not nearly as much code as the XSLT samples given in this thread. -nathan strutz -Original Message- From: Bryan F. Hogan [mailto:[EMAIL PROTECTED] Sent: Monday, March 01, 2004 7:23 AM To: CF-Talk Subject: Re: template reader/parser sort of thing :) To make it a little easier to work with I would suggest using tag like syntax instead of comment syntax. Then use regular expressions to parse the page into a structure replace your tags with the appropriate data, write the page to disk or memory, and then save the unparsed page as a template. Ryan Mitchell wrote: > Hello > > I'm working on a project that i would like to make skinnable... i'm not > just talking css skinnable i mean like proper skinnable. > > I was wanting to use a file as a template that contained some variation > of comments eg <[EMAIL PROTECTED] links ---@> or something to that effect, which are > then replaced by finding the appropriate entry in a structure of items > to be replaced... > > Has anyone done this before? What happens when you have an arrangement > like this... > > > > > > > > > > ie nested bits needing replaced. > > Any wise thoughts? Things to watch out for? > > Thanks, > Ryan [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: template reader/parser sort of thing :)
I assume you probably will want to handle the deepest nested tags first before working your way back out to the bottom-most level, in which case a recursive function is probably the best way to handle it. Something along the lines of this maybe: (Please note this function works when you have a matching and only -- so be sure to use begin and end in your comment names for this one to work.) I attached a zip file containing this cftemplate for your edification and amusement. // // // // // // function ConvertIt(source) { var openTagInfo=0; var tagName=0; var tagContent=0; var reSafeTagName=0; var closeTagInfo=0; var newSource=source; var newSourceLeft=0; var newSourceRight=0; // find the 'open-tag' openTagInfo=REFindNoCase("<[EMAIL PROTECTED]:space:]]*begin[[:space:]]+([EMAIL PROTECTED])@--- >",source,1,"TRUE"); // check if an 'open-tag' was found if(openTagInfo.pos[1] GT 0) { // get the 'name' of the tag tagName=Trim(Mid(source,openTagInfo.pos[2],openTagInfo.len[2])); // escape non-alphanumeric characters for our upcoming regular closetag match regex reSafeTagName=REReplaceNoCase(tagName,"([^[:alnum:]])","\\\1","ALL"); // find the 'close-tag' closeTagInfo=REFindNoCase("<[EMAIL PROTECTED]:space:]]*end[[:space:]]+"&reSafeTagN ame&"[[:space:[EMAIL PROTECTED]>",source,1,"TRUE"); // check if a 'close-tag' was found if(closeTagInfo.pos[1] GT 0) { // make sure tag content is more than an empty string so our Mid() function doesn't bomb if((closeTagInfo.pos[1]-(openTagInfo.pos[1]+openTagInfo.len[1])) GT 0) { // extract the tag content tagContent=Mid(newSource,openTagInfo.pos[1]+openTagInfo.len[1],closeTagI nfo.pos[1]-(openTagInfo.pos[1]+openTagInfo.len[1])); // if left-side or right-side remainders are zero-length we need to manually set empty strings so as not to bomb Left() and Right() functions if(openTagInfo.pos[1] GT 1) { newSourceLeft=Left(newSource,openTagInfo.pos[1]-1); } else { newSourceLeft=''; } if((Len(newSource)-(closeTagInfo.pos[1]+closeTagInfo.len[1]-1)) GT 0) { newSourceRight=Right(newSource,Len(newSource)-(closeTagInfo.pos[1]+close TagInfo.len[1]-1)); } else { newSourceRight=''; } // recursively call ConvertIt() to handle nested tags first tagContent=ConvertIt(tagContent); // okay NOW we perform any conversion functions that you want // since i have no idea what you want to do here i will just HTMLEditFormat any content surrounded by [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re: template reader/parser sort of thing :)
ok, i would prefer not to do it this way.. basically among other ideas i would love to convert phpbb over to coldfusion.. i've been working on it for a while, and now i've come to the reading and parsing of the template files... i want to be able to read in phpbb template files and so xlst/xml won't work. my main problem comes with nested replacements... how do you do it? TIA, Ryan [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: template reader/parser sort of thing :)
I concur with dov -- CFMX has built in XMLTransform functions for doing all this stuff right in XML which means the designs are much more portable and stuff -- XSLT is very flexible -- the only pain in the butt is filling in form element values which I do with _javascript_. I actually wrote a function for doing this find-replace action after the XML transform. Here's an example for doing the whole thing [also attached in example.cfm for convenience] // begin example.cfm // begin example.cfm // begin example.cfm // begin example.cfm >Joe O'Shmoe Male 2/20/1975 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <br> var<br> firstName='<post-xsl:jsstringformat><xsl:value-of<br> select="person/name/first" /></post-xsl:jsstringformat>';<br> var<br> lastName='<post-xsl:jsstringformat><xsl:value-of<br> select="person/name/last" /></post-xsl:jsstringformat>';<br> method="post"> cellspacing="0"> Person's Name: type="text" value="" /> type="text" value="" /> <br> <br> document.forms.myForm.firstName.value=firstName;<br> <br> document.forms.myForm.lastName.value=lastName;<br> returntype="string"> var content=sourceContent; var contentLeft=''; var contentRight=''; var openTag=''; var openTagIndex=1; var closeTag=''; var closeTagIndex=0; var tagContent=''; var tagContentLen=0; while(openTagIndex LT Len(content)) { openTagIndex=FindNoCase(openTag,content,openTagIndex); if(openTagIndex EQ 0) { openTagIndex=Len(content); } else { closeTagIndex=FindNoCase(closeTag,content,openTagIndex); if(closeTagIndex EQ 0) { openTagIndex=Len(content); } else { tagContentLen=closeTagIndex-(openTagIndex+Len(openTag)); if(tagContentLen GT 0) { tagContent=Mid(content,openTagIndex+Len(openTag),tagContentLen); tagContent=JSStringFormat(tagContent); } else { tagContent=''; } if(openTagIndex GT 1) { contentLeft=Left(content,openTagIndex-1); } else { contentLeft=''; } if((closeTagIndex+Len(closeTag)-1) LT Len(content)) { contentRight=Right(content,Len(content)-(closeTagIndex+Len(closeTag)-1)) ; } else { contentRight=''; } content=contentLeft & tagContent & contentRight; openTagIndex=openTagIndex+1; } } } var content=sourceContent; content=PostXSL_JSStringFormat(content); content=ReplaceNoCase(content,' encoding="UTF-8"?>','','ALL'); some page #personXHTML# ////// end example.cfm // // end example.cfm // // end example.cfm // // end example.cfm // -Original Message- From: Katz, Dov B (IT) [mailto:[EMAIL PROTECTED] Sent: Monday, March 01, 2004 8:27 AM To: CF-Talk Subject: RE: template reader/parser sort of thing :) I recommend that you use XML to do the templating, and XSLT to apply the styles to your templated files. This is closer to an industry-adopted standard instead of some sort of hand-coded solution. Why reinvent the wheel? -dov _ From: Ryan Mitchell [mailto:[EMAIL PROTECTED] Sent: Monday, March 01, 2004 9:15 AM To: CF-Talk Subject: template reader/parser sort of thing :) Hello I'm working on a project that i would like to make skinnable... i'm not just talking css skinnable i mean like proper skinnable. I was wanting to use a file as a template that contained some variation of comments eg <[EMAIL PROTECTED] links ---@> or something to that effect, which are then replaced by finding the appropriate entry in a structure of items to be replaced... Has anyone done this before? What happens when you have an arrangement like this... ie nested bits needing replaced. Any wise thoughts? Things to watch out for? Thanks, Ryan _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: template reader/parser sort of thing :)
I recommend that you use XML to do the templating, and XSLT to apply the styles to your templated files. This is closer to an industry-adopted standard instead of some sort of hand-coded solution. Why reinvent the wheel? -dov _ From: Ryan Mitchell [mailto:[EMAIL PROTECTED] Sent: Monday, March 01, 2004 9:15 AM To: CF-Talk Subject: template reader/parser sort of thing :) Hello I'm working on a project that i would like to make skinnable... i'm not just talking css skinnable i mean like proper skinnable. I was wanting to use a file as a template that contained some variation of comments eg <[EMAIL PROTECTED] links ---@> or something to that effect, which are then replaced by finding the appropriate entry in a structure of items to be replaced... Has anyone done this before? What happens when you have an arrangement like this... ie nested bits needing replaced. Any wise thoughts? Things to watch out for? Thanks, Ryan _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re: template reader/parser sort of thing :)
To make it a little easier to work with I would suggest using tag like syntax instead of comment syntax. Then use regular expressions to parse the page into a structure replace your tags with the appropriate data, write the page to disk or memory, and then save the unparsed page as a template. Ryan Mitchell wrote: > Hello > > I'm working on a project that i would like to make skinnable... i'm not > just talking css skinnable i mean like proper skinnable. > > I was wanting to use a file as a template that contained some variation > of comments eg <[EMAIL PROTECTED] links ---@> or something to that effect, which are > then replaced by finding the appropriate entry in a structure of items > to be replaced... > > Has anyone done this before? What happens when you have an arrangement > like this... > > > > > > > > > > ie nested bits needing replaced. > > Any wise thoughts? Things to watch out for? > > Thanks, > Ryan [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re: template reader/parser sort of thing :)
Have you seen the contentVariables in Fusebox 4? It handles this type of skinning for you. If you want it db driven, you could just write a script to write out the appropriate fb4 xml. Steve Nelson Ryan Mitchell wrote: > Hello > > I'm working on a project that i would like to make skinnable... i'm > not > just talking css skinnable i mean like proper skinnable. > > I was wanting to use a file as a template that contained some > variation > of comments eg <[EMAIL PROTECTED] links ---@> or something to that effect, which > are > then replaced by finding the appropriate entry in a structure of items > > to be replaced... > > Has anyone done this before? What happens when you have an arrangement > > like this... > > > > > > > > > > ie nested bits needing replaced. > > Any wise thoughts? Things to watch out for? > > Thanks, > Ryan > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
template reader/parser sort of thing :)
Hello I'm working on a project that i would like to make skinnable... i'm not just talking css skinnable i mean like proper skinnable. I was wanting to use a file as a template that contained some variation of comments eg <[EMAIL PROTECTED] links ---@> or something to that effect, which are then replaced by finding the appropriate entry in a structure of items to be replaced... Has anyone done this before? What happens when you have an arrangement like this... ie nested bits needing replaced. Any wise thoughts? Things to watch out for? Thanks, Ryan [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]