Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline Operator #691

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Pipeline with recursive search. To take a function with parent
  • Loading branch information
Kieling committed Feb 22, 2019
commit a5920c37b3d02aaa9993f00f8cc360e080bd1cbd
15 changes: 9 additions & 6 deletions mustache.js
Original file line number Diff line number Diff line change
@@ -383,13 +383,16 @@
Context.prototype.resolvePipelineOperator = function resolvePipelineOperator (value, pipelines){
var self = this;
var pipelineResolver = function pipelineResolver (val, func){
if (self.view.hasOwnProperty(func)){
return self.view[func](val);
} else if (self.parent && self.parent.view.hasOwnProperty(func)){
return self.parent.view[func](val);
} else {
return val;
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);
};
2 changes: 1 addition & 1 deletion mustache.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions test/_files/cli_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Howdy LeBron, CLI rox
9 changes: 9 additions & 0 deletions test/_files/pipeline.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,15 @@
job: {
name: 'Developer'
},
attributes:[
{
name: 'good',
options: [
'outgoing',
'shy'
]
}
],
numbers:[1,2,3],
sumOne:(value)=>{
return value + 1;
7 changes: 7 additions & 0 deletions test/_files/pipeline.mustache
Original file line number Diff line number Diff line change
@@ -48,3 +48,10 @@
{{#numbers}}
{{. |> sumOne |> setNameFuncion |> lower}}
{{/numbers}}
-- Level Array
{{#attributes}}
{{#options}}
{{name |> upper}}
{{. |> upper}}
{{/options}}
{{/attributes}}
5 changes: 5 additions & 0 deletions test/_files/pipeline.txt
Original file line number Diff line number Diff line change
@@ -48,3 +48,8 @@ Developer
2: this is a value
3: this is a value
4: this is a value
-- Level Array
GOOD
OUTGOING
GOOD
SHY