Re: template reader/parser sort of thing :)

2004-03-01 Thread Steve Nelson
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...

 !---@ begin links @---

!---@ main links @---

!---@ end main links @---

 !---@ end links @---

 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 :)

2004-03-01 Thread Bryan F. Hogan
To make it a little easier to work with I would suggest using tag like 
syntax instead of comment syntax.

?mytags:link?
	?mytags:link main=1 /?
?mytags:link?

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...
 
 !---@ begin links @---
 
!---@ main links @---
 
!---@ end main links @---
 
 !---@ end links @---
 
 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 :)

2004-03-01 Thread Katz, Dov B (IT)
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...

!---@ begin links @---

 !---@ main links @---

!---@ end main links @---

!---@ end links @---

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 :)

2004-03-01 Thread Brendan Avery
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 

!--- create the XML Object containing the person's information ---
cfxml variable=personXMLObj
	person
		name
			firstgt;Joe/first
			lastO'Shmoe/last	
		/name
		sexMale/sex
		birthday2/20/1975/birthday
	/person
/cfxml

!--- create teh XSL template to display the person's information ---
cfsavecontent variable=personXSL
	xsl:stylesheet version=1.0
xmlns:xsl=http://www.w3.org/1999/XSL/Transform
		xsl:template match=/
			script
var
firstName='post-xsl:jsstringformatxsl:value-of
select=person/name/first //post-xsl:jsstringformat';
var
lastName='post-xsl:jsstringformatxsl:value-of
select=person/name/last //post-xsl:jsstringformat';
			/script
			form name=myForm action="">
method=post
			table border=1 cellpadding=3
cellspacing=0
tr align=left valign=top
	tdbPerson's Name:/b/td
	tdi
		input name=firstName
type=text value= /
		input name=lastName
type=text value= /
		/i/td
/tr
			/table
			/form
			script
	
document.forms.myForm.firstName.value=firstName;
	
document.forms.myForm.lastName.value=lastName;
			/script
		/xsl:template
	/xsl:stylesheet
/cfsavecontent

!--- this is the function for encoding post-xsl:jsstringformat tag
content ---
cffunction name=PostXSL_JSStringFormat access=private
returntype=string
	cfargument name=sourceContent type=string required=yes
	cfscript
		var content=sourceContent;
		var contentLeft='';
		var contentRight='';
		var openTag='post-xsl:jsstringformat';
		var openTagIndex=1;
		var closeTag='/post-xsl:jsstringformat';
		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;
}
			}
		}
	/cfscript
	cfreturn content
/cffunction

!--- this is the wrapper function for post-xsl:* tags ---
cffunction name=PostXSL access=private returntype=string
	cfargument name=sourceContent type=string required=yes
	cfscript
		var content=sourceContent;
		content=PostXSL_JSStringFormat(content);
		content=ReplaceNoCase(content,'?xml version=1.0
encoding=UTF-8?','','ALL');
	/cfscript
	cfreturn content
/cffunction

!--- this is the demo of it all in action ---
cfset personXHTML=PostXSL(XMLTransform(personXMLObj,personXSL))
cfoutput
	html
		head
			titlesome page/title
		/head
		body
			#personXHTML#
		/body
	/html
/cfoutput

// 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 i

Re: template reader/parser sort of thing :)

2004-03-01 Thread Ryan Mitchell
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 :)

2004-03-01 Thread Brendan Avery
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 !---@ begin
something @--- and !---@ end something @--- 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.

//
//
//
//
//
//

cfset sourceText=
!---@ begin main @---

	some text some text some text
	some text some text some text
	some text some text some text
	a href=''link/a
	
 !---@ begin links @---

	some text some text some text
	some text some text some text
	a href=''link/a
	a href=''link/a
	a href=''link/a
		
!---@ end links @---

 	some text some text some text
 	some text some text some text
 	some text some text some text
	a href=''link/a

!---@ end main @---


cfscript

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 !---@
tags.
tagContent=HTMLEditFormat(tagContent);

// now we are done with conversion so
lets put the tag contents back into the rest of the source

newSource=newSourceLeft  tagContent 
newSourceRight;

// ALL DONE.
			}		
		}
	}
	
	// return updated source text
	return newSource;
}

/cfscript

cfoutput
pre#HTMLEditFormat(ConvertIt(sourceText))#/pre
/cfoutput



//
//
//
//
//
//





-Original Message-
From: Ryan Mitchell [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 01, 2004 9:06 AM
To: CF-Talk
Subject: 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 :)

2004-03-01 Thread Nathan Strutz
Actually I really like this idea, but modified a bit... cfimport a taglib
of custom display tags, where from depends on the skin you want to use, then
mytags:linksSectionmytags:links/mytags:linksSection. 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.

?mytags:link?
?mytags:link main=1 /?
?mytags:link?

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...

 !---@ begin links @---

!---@ main links @---

!---@ end main links @---

 !---@ end links @---

 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 :)

2004-03-01 Thread Barney Boisvert
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... 
 cfimport a taglib
 of custom display tags, where from depends on the skin you 
 want to use, then
 mytags:linksSectionmytags:links/mytags:linksSection. 
 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.
 
?mytags:link?
?mytags:link main=1 /?
?mytags:link?
 
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...

 !---@ begin links @---

!---@ main links @---

!---@ end main links @---

 !---@ end links @---

 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 :)

2004-03-01 Thread Matthew Walker
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... 
 cfimport a taglib
 of custom display tags, where from depends on the skin you 
 want to use, then
 mytags:linksSectionmytags:links/mytags:linksSection. 
 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.
 
?mytags:link?
?mytags:link main=1 /?
?mytags:link?
 
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...

 !---@ begin links @---

!---@ main links @---

!---@ end main links @---

 !---@ end links @---

 ie nested bits needing replaced.

 Any wise thoughts? Things to watch out for?

 Thanks,
 Ryan
 
 


_
 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]