Permalink
Browse files

support variable name like @rid_child

  • Loading branch information...
1 parent 6fe7cb8 commit 99e8740d41c4eae8a5839b816b339145ebb3e5ae @kinogam committed Jan 23, 2013
Showing with 22 additions and 6 deletions.
  1. +1 −1 lib/kino.razor.js
  2. +1 −1 lib/kino.razor.min.js
  3. +20 −4 test/kino.razor.test.js
View
@@ -58,7 +58,7 @@
//正则集合
var RegexCollection = {
VariableFirstChar: /^[\(_a-zA-Z]/,
- Variable: /^(?:(?:\()(?:new\s+)?[a-zA-Z0-9]+(?:\.|[-\+*\/^=<>?:]|[\[\(][^\]\)]*[\]\)]|[a-zA-Z0-9]+)*(?:\))|(?:new\s+)?[a-zA-Z0-9]+(?:\.|[\[\(][^\]\)]*[\]\)]|[a-zA-Z0-9]+)*)/,
+ Variable: /^(?:(?:\()(?:new\s+)?[_a-zA-Z0-9]+(?:\.|[-\+*\/^=<>?:]|[\[\(][^\]\)]*[\]\)]|[_a-zA-Z0-9]+)*(?:\))|(?:new\s+)?[_a-zA-Z0-9]+(?:\.|[\[\(][^\]\)]*[\]\)]|[_a-zA-Z0-9]+)*)/,
ConditionAndLoop: /^(?:if|for|while)\s*\(/,
ElseCondition: /^[\s\r\n\t]*else(?:\s*{|[\s\t]+if\()?/
};
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -118,10 +118,7 @@ test("It should use new XXX() as variable", function () {
equal(/^now\sis\s\d+$/.test(str), true);
});
-test("fix bug with ')'", function () {
- var str = kino.razor("Address:(@Address)", { Address: "test load" });
- equal(str, "Address:(test load)");
-});
+
test("use custom symbol instead of '@'", function () {
kino.razor.use("&");
@@ -144,3 +141,22 @@ test("@(i) style should support operation", function () {
var str = kino.razor("@(i+1)", { i: 1 });
equal(str, "2");
});
+
+
+module("bug fix", {
+ setup: function () {
+ kino.razor.use("@");
+ }
+});
+
+
+test("fix bug with ')'", function () {
+ var str = kino.razor("Address:(@Address)", { Address: "test load" });
+ equal(str, "Address:(test load)");
+});
+
+test("support variable name like @rid_child", function () {
+ var templateStr = "@{var r_child_id = 'rid_1';}<hello>@r_child_id</hello>";
+ var result = kino.razor(templateStr, {});
+ equal(result, "<hello>rid_1</hello>");
+});

0 comments on commit 99e8740

Please sign in to comment.