Selaa lähdekoodia

Merge a5920c37b3 into 1c4187ab31

pull/691/merge
Raphael Kieling GitHub 6 vuotta sitten
vanhempi
commit
baa74f382f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 muutettua tiedostoa jossa 184 lisäystä ja 5 poistoa
  1. +33
    -1
      mustache.js
  2. +1
    -1
      mustache.min.js
  3. +3
    -3
      package.json
  4. +1
    -0
      test/_files/cli_output.txt
  5. +34
    -0
      test/_files/pipeline.js
  6. +57
    -0
      test/_files/pipeline.mustache
  7. +55
    -0
      test/_files/pipeline.txt

+ 33
- 1
mustache.js Näytä tiedosto

@@ -92,6 +92,7 @@
var equalsRe = /\s*=/;
var curlyRe = /\s*\}/;
var tagRe = /#|\^|\/|>|\{|&|=|!/;
var pipelineRe = /\|\>?/;

/**
* Breaks up the given `template` string into a tree of tokens. If the `tags`
@@ -397,13 +398,39 @@
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
* up the context hierarchy if the value is absent in this context's view.
*/
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;
if (cache.hasOwnProperty(name)) {
value = cache[name];
@@ -478,9 +505,14 @@
cache[name] = value;
}


if (isFunction(value))
value = value.call(this.view);

if (pipelines){
value = this.resolvePipelineOperator(value, pipelines);
}

return value;
};



+ 1
- 1
mustache.min.js
File diff suppressed because it is too large
Näytä tiedosto


+ 3
- 3
package.json Näytä tiedosto

@@ -1,6 +1,6 @@
{
"name": "mustache",
"version": "3.0.1",
"name": "terun-mustache",
"version": "3.0.3",
"description": "Logic-less {{mustache}} templates with JavaScript",
"author": "mustache.js Authors <http://github.com/janl/mustache.js>",
"homepage": "https://github.com/janl/mustache.js",
@@ -44,7 +44,7 @@
"eslint": "2.5.1",
"jshint": "^2.9.5",
"mocha": "^3.0.2",
"uglify-js": "^3.4.6",
"uglify-js": "^3.4.6"
"zuul": "^3.11.0",
"zuul-ngrok": "nolanlawson/zuul-ngrok#patch-1"
},


+ 1
- 0
test/_files/cli_output.txt Näytä tiedosto

@@ -0,0 +1 @@
Howdy LeBron, CLI rox

+ 34
- 0
test/_files/pipeline.js Näytä tiedosto

@@ -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"
}
})

+ 57
- 0
test/_files/pipeline.mustache Näytä tiedosto

@@ -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}}

+ 55
- 0
test/_files/pipeline.txt Näytä tiedosto

@@ -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

Loading…
Peruuta
Tallenna