-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for interpolation in html attributes
- Loading branch information
Evan You
committed
Jan 6, 2014
1 parent
354f559
commit a2e287f
Showing
9 changed files
with
161 additions
and
86 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,22 +1,36 @@ | ||
var BINDING_RE = /\{\{(.+?)\}\}/ | ||
|
||
module.exports = { | ||
/** | ||
* Parse a piece of text, return an array of tokens | ||
*/ | ||
function parse (text) { | ||
if (!BINDING_RE.test(text)) return null | ||
var m, i, tokens = [] | ||
/* jshint boss: true */ | ||
while (m = text.match(BINDING_RE)) { | ||
i = m.index | ||
if (i > 0) tokens.push(text.slice(0, i)) | ||
tokens.push({ key: m[1].trim() }) | ||
text = text.slice(i + m[0].length) | ||
} | ||
if (text.length) tokens.push(text) | ||
return tokens | ||
} | ||
|
||
/** | ||
* Parse a piece of text, return an array of tokens | ||
*/ | ||
parse: function (text) { | ||
if (!BINDING_RE.test(text)) return null | ||
var m, i, tokens = [] | ||
/* jshint boss: true */ | ||
while (m = text.match(BINDING_RE)) { | ||
i = m.index | ||
if (i > 0) tokens.push(text.slice(0, i)) | ||
tokens.push({ key: m[1].trim() }) | ||
text = text.slice(i + m[0].length) | ||
} | ||
if (text.length) tokens.push(text) | ||
return tokens | ||
/** | ||
* Parse an attribute value with possible interpolation tags | ||
* return a Directive-friendly expression | ||
*/ | ||
function parseAttr (attr) { | ||
var tokens = parse(attr) | ||
if (!tokens) return null | ||
var res = [], token | ||
for (var i = 0, l = tokens.length; i < l; i++) { | ||
token = tokens[i] | ||
res.push(token.key || ('"' + token + '"')) | ||
} | ||
|
||
} | ||
return res.join('+') | ||
} | ||
|
||
exports.parse = parse | ||
exports.parseAttr = parseAttr |
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
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
Oops, something went wrong.