Skip to content
Browse files

Refactoring: extracted RenderQuerySection() and RenderArraySection()

  • Loading branch information...
1 parent f53dc93 commit a2e9081f358ae3a927db1499811e83c60d4064fe @pmcelhaney committed May 29, 2010
Showing with 24 additions and 10 deletions.
  1. +24 −10 Mustache.cfc
View
34 Mustache.cfc
@@ -40,29 +40,43 @@
<cfargument name="inner"/>
<cfargument name="context"/>
<cfset var ctx = get(tagName, context) />
- <cfset var result = "" />
- <cfset var item = "" />
<cfif isStruct(ctx)>
<cfreturn render(inner, ctx)>
<cfelseif isQuery(ctx)>
- <cfloop query="ctx">
- <cfset result &= render(inner, ctx) /> <!--- TODO: should probably use StringBuilder for performance --->
- </cfloop>
- <cfreturn result/>
+ <cfreturn renderQuerySection(inner, ctx) />
<cfelseif isArray(ctx)>
- <cfloop array="#ctx#" index="item">
- <cfset result &= render(inner, item) /> <!--- TODO: should probably use StringBuilder for performance --->
- </cfloop>
- <cfreturn result />
+ <cfreturn renderArraySection(inner, ctx) />
<cfelseif isFunction(context[tagName])>
<cfreturn evaluate("context.#tagName#(inner)") />
<cfelseif ctx xor type eq "^">
<cfreturn inner />
<cfelse>
<cfreturn "" />
</cfif>
+ </cffunction>
+
+ <cffunction name="renderQuerySection" access="private" output="false">
+ <cfargument name="template"/>
+ <cfargument name="context"/>
+ <cfset var result = "" />
+ <cfloop query="context">
+ <cfset result &= render(template, context) /> <!--- TODO: should probably use StringBuilder for performance --->
+ </cfloop>
+ <cfreturn result/>
+ </cffunction>
+
+ <cffunction name="renderArraySection" access="private" output="false">
+ <cfargument name="template"/>
+ <cfargument name="context"/>
+ <cfset var result = "" />
+ <cfset var item = "" />
+ <cfloop array="#context#" index="item">
+ <cfset result &= render(template, item) /> <!--- TODO: should probably use StringBuilder for performance --->
+ </cfloop>
+ <cfreturn result/>
</cffunction>
+
<cffunction name="renderTags" access="private" output="false">
<cfargument name="template"/>
<cfargument name="context" />

0 comments on commit a2e9081

Please sign in to comment.
Something went wrong with that request. Please try again.