Skip to content

Commit

Permalink
Process templates like "{{#contact}}({{name}}'s number is {{phone}}){…
Browse files Browse the repository at this point in the history
…{/contact}}," where contact is a struct.
  • Loading branch information
pmcelhaney committed May 28, 2010
1 parent 06028c4 commit 77ddcc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 6 additions & 3 deletions CFStache.cfc
Expand Up @@ -31,15 +31,18 @@
<cfset type = matches[2] />
<cfset tagName = matches[3] />
<cfset inner = matches[4] />
<cfset template = replace(template, tag, renderTemplate(tagName, inner))/>
<cfset template = replace(template, tag, renderSection(tagName, inner))/>
</cfloop>
<cfreturn template/>
</cffunction>

<cffunction name="renderTemplate">
<cffunction name="renderSection">
<cfargument name="tagName"/>
<cfargument name="inner"/>
<cfif get(tagName)>
<cfset var ctx = get(tagName) />
<cfif isStruct(ctx)>
<cfreturn render(inner, ctx)>
<cfelseif ctx>
<cfreturn inner />
<cfelse>
<cfreturn "" />
Expand Down
13 changes: 11 additions & 2 deletions Tests.cfc
Expand Up @@ -60,8 +60,17 @@
<cfset template = "Ready {{##set}}set {{/set}}go!" />
<cfset context = { set = true } />
<cfset expected = "Ready set go!" />
</cffunction>

</cffunction>

<cffunction name="structAsSection">
<cfset context = {
contact = { name = 'Jenny', phone = '867-5309'}
} />
<cfset template = "{{##contact}}({{name}}'s number is {{phone}}){{/contact}}">
<cfset expected = "(Jenny's number is 867-5309)" />


</cffunction>



Expand Down

0 comments on commit 77ddcc6

Please sign in to comment.