|
|
@@ -8,6 +8,46 @@ var KEY_RE = /^[^\|<]+/,
|
|
|
FILTER_TOKEN_RE = /[^\s']+|'[^']+'/g,
|
|
|
DEPS_RE = /<[^<\|]+/g
|
|
|
|
|
|
+// parse a key, extract argument and nesting/root info
|
|
|
+function parseKey (rawKey) {
|
|
|
+
|
|
|
+ var res = {},
|
|
|
+ argMatch = rawKey.match(ARG_RE)
|
|
|
+
|
|
|
+ res.key = argMatch
|
|
|
+ ? argMatch[2].trim()
|
|
|
+ : rawKey.trim()
|
|
|
+
|
|
|
+ res.arg = argMatch
|
|
|
+ ? argMatch[1].trim()
|
|
|
+ : null
|
|
|
+
|
|
|
+ var nesting = res.key.match(/^\^+/)
|
|
|
+ res.nesting = nesting
|
|
|
+ ? nesting[0].length
|
|
|
+ : false
|
|
|
+
|
|
|
+ res.root = res.key.charAt(0) === '$'
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+function parseFilter (filter) {
|
|
|
+
|
|
|
+ var tokens = filter.slice(1)
|
|
|
+ .match(FILTER_TOKEN_RE)
|
|
|
+ .map(function (token) {
|
|
|
+ return token.replace(/'/g, '').trim()
|
|
|
+ })
|
|
|
+
|
|
|
+ return {
|
|
|
+ name : tokens[0],
|
|
|
+ apply : filters[tokens[0]],
|
|
|
+ args : tokens.length > 1
|
|
|
+ ? tokens.slice(1)
|
|
|
+ : null
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
function Directive (directiveName, expression) {
|
|
|
|
|
|
var directive = directives[directiveName]
|
|
|
@@ -26,41 +66,22 @@ function Directive (directiveName, expression) {
|
|
|
this.directiveName = directiveName
|
|
|
this.expression = expression
|
|
|
|
|
|
- var rawKey = expression.match(KEY_RE)[0], // guarded in parse
|
|
|
- argMatch = rawKey.match(ARG_RE)
|
|
|
-
|
|
|
- this.key = argMatch
|
|
|
- ? argMatch[2].trim()
|
|
|
- : rawKey.trim()
|
|
|
+ var rawKey = expression.match(KEY_RE)[0],
|
|
|
+ keyInfo = parseKey(rawKey)
|
|
|
|
|
|
- this.arg = argMatch
|
|
|
- ? argMatch[1].trim()
|
|
|
- : null
|
|
|
+ for (var prop in keyInfo) {
|
|
|
+ this[prop] = keyInfo[prop]
|
|
|
+ }
|
|
|
|
|
|
var filterExps = expression.match(FILTERS_RE)
|
|
|
- if (filterExps) {
|
|
|
- this.filters = filterExps.map(function (filter) {
|
|
|
- var tokens = filter.slice(1)
|
|
|
- .match(FILTER_TOKEN_RE)
|
|
|
- .map(function (token) {
|
|
|
- return token.replace(/'/g, '').trim()
|
|
|
- })
|
|
|
- return {
|
|
|
- name : tokens[0],
|
|
|
- apply : filters[tokens[0]],
|
|
|
- args : tokens.length > 1
|
|
|
- ? tokens.slice(1)
|
|
|
- : null
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.filters = null
|
|
|
- }
|
|
|
+ this.filters = filterExps
|
|
|
+ ? filterExps.map(parseFilter)
|
|
|
+ : null
|
|
|
|
|
|
var depExp = expression.match(DEPS_RE)
|
|
|
- if (depExp) {
|
|
|
- this.deps = depExp[0].slice(1).trim().split(/\s+/)
|
|
|
- }
|
|
|
+ this.deps = depExp
|
|
|
+ ? depExp[0].slice(1).trim().split(/\s+/).map(parseKey)
|
|
|
+ : null
|
|
|
}
|
|
|
|
|
|
Directive.prototype.update = function (value) {
|