Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions mustache/Mustache.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--->

<cfset variables.SectionRegEx = CreateObject("java","java.util.regex.Pattern").compile("\{\{(##|\^)\s*(\w+)\s*}}(.*?)\{\{/\s*\2\s*\}\}", 32)>
<cfset variables.TagRegEx = CreateObject("java","java.util.regex.Pattern").compile("\{\{(!|\{|&|\>)?\s*(\w+).*?\}?\}\}", 32) />
<cfset variables.TagRegEx = CreateObject("java","java.util.regex.Pattern").compile("\{\{(!|\{|&|\>)?\s*([\w\.]+).*?\}?\}\}", 32) />


<cffunction name="init" output="false">
<cfreturn this />
Expand Down Expand Up @@ -65,7 +66,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cfset type = matches[2] />
<cfset tagName = matches[3] />
<cfset inner = matches[4] />

<cfset template = replace(template, tag, renderSection(tagName, type, inner, context))/>

</cfloop>
<cfreturn template/>
</cffunction>
Expand All @@ -76,6 +79,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cfargument name="inner"/>
<cfargument name="context"/>
<cfset var ctx = get(arguments.tagName, context) />

<cfif isStruct(ctx) and !StructIsEmpty(ctx)>
<cfreturn render(arguments.inner, ctx) />
<cfelseif isQuery(ctx) AND ctx.recordCount>
Expand All @@ -91,7 +95,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cfreturn "" />
</cffunction>

<cffunction name="convertToBoolean">
<cffunction name="convertToBoolean" output="false">
<cfargument name="value"/>
<cfif isBoolean(value)>
<cfreturn value />
Expand All @@ -114,9 +118,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

<cffunction name="renderArraySection" access="private" output="false">
<cfargument name="template"/>
<cfargument name="context"/>
<cfargument name="context"/>
<cfset var result = [] />
<cfset var item = "" />

<cfloop array="#context#" index="item">
<cfset ArrayAppend(result, render(template, item)) />
</cfloop>
Expand Down Expand Up @@ -147,6 +152,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cfargument name="type" />
<cfargument name="tagName" />
<cfargument name="context" />

<cfif type eq "!">
<cfreturn "" />
<cfelseif type eq "{" or type eq "&">
Expand All @@ -168,20 +174,23 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cffunction name="get" access="private" output="false">
<cfargument name="key" />
<cfargument name="context"/>

<cfif isStruct(context) && structKeyExists(context, key) >
<cfif isCustomFunction(context[key])>
<cfreturn evaluate("context.#key#('')")>
<cfelse>
<cfreturn context[key]/>
</cfif>
<cfelseif isQuery(context)>
<cfif listContainsNoCase(context.columnList, key)>
<cfreturn context[key][context.currentrow] />
<cfif listContainsNoCase(context.columnList, key)>
<cfreturn context[key][context.currentrow] />
<cfelse>
<cfreturn "" />
<cfreturn "" />
</cfif>
<cfelse>
<cfreturn "" />
<cfelseif (NOT isArray(context)) AND key EQ ".">
<cfreturn ToString(context)>
<cfelse>
<cfreturn "" />
</cfif>
</cffunction>

Expand Down