| @@ -92,6 +92,7 @@ | |||||
| var equalsRe = /\s*=/; | var equalsRe = /\s*=/; | ||||
| var curlyRe = /\s*\}/; | var curlyRe = /\s*\}/; | ||||
| var tagRe = /#|\^|\/|>|\{|&|=|!/; | var tagRe = /#|\^|\/|>|\{|&|=|!/; | ||||
| var pipelineRe = /\|\>?/; | |||||
| /** | /** | ||||
| * Breaks up the given `template` string into a tree of tokens. If the `tags` | * Breaks up the given `template` string into a tree of tokens. If the `tags` | ||||
| @@ -397,13 +398,39 @@ | |||||
| return new Context(view, this); | return new Context(view, this); | ||||
| }; | }; | ||||
| Context.prototype.resolvePipelineOperator = function resolvePipelineOperator (value, pipelines){ | |||||
| var self = this; | |||||
| var pipelineResolver = function pipelineResolver (val, func){ | |||||
| var findFunction = function(instance, functionToFind, valueToPutInFindedFunction, depth){ | |||||
| if(depth <= 0 || !instance) return null; | |||||
| if(instance.view.hasOwnProperty(functionToFind)) return instance.view[func](valueToPutInFindedFunction); | |||||
| return findFunction(instance.parent, functionToFind, val, depth) | |||||
| } | |||||
| var findedFunction = findFunction(self, func, val, 20) | |||||
| return findedFunction ? findedFunction : val | |||||
| }; | |||||
| return pipelines.reduce(pipelineResolver,value); | |||||
| }; | |||||
| /** | /** | ||||
| * Returns the value of the given name in this context, traversing | * Returns the value of the given name in this context, traversing | ||||
| * up the context hierarchy if the value is absent in this context's view. | * up the context hierarchy if the value is absent in this context's view. | ||||
| */ | */ | ||||
| Context.prototype.lookup = function lookup (name) { | Context.prototype.lookup = function lookup (name) { | ||||
| var cache = this.cache; | |||||
| // {{variable | pipelineOne |> pipelineTwo}} | |||||
| // output: [variable,pipelineOne, pipelineTwo ] | |||||
| // Can use | or |>. | |||||
| var replacedName = name | |||||
| .replace(new RegExp(spaceRe, 'g'),'') | |||||
| .split(pipelineRe); | |||||
| name = replacedName.shift(); | |||||
| pipelines = replacedName; | |||||
| var cache = this.cache; | |||||
| var value; | var value; | ||||
| if (cache.hasOwnProperty(name)) { | if (cache.hasOwnProperty(name)) { | ||||
| value = cache[name]; | value = cache[name]; | ||||
| @@ -478,9 +505,14 @@ | |||||
| cache[name] = value; | cache[name] = value; | ||||
| } | } | ||||
| if (isFunction(value)) | if (isFunction(value)) | ||||
| value = value.call(this.view); | value = value.call(this.view); | ||||
| if (pipelines){ | |||||
| value = this.resolvePipelineOperator(value, pipelines); | |||||
| } | |||||
| return value; | return value; | ||||
| }; | }; | ||||
| @@ -1,6 +1,6 @@ | |||||
| { | { | ||||
| "name": "mustache", | |||||
| "version": "3.0.1", | |||||
| "name": "terun-mustache", | |||||
| "version": "3.0.3", | |||||
| "description": "Logic-less {{mustache}} templates with JavaScript", | "description": "Logic-less {{mustache}} templates with JavaScript", | ||||
| "author": "mustache.js Authors <http://github.com/janl/mustache.js>", | "author": "mustache.js Authors <http://github.com/janl/mustache.js>", | ||||
| "homepage": "https://github.com/janl/mustache.js", | "homepage": "https://github.com/janl/mustache.js", | ||||
| @@ -44,7 +44,7 @@ | |||||
| "eslint": "2.5.1", | "eslint": "2.5.1", | ||||
| "jshint": "^2.9.5", | "jshint": "^2.9.5", | ||||
| "mocha": "^3.0.2", | "mocha": "^3.0.2", | ||||
| "uglify-js": "^3.4.6", | |||||
| "uglify-js": "^3.4.6" | |||||
| "zuul": "^3.11.0", | "zuul": "^3.11.0", | ||||
| "zuul-ngrok": "nolanlawson/zuul-ngrok#patch-1" | "zuul-ngrok": "nolanlawson/zuul-ngrok#patch-1" | ||||
| }, | }, | ||||
| @@ -0,0 +1 @@ | |||||
| Howdy LeBron, CLI rox | |||||
| @@ -0,0 +1,34 @@ | |||||
| ({ | |||||
| name: 'name', | |||||
| job: { | |||||
| name: 'Developer' | |||||
| }, | |||||
| attributes:[ | |||||
| { | |||||
| name: 'good', | |||||
| options: [ | |||||
| 'outgoing', | |||||
| 'shy' | |||||
| ] | |||||
| } | |||||
| ], | |||||
| numbers:[1,2,3], | |||||
| sumOne:(value)=>{ | |||||
| return value + 1; | |||||
| }, | |||||
| upper:(value)=>{ | |||||
| return value.toUpperCase() | |||||
| }, | |||||
| lower: (value)=>{ | |||||
| return value.toLowerCase() | |||||
| }, | |||||
| firstUpper:(value) =>{ | |||||
| value = value.split('') | |||||
| value[0] = value[0].toUpperCase() | |||||
| value = value.join('') | |||||
| return value; | |||||
| }, | |||||
| setNameFuncion:(value)=>{ | |||||
| return value + ": This is a value" | |||||
| } | |||||
| }) | |||||
| @@ -0,0 +1,57 @@ | |||||
| -- Use | | |||||
| {{name | upper}} | |||||
| {{name |upper}} | |||||
| {{name| upper}} | |||||
| {{name|upper}} | |||||
| {{name|underscore}} | |||||
| {{name|underscore }} | |||||
| {{name|lower}} | |||||
| {{name | lower}} | |||||
| {{name |lower}} | |||||
| {{name |lower | upper}} | |||||
| {{name |lower | upper | lower | upper}} | |||||
| {{name |lower | firstUpper}} | |||||
| {{name | upper | firstUpper}} | |||||
| {{job.name | upper}} | |||||
| {{job.name | lower | firstUpper}} | |||||
| {{#numbers}} | |||||
| {{. | sumOne}} | |||||
| {{/numbers}} | |||||
| {{#numbers}} | |||||
| {{. | sumOne | setNameFuncion}} | |||||
| {{/numbers}} | |||||
| {{#numbers}} | |||||
| {{. | sumOne | setNameFuncion | lower}} | |||||
| {{/numbers}} | |||||
| -- Use |> | |||||
| {{name |> upper}} | |||||
| {{name |>upper}} | |||||
| {{name|> upper}} | |||||
| {{name|>upper}} | |||||
| {{name|>underscore}} | |||||
| {{name|>underscore }} | |||||
| {{name|>lower}} | |||||
| {{name |> lower}} | |||||
| {{name |>lower}} | |||||
| {{name |>lower |> upper}} | |||||
| {{name |>lower |> upper |> lower |> upper}} | |||||
| {{name |>lower |> firstUpper}} | |||||
| {{name |> upper |> firstUpper}} | |||||
| {{job.name |> upper}} | |||||
| {{job.name |> lower |> firstUpper}} | |||||
| {{#numbers}} | |||||
| {{. |> sumOne}} | |||||
| {{/numbers}} | |||||
| {{#numbers}} | |||||
| {{. |> sumOne |> setNameFuncion}} | |||||
| {{/numbers}} | |||||
| {{#numbers}} | |||||
| {{. |> sumOne |> setNameFuncion |> lower}} | |||||
| {{/numbers}} | |||||
| -- Level Array | |||||
| {{#attributes}} | |||||
| {{#options}} | |||||
| {{name |> upper}} | |||||
| {{. |> upper}} | |||||
| {{/options}} | |||||
| {{/attributes}} | |||||
| @@ -0,0 +1,55 @@ | |||||
| -- Use | | |||||
| NAME | |||||
| NAME | |||||
| NAME | |||||
| NAME | |||||
| name | |||||
| name | |||||
| name | |||||
| name | |||||
| name | |||||
| NAME | |||||
| NAME | |||||
| Name | |||||
| NAME | |||||
| DEVELOPER | |||||
| Developer | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 2: This is a value | |||||
| 3: This is a value | |||||
| 4: This is a value | |||||
| 2: this is a value | |||||
| 3: this is a value | |||||
| 4: this is a value | |||||
| -- Use |> | |||||
| NAME | |||||
| NAME | |||||
| NAME | |||||
| NAME | |||||
| name | |||||
| name | |||||
| name | |||||
| name | |||||
| name | |||||
| NAME | |||||
| NAME | |||||
| Name | |||||
| NAME | |||||
| DEVELOPER | |||||
| Developer | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 2: This is a value | |||||
| 3: This is a value | |||||
| 4: This is a value | |||||
| 2: this is a value | |||||
| 3: this is a value | |||||
| 4: this is a value | |||||
| -- Level Array | |||||
| GOOD | |||||
| OUTGOING | |||||
| GOOD | |||||
| SHY | |||||