-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecb46ab
commit e0a8151
Showing
24 changed files
with
13,056 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/*can-stache@3.13.2#expressions/arg*/ | ||
define(function (require, exports, module) { | ||
var Arg = function (expression, modifiers) { | ||
this.expr = expression; | ||
this.modifiers = modifiers || {}; | ||
this.isCompute = false; | ||
}; | ||
Arg.prototype.value = function () { | ||
return this.expr.value.apply(this.expr, arguments); | ||
}; | ||
module.exports = Arg; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/*can-stache@3.13.2#expressions/bracket*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'../src/expression-helpers' | ||
], function (require, exports, module) { | ||
var expressionHelpers = require('../src/expression-helpers'); | ||
var Bracket = function (key, root) { | ||
this.root = root; | ||
this.key = key; | ||
}; | ||
Bracket.prototype.value = function (scope, helpers) { | ||
var root = this.root ? this.root.value(scope, helpers) : scope.peek('.'); | ||
return expressionHelpers.getObservableValue_fromDynamicKey_fromObservable(this.key.value(scope, helpers), root, scope, helpers, {}); | ||
}; | ||
module.exports = Bracket; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*can-stache@3.13.2#expressions/call*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-view-scope', | ||
'./hashes', | ||
'../src/set-identifier', | ||
'can-compute', | ||
'can-reflect', | ||
'can-symbol', | ||
'can-util/js/assign', | ||
'can-util/js/is-empty-object', | ||
'../src/expression-helpers' | ||
], function (require, exports, module) { | ||
var Scope = require('can-view-scope'); | ||
var Hashes = require('./hashes'); | ||
var SetIdentifier = require('../src/set-identifier'); | ||
var compute = require('can-compute'); | ||
var canReflect = require('can-reflect'); | ||
var canSymbol = require('can-symbol'); | ||
var assign = require('can-util/js/assign'); | ||
var isEmptyObject = require('can-util/js/is-empty-object'); | ||
var expressionHelpers = require('../src/expression-helpers'); | ||
var Call = function (methodExpression, argExpressions) { | ||
this.methodExpr = methodExpression; | ||
this.argExprs = argExpressions.map(expressionHelpers.convertToArgExpression); | ||
}; | ||
Call.prototype.args = function (scope, helperOptions) { | ||
var hashExprs = {}; | ||
var args = []; | ||
for (var i = 0, len = this.argExprs.length; i < len; i++) { | ||
var arg = this.argExprs[i]; | ||
if (arg.expr instanceof Hashes) { | ||
assign(hashExprs, arg.expr.hashExprs); | ||
} | ||
var value = arg.value.apply(arg, arguments); | ||
args.push({ | ||
call: !arg.modifiers || !arg.modifiers.compute, | ||
value: value | ||
}); | ||
} | ||
return function () { | ||
var finalArgs = []; | ||
if (!isEmptyObject(hashExprs)) { | ||
finalArgs.hashExprs = hashExprs; | ||
} | ||
for (var i = 0, len = args.length; i < len; i++) { | ||
finalArgs[i] = args[i].call ? canReflect.getValue(args[i].value) : expressionHelpers.toCompute(args[i].value); | ||
} | ||
return finalArgs; | ||
}; | ||
}; | ||
Call.prototype.value = function (scope, helperScope, helperOptions) { | ||
var method = this.methodExpr.value(scope, helperScope); | ||
var isHelper = this.isHelper = this.methodExpr.isHelper; | ||
var getArgs = this.args(scope, helperScope); | ||
var computeValue = compute(function (newVal) { | ||
var func = canReflect.getValue(method); | ||
if (typeof func === 'function') { | ||
var args = getArgs(); | ||
if (isHelper && helperOptions) { | ||
helperOptions.helpers = helperOptions.helpers || new Scope.Options({}); | ||
if (args.hashExprs && helperOptions.exprData) { | ||
helperOptions.exprData.hashExprs = args.hashExprs; | ||
} | ||
args.push(helperOptions); | ||
} | ||
if (arguments.length) { | ||
args.unshift(new SetIdentifier(newVal)); | ||
} | ||
return func.apply(null, args); | ||
} | ||
}); | ||
compute.temporarilyBind(computeValue); | ||
return computeValue; | ||
}; | ||
Call.prototype.closingTag = function () { | ||
return this.methodExpr.key; | ||
}; | ||
module.exports = Call; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*can-stache@3.13.2#expressions/hashes*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-reflect', | ||
'can-compute', | ||
'../src/expression-helpers' | ||
], function (require, exports, module) { | ||
var canReflect = require('can-reflect'); | ||
var compute = require('can-compute'); | ||
var expressionHelpers = require('../src/expression-helpers'); | ||
var Hashes = function (hashes) { | ||
this.hashExprs = hashes; | ||
}; | ||
Hashes.prototype.value = function (scope, helperOptions) { | ||
var hash = {}; | ||
for (var prop in this.hashExprs) { | ||
var val = expressionHelpers.convertToArgExpression(this.hashExprs[prop]), value = val.value.apply(val, arguments); | ||
hash[prop] = { | ||
call: !val.modifiers || !val.modifiers.compute, | ||
value: value | ||
}; | ||
} | ||
return compute(function () { | ||
var finalHash = {}; | ||
for (var prop in hash) { | ||
finalHash[prop] = hash[prop].call ? canReflect.getValue(hash[prop].value) : expressionHelpers.toComputeOrValue(hash[prop].value); | ||
} | ||
return finalHash; | ||
}); | ||
}; | ||
module.exports = Hashes; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*can-stache@3.13.2#expressions/helper-lookup*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'./lookup', | ||
'../src/lookup-value-or-helper' | ||
], function (require, exports, module) { | ||
var Lookup = require('./lookup'); | ||
var lookupValueOrHelper = require('../src/lookup-value-or-helper'); | ||
var HelperLookup = function () { | ||
Lookup.apply(this, arguments); | ||
}; | ||
HelperLookup.prototype.value = function (scope, helperOptions) { | ||
var result = lookupValueOrHelper(this.key, scope, helperOptions, { | ||
isArgument: true, | ||
args: [ | ||
scope.peek('.'), | ||
scope | ||
] | ||
}); | ||
return result.helper || result.value; | ||
}; | ||
module.exports = HelperLookup; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*can-stache@3.13.2#expressions/helper-scope-lookup*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'./lookup', | ||
'../src/expression-helpers' | ||
], function (require, exports, module) { | ||
var Lookup = require('./lookup'); | ||
var expressionHelpers = require('../src/expression-helpers'); | ||
var HelperScopeLookup = function () { | ||
Lookup.apply(this, arguments); | ||
}; | ||
HelperScopeLookup.prototype.value = function (scope, helperOptions) { | ||
return expressionHelpers.getObservableValue_fromKey(this.key, scope, { | ||
callMethodsOnObservables: true, | ||
isArgument: true, | ||
args: [ | ||
scope.peek('.'), | ||
scope | ||
] | ||
}); | ||
}; | ||
module.exports = HelperScopeLookup; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/*can-stache@3.13.2#expressions/helper*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'./literal', | ||
'can-compute', | ||
'can-util/js/assign', | ||
'can-util/js/dev', | ||
'can-util/js/is-empty-object', | ||
'../src/expression-helpers', | ||
'../src/utils', | ||
'../helpers/core' | ||
], function (require, exports, module) { | ||
var Literal = require('./literal'); | ||
var compute = require('can-compute'); | ||
var assign = require('can-util/js/assign'); | ||
var dev = require('can-util/js/dev'); | ||
var isEmptyObject = require('can-util/js/is-empty-object'); | ||
var expressionHelpers = require('../src/expression-helpers'); | ||
var utils = require('../src/utils'); | ||
var mustacheHelpers = require('../helpers/core'); | ||
var Helper = function (methodExpression, argExpressions, hashExpressions) { | ||
this.methodExpr = methodExpression; | ||
this.argExprs = argExpressions; | ||
this.hashExprs = hashExpressions; | ||
this.mode = null; | ||
}; | ||
Helper.prototype.args = function (scope, helperOptions) { | ||
var args = []; | ||
for (var i = 0, len = this.argExprs.length; i < len; i++) { | ||
var arg = this.argExprs[i]; | ||
args.push(expressionHelpers.toComputeOrValue(arg.value.apply(arg, arguments))); | ||
} | ||
return args; | ||
}; | ||
Helper.prototype.hash = function (scope, helperOptions) { | ||
var hash = {}; | ||
for (var prop in this.hashExprs) { | ||
var val = this.hashExprs[prop]; | ||
hash[prop] = expressionHelpers.toComputeOrValue(val.value.apply(val, arguments)); | ||
} | ||
return hash; | ||
}; | ||
Helper.prototype.helperAndValue = function (scope, helperOptions) { | ||
var looksLikeAHelper = this.argExprs.length || !isEmptyObject(this.hashExprs), helper, computeData, methodKey = this.methodExpr instanceof Literal ? '' + this.methodExpr._value : this.methodExpr.key, initialValue, args; | ||
if (looksLikeAHelper) { | ||
helper = mustacheHelpers.getHelper(methodKey, helperOptions); | ||
} | ||
if (!helper) { | ||
computeData = expressionHelpers.getObservableValue_fromKey(methodKey, scope, { isArgument: true }); | ||
if (typeof computeData.initialValue === 'function') { | ||
args = this.args(scope, helperOptions).map(expressionHelpers.toComputeOrValue); | ||
var functionResult = compute(function () { | ||
return computeData.initialValue.apply(null, args); | ||
}); | ||
compute.temporarilyBind(functionResult); | ||
return { value: functionResult }; | ||
} else if (typeof computeData.initialValue !== 'undefined') { | ||
return { value: computeData }; | ||
} | ||
if (!looksLikeAHelper && initialValue === undefined) { | ||
helper = mustacheHelpers.getHelper(methodKey, helperOptions); | ||
} | ||
} | ||
return { | ||
value: computeData, | ||
args: args, | ||
helper: helper && helper.fn | ||
}; | ||
}; | ||
Helper.prototype.evaluator = function (helper, scope, helperOptions, readOptions, nodeList, truthyRenderer, falseyRenderer, stringOnly) { | ||
var helperOptionArg = { stringOnly: stringOnly }, context = scope.peek('.'), args = this.args(scope, helperOptions, nodeList, truthyRenderer, falseyRenderer, stringOnly), hash = this.hash(scope, helperOptions, nodeList, truthyRenderer, falseyRenderer, stringOnly); | ||
utils.convertToScopes(helperOptionArg, scope, helperOptions, nodeList, truthyRenderer, falseyRenderer, stringOnly); | ||
assign(helperOptionArg, { | ||
context: context, | ||
scope: scope, | ||
contexts: scope, | ||
hash: hash, | ||
nodeList: nodeList, | ||
exprData: this, | ||
helperOptions: helperOptions, | ||
helpers: helperOptions | ||
}); | ||
args.push(helperOptionArg); | ||
return function () { | ||
return helper.apply(context, args); | ||
}; | ||
}; | ||
Helper.prototype.value = function (scope, helperOptions, nodeList, truthyRenderer, falseyRenderer, stringOnly) { | ||
var helperAndValue = this.helperAndValue(scope, helperOptions); | ||
var helper = helperAndValue.helper; | ||
if (!helper) { | ||
return helperAndValue.value; | ||
} | ||
var fn = this.evaluator(helper, scope, helperOptions, nodeList, truthyRenderer, falseyRenderer, stringOnly); | ||
var computeValue = compute(fn); | ||
compute.temporarilyBind(computeValue); | ||
if (!expressionHelpers.computeHasDependencies(computeValue)) { | ||
return computeValue(); | ||
} else { | ||
return computeValue; | ||
} | ||
}; | ||
Helper.prototype.closingTag = function () { | ||
return this.methodExpr.key; | ||
}; | ||
module.exports = Helper; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/*can-stache@3.13.2#expressions/literal*/ | ||
define(function (require, exports, module) { | ||
var Literal = function (value) { | ||
this._value = value; | ||
}; | ||
Literal.prototype.value = function () { | ||
return this._value; | ||
}; | ||
module.exports = Literal; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*can-stache@3.13.2#expressions/lookup*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'../src/expression-helpers', | ||
'../src/lookup-value-or-helper' | ||
], function (require, exports, module) { | ||
var expressionHelpers = require('../src/expression-helpers'); | ||
var lookupValueOrHelper = require('../src/lookup-value-or-helper'); | ||
var Lookup = function (key, root) { | ||
this.key = key; | ||
this.rootExpr = root; | ||
}; | ||
Lookup.prototype.value = function (scope, helperOptions) { | ||
if (this.rootExpr) { | ||
return expressionHelpers.getObservableValue_fromDynamicKey_fromObservable(this.key, this.rootExpr.value(scope, helperOptions), scope, {}, {}); | ||
} else { | ||
var result = lookupValueOrHelper(this.key, scope, helperOptions); | ||
this.isHelper = result.helper && !result.helper.callAsMethod; | ||
return result.helper || result.value; | ||
} | ||
}; | ||
module.exports = Lookup; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*can-stache@3.13.2#expressions/scope-lookup*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'../src/expression-helpers', | ||
'./lookup' | ||
], function (require, exports, module) { | ||
var expressionHelpers = require('../src/expression-helpers'); | ||
var Lookup = require('./lookup'); | ||
var ScopeLookup = function (key, root) { | ||
Lookup.apply(this, arguments); | ||
}; | ||
ScopeLookup.prototype.value = function (scope, helperOptions) { | ||
if (this.rootExpr) { | ||
return expressionHelpers.getObservableValue_fromDynamicKey_fromObservable(this.key, this.rootExpr.value(scope, helperOptions), scope, {}, {}); | ||
} | ||
return expressionHelpers.getObservableValue_fromKey(this.key, scope, helperOptions); | ||
}; | ||
module.exports = ScopeLookup; | ||
}); |
Oops, something went wrong.