Skip to content
Browse files

Merge pull request #6 from GunioRobot/clean

Hi! I cleaned up your code for you!
  • Loading branch information...
2 parents b26ec84 + 33c2967 commit a37a3acf1831afdcda6944565410571dfbe561de @pmcelhaney committed Nov 8, 2011
View
4 LICENSE
@@ -10,10 +10,10 @@ without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
-
+
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
-
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
View
80 mustache/Mustache.cfc
@@ -1,6 +1,6 @@
-<!---
+<!---
Mustache.cfc
-https://github.com/pmcelhaney/Mustache.cfc
+https://github.com/pmcelhaney/Mustache.cfc
The MIT License
@@ -14,10 +14,10 @@ without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
-
+
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
-
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -28,8 +28,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--->
<cfcomponent>
-
- <!---
+
+ <!---
reference for string building
http://www.aliaspooryorik.com/blog/index.cfm/e/posts.details/post/string-concatenation-performance-test-128
--->
@@ -40,25 +40,25 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cffunction name="init" output="false">
<cfreturn this />
</cffunction>
-
+
<cffunction name="render" output="false">
<cfargument name="template" default="#readMustacheFile(ListLast(getMetaData(this).name, '.'))#"/>
<cfargument name="context" default="#this#"/>
<cfset template = renderSections(template, context) />
<cfreturn renderTags(template, context)/>
</cffunction>
-
+
<cffunction name="renderSections" access="private" output="false">
<cfargument name="template" />
<cfargument name="context" />
<cfset var tag = ""/>
- <cfset var tagName = ""/>
+ <cfset var tagName = ""/>
<cfset var type = "" />
<cfset var inner = "" />
<cfset var matches = arrayNew(1) />
<cfloop condition = "true" >
<cfset matches = ReFindNoCaseValues(template, variables.SectionRegEx)>
- <cfif arrayLen(matches) eq 0>
+ <cfif arrayLen(matches) eq 0>
<cfbreak>
</cfif>
<cfset tag = matches[1] />
@@ -68,14 +68,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cfset template = replace(template, tag, renderSection(tagName, type, inner, context))/>
</cfloop>
<cfreturn template/>
- </cffunction>
-
+ </cffunction>
+
<cffunction name="renderSection" access="private" output="false">
<cfargument name="tagName"/>
<cfargument name="type"/>
<cfargument name="inner"/>
<cfargument name="context"/>
- <cfset var ctx = get(arguments.tagName, 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>
@@ -89,9 +89,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cfreturn inner />
</cfif>
<cfreturn "" />
- </cffunction>
-
- <cffunction name="convertToBoolean">
+ </cffunction>
+
+ <cffunction name="convertToBoolean">
<cfargument name="value"/>
<cfif isBoolean(value)>
<cfreturn value />
@@ -101,7 +101,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</cfif>
<cfreturn false>
</cffunction>
-
+
<cffunction name="renderQuerySection" access="private" output="false">
<cfargument name="template"/>
<cfargument name="context"/>
@@ -110,39 +110,39 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cfset ArrayAppend(result, render(template, context)) />
</cfloop>
<cfreturn ArrayToList(result, "") />
- </cffunction>
-
+ </cffunction>
+
<cffunction name="renderArraySection" access="private" output="false">
<cfargument name="template"/>
<cfargument name="context"/>
- <cfset var result = [] />
+ <cfset var result = [] />
<cfset var item = "" />
<cfloop array="#context#" index="item">
<cfset ArrayAppend(result, render(template, item)) />
</cfloop>
<cfreturn ArrayToList(result, "") />
</cffunction>
-
-
+
+
<cffunction name="renderTags" access="private" output="false">
<cfargument name="template"/>
<cfargument name="context" />
<cfset var tag = ""/>
- <cfset var tagName = ""/>
+ <cfset var tagName = ""/>
<cfset var matches = arrayNew(1) />
- <cfloop condition = "true" >
- <cfset matches = ReFindNoCaseValues(template, variables.TagRegEx) />
+ <cfloop condition = "true" >
+ <cfset matches = ReFindNoCaseValues(template, variables.TagRegEx) />
<cfif arrayLen(matches) eq 0>
<cfbreak>
</cfif>
<cfset tag = matches[1]/>
<cfset type = matches[2] />
<cfset tagName = matches[3] />
- <cfset template = replace(template, tag, renderTag(type, tagName, context))/>
+ <cfset template = replace(template, tag, renderTag(type, tagName, context))/>
</cfloop>
- <cfreturn template/>
+ <cfreturn template/>
</cffunction>
-
+
<cffunction name="renderTag" access="private" output="false">
<cfargument name="type" />
<cfargument name="tagName" />
@@ -155,36 +155,36 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<cfreturn render(readMustacheFile(tagName), context) />
<cfelse>
<cfreturn htmlEditFormat(get(tagName, context)) />
- </cfif>
- </cffunction>
-
+ </cfif>
+ </cffunction>
+
<cffunction name="readMustacheFile" access="private" output="false">
- <cfargument name="filename" />
+ <cfargument name="filename" />
<cfset var template="" />
- <cffile action="read" file="#getDirectoryFromPath(getMetaData(this).path)##filename#.mustache" variable="template"/>
+ <cffile action="read" file="#getDirectoryFromPath(getMetaData(this).path)##filename#.mustache" variable="template"/>
<cfreturn trim(template)/>
</cffunction>
-
+
<cffunction name="get" access="private" output="false">
<cfargument name="key" />
<cfargument name="context"/>
<cfif isStruct(context) && structKeyExists(context, key) >
- <cfif isCustomFunction(context[key])>
+ <cfif isCustomFunction(context[key])>
<cfreturn evaluate("context.#key#('')")>
<cfelse>
- <cfreturn context[key]/>
+ <cfreturn context[key]/>
</cfif>
- <cfelseif isQuery(context)>
+ <cfelseif isQuery(context)>
<cfif listContainsNoCase(context.columnList, key)>
<cfreturn context[key][context.currentrow] />
- <cfelse>
+ <cfelse>
<cfreturn "" />
</cfif>
<cfelse>
<cfreturn "" />
</cfif>
</cffunction>
-
+
<cffunction name="ReFindNoCaseValues" access="private" output="false">
<cfargument name="text"/>
<cfargument name="re"/>
@@ -204,5 +204,5 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</cfif>
<cfreturn results />
</cffunction>
-
+
</cfcomponent>
View
2 tests/Filter.cfc
@@ -1,6 +1,6 @@
<cfcomponent>
- <cffunction name="bold" >
+ <cffunction name="bold" >
<cfargument name="text">
<cfreturn "<b>#text#</b>" />
</cffunction>
View
8 tests/Person.cfc
@@ -1,9 +1,9 @@
<cfcomponent>
-
+
<cfset this.firstname = "John" />
- <cfset this.lastname = "Smith" />
-
+ <cfset this.lastname = "Smith" />
+
<cffunction name="fullName" >
<cfreturn "#this.firstname# #this.lastname#" />
</cffunction>
-</cfcomponent>
+</cfcomponent>
View
94 tests/RenderTests.cfc
@@ -1,74 +1,74 @@
<cfcomponent extends="mxunit.framework.TestCase">
-
+
<cffunction name="setup">
<cfset stache = createObject("component", "mustache.Mustache").init()/>
</cffunction>
-
+
<cffunction name="tearDown">
<cfset assertEquals(expected, stache.render(template, context)) />
</cffunction>
-
+
<cffunction name="basic">
<cfset context = { thing = 'world'} />
<cfset template = "Hello, {{thing}}!" />
<cfset expected = "Hello, World!" />
- </cffunction>
-
- <cffunction name="lessBasic">
+ </cffunction>
+
+ <cffunction name="lessBasic">
<cfset context = { beverage = 'soda', person = 'Bob' } />
<cfset template = "It's a nice day for {{beverage}}, right {{person}}?" />
<cfset expected = "It's a nice day for soda, right Bob?"/>
- </cffunction>
-
+ </cffunction>
+
<cffunction name="evenLessBasic">
<cfset context = { name = 'Jon', thing = 'racecar'} />
<cfset template = "I think {{name}} wants a {{thing}}, right {{name}}?">
<cfset expected = "I think Jon wants a racecar, right Jon?" />
- </cffunction>
-
+ </cffunction>
+
<cffunction name="ignoresMisses">
<cfset context = { name = 'Jon'} />
<cfset template = "I think {{name}} wants a {{thing}}, right {{name}}?">
<cfset expected = "I think Jon wants a , right Jon?" />
- </cffunction>
-
+ </cffunction>
+
<cffunction name="renderZero">
<cfset context = { value = 0 } />
- <cfset template = "My value is {{value}}." />
+ <cfset template = "My value is {{value}}." />
<cfset expected = "My value is 0." />
- </cffunction>
-
+ </cffunction>
+
<cffunction name="comments">
<cfset context = structNew() />
<cfset context['!'] = "FAIL" />
<cfset context['the'] = "FAIL" />
<cfset template = "What {{!the}} what?" />
<cfset expected = "What what?" />
</cffunction>
-
+
<cffunction name="falseSectionsAreHidden">
<cfset context = { set = false } />
<cfset template = "Ready {{##set}}set {{/set}}go!" />
<cfset expected = "Ready go!" />
</cffunction>
-
+
<cffunction name="trueSectionsAreShown">
<cfset context = { set = true } />
<cfset template = "Ready {{##set}}set {{/set}}go!" />
<cfset expected = "Ready set go!" />
</cffunction>
-
+
<cffunction name="falseSectionsAreShownIfInverted">
<cfset context = { set = false } />
<cfset template = "Ready {{^set}}set {{/set}}go!" />
<cfset expected = "Ready set go!" />
</cffunction>
-
+
<cffunction name="trueSectionsAreHiddenIfInverted">
<cfset context = { set = true } />
<cfset template = "Ready {{^set}}set {{/set}}go!" />
<cfset expected = "Ready go!" />
- </cffunction>
+ </cffunction>
<cffunction name="emptyStringsAreFalse">
<cfset context = { set = "" } />
@@ -93,27 +93,27 @@
<cfset template = "Ready {{##set}}No records found{{/set}}go!" />
<cfset expected = "Ready go!" />
</cffunction>
-
+
<cffunction name="nonEmptyStringsAreTrue">
<cfset context = { set = "x" } />
<cfset template = "Ready {{##set}}set {{/set}}go!" />
<cfset expected = "Ready set go!" />
- </cffunction>
+ </cffunction>
<cffunction name="skipMissingField">
<cfset context = structNew() />
<cfset template = "There's something {{##foo}}missing{{/foo}}!" />
<cfset expected = "There's something !" />
</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>
-
+ </cffunction>
+
<cffunction name="queryAsSection">
<cfset contacts = queryNew("name,phone")/>
<cfset queryAddRow(contacts)>
@@ -134,80 +134,80 @@
<cfset context = {contacts = contacts} />
<cfset template = "{{##contacts}}({{name}}'s number is {{phone}}){{/contacts}}">
<cfset expected = "(Jenny's number is )" />
- </cffunction>
-
+ </cffunction>
+
<cffunction name="arrayAsSection">
<cfset context = {
- contacts = [
+ contacts = [
{ name = 'Jenny', phone = '867-5309'}
, { name = 'Tom', phone = '555-1234'}
]
} />
<cfset template = "{{##contacts}}({{name}}'s number is {{phone}}){{/contacts}}">
<cfset expected = "(Jenny's number is 867-5309)(Tom's number is 555-1234)" />
- </cffunction>
+ </cffunction>
<cffunction name="missingStructKeyIsSkipped">
<cfset context = {
- contacts = [
+ contacts = [
{ name = 'Jenny', phone = '867-5309'}
, { name = 'Tom'}
]
} />
<cfset template = "{{##contacts}}({{name}}'s number is {{^phone}}unlisted{{/phone}}{{phone}}){{/contacts}}">
<cfset expected = "(Jenny's number is 867-5309)(Tom's number is unlisted)" />
</cffunction>
-
+
<cffunction name="escape">
<cfset context = { thing = '<b>world</b>'} />
<cfset template = "Hello, {{thing}}!" />
<cfset expected = "Hello, &lt;b&gt;world&lt;/b&gt;!" />
</cffunction>
-
+
<cffunction name="dontEscape">
<cfset template = "Hello, {{{thing}}}!" />
<cfset context = { thing = '<b>world</b>'} />
<cfset expected = "Hello, <b>world</b>!" />
</cffunction>
-
+
<cffunction name="dontEscapeWithAmpersand">
<cfset context = { thing = '<b>world</b>'} />
<cfset template = "Hello, {{&thing}}!" />
<cfset expected = "Hello, <b>world</b>!" />
- </cffunction>
-
+ </cffunction>
+
<cffunction name="ignoreWhitespace">
<cfset context = { thing = 'world'} />
<cfset template = "Hello, {{ thing }}!" />
<cfset expected = "Hello, world!" />
- </cffunction>
-
+ </cffunction>
+
<cffunction name="ignoreWhitespaceInSection">
<cfset context = { set = true } />
<cfset template = "Ready {{## set }}set {{/ set }}go!" />
<cfset expected = "Ready set go!" />
- </cffunction>
-
+ </cffunction>
+
<cffunction name="callAFunction">
<cfset context = createObject("component", "Person")/>
<cfset context.firstname = "Chris" />
<cfset context.lastname = "Wanstrath" />
- <cfset template = "Mustache was created by {{fullname}}." />
+ <cfset template = "Mustache was created by {{fullname}}." />
<cfset expected = "Mustache was created by Chris Wanstrath." />
</cffunction>
-
- <cffunction name="filter">
+
+ <cffunction name="filter">
<cfset context = createObject("component", "Filter")/>
<cfset template = "Hello, {{##bold}}world{{/bold}}." />
<cfset expected = "Hello, <b>world</b>." />
</cffunction>
-
- <cffunction name="partial">
+
+ <cffunction name="partial">
<!--- using a subclass so that it will look for the partial in this directory --->
- <cfset stache = createObject("component", "Winner").init()/>
+ <cfset stache = createObject("component", "Winner").init()/>
<cfset context = { word = 'Goodnight', name = 'Gracie' } />
<cfset template = "<ul><li>Say {{word}}, {{name}}.</li><li>{{> gracie_allen}}</li></ul>" />
- <cfset expected = "<ul><li>Say Goodnight, Gracie.</li><li>Goodnight</li></ul>" />
+ <cfset expected = "<ul><li>Say Goodnight, Gracie.</li><li>Goodnight</li></ul>" />
</cffunction>
-
+
</cfcomponent>
View
2 tests/Tests.cfc
@@ -1,4 +1,4 @@
-<cfcomponent output="false" extends="mxunit.framework.TestSuite">
+<cfcomponent output="false" extends="mxunit.framework.TestSuite">
<cfset addAll("tests.RenderTests")>
<cfset addAll("tests.WinnerTest") />
<cfset addAll("tests.one.two.three.WinnerTest") />
View
2 tests/Winner.cfc
@@ -1,3 +1,3 @@
<cfcomponent extends="mustache.Mustache">
-
+
</cfcomponent>
View
8 tests/WinnerTest.cfc
@@ -4,14 +4,14 @@
<cfset winner.name = "Patrick" />
<cfset winner.value = 10000 />
<cfset winner.taxed_value = 10000 - 10000 * 0.4/>
- <cfset winner.in_ca = true />
+ <cfset winner.in_ca = true />
<!--- TODO: Technically, there shouldn't be newlines after "$10000!" and "taxes." (going by the ctemplate spec) --->
<cfset expected = "Hello Patrick
You have just won $10000!
Well, $6000, after taxes.
-" />
+" />
<cfset assertEquals(expected, winner.render()) />
</cffunction>
-
-</cfcomponent>
+
+</cfcomponent>
View
2 tests/one/two/three/Winner.cfc
@@ -1,3 +1,3 @@
<cfcomponent extends="mustache.Mustache">
-
+
</cfcomponent>
View
8 tests/one/two/three/WinnerTest.cfc
@@ -4,14 +4,14 @@
<cfset winner.name = "Patrick" />
<cfset winner.value = 10000 />
<cfset winner.taxed_value = 10000 - 10000 * 0.4/>
- <cfset winner.in_ca = true />
+ <cfset winner.in_ca = true />
<!--- TODO: Technically, there shouldn't be newlines after "$10000!" and "taxes." (going by the ctemplate spec) --->
<cfset expected = "Hello Patrick
You have just won $10000!
Well, $6000, after taxes.
-" />
+" />
<cfset assertEquals(expected, winner.render()) />
</cffunction>
-
-</cfcomponent>
+
+</cfcomponent>

0 comments on commit a37a3ac

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