Permalink
Browse files

Commit rest of files forgotten in last commit

  • Loading branch information...
1 parent f50d412 commit b5dcde98b1bcd2deef2f9eaf51613aeb2e74ed5d @ianb committed Aug 31, 2011
View
@@ -5,6 +5,7 @@ var sys = require('sys');
var string_utils = require('../utils/string');
var html = require('../utils/html');
var iter = require('../utils/iter');
+var mixin = require('../utils/mixin').mixin;
function normalize(value) {
if (typeof value !== 'string') { return value; }
@@ -26,7 +27,7 @@ function Token(type, contents) {
this.contents = contents;
}
-process.mixin(Token.prototype, {
+mixin(Token.prototype, {
split_contents: function () {
return string_utils.smart_split(this.contents);
}
@@ -59,7 +60,7 @@ function tokenize(input) {
var res = consume_until("{{", "{%");
if (res[0]) { token_list.push( new Token('text', res[0]) ); }
-
+
if (res[1] === "{{") { return variable_tag; }
if (res[1] === "{%") { return template_tag; }
return undefined;
@@ -128,7 +129,7 @@ var FilterExpression = function (expression, constant) {
if (parsed.constant !== undefined) { this.constant = normalize(parsed.constant); }
if (parsed.variable !== undefined) { this.variable = normalize(parsed.variable); }
- if (parsed.filter_name) {
+ if (parsed.filter_name) {
this.filter_list.push( this.make_filter_token(parsed) );
}
@@ -141,7 +142,7 @@ var FilterExpression = function (expression, constant) {
};
-process.mixin(FilterExpression.prototype, {
+mixin(FilterExpression.prototype, {
consume: function (expression) {
var m = filter_re.exec(expression);
@@ -239,10 +240,10 @@ function make_nodelist() {
return node_list;
}
-process.mixin(Parser.prototype, {
+mixin(Parser.prototype, {
parse: function () {
-
+
var stoppers = Array.prototype.slice.apply(arguments);
var node_list = make_nodelist();
var token = this.token_list[0];
@@ -304,7 +305,7 @@ function Context(o) {
this.filters = require('./template_defaults').filters;
}
-process.mixin(Context.prototype, {
+mixin(Context.prototype, {
get: function (name) {
if (typeof name !== 'string') { return name; }
@@ -331,7 +332,7 @@ process.mixin(Context.prototype, {
if (typeof val === 'function') {
return val();
- } else {
+ } else {
return val;
}
}
@@ -358,7 +359,7 @@ function Template(input) {
this.node_list = parser.parse();
}
-process.mixin(Template.prototype, {
+mixin(Template.prototype, {
render: function (o, callback) {
if (!callback) { throw 'template.render() must be called with a callback'; }
@@ -1,6 +1,7 @@
var sys = require('sys');
-process.mixin(GLOBAL, require('../utils/test').dsl);
-process.mixin(GLOBAL, require('./template'));
+var mixin = require('../utils/mixin').mixin;
+mixin(GLOBAL, require('../utils/test').dsl);
+mixin(GLOBAL, require('./template'));
testcase('Test tokenizer');
test('sanity test', function () {
@@ -27,7 +28,7 @@ testcase('Test tokenizer');
testcase('Filter Expression tests');
test('should parse valid syntax', function () {
- assertEquals(
+ assertEquals(
{ variable: 'item', filter_list: [ { name: 'add' } ] },
new FilterExpression("item|add")
);
@@ -3,11 +3,12 @@
var sys = require('sys');
var string_utils = require('../utils/string');
+var mixin = require('../utils/mixin').mixin;
var date_utils = require('../utils/date');
var html = require('../utils/html');
var iter = require('../utils/iter');
-process.mixin(GLOBAL, require('../utils/tags'));
+mixin(GLOBAL, require('../utils/tags'));
/* TODO: Missing filters
@@ -28,7 +29,7 @@ Missing tags:
NOTE:
cycle tag does not support legacy syntax (row1,row2,row3)
load takes a path - like require. Loaded module must expose tags and filters objects.
- url tag relies on app being set in process.djangode_urls
+ url tag relies on app being set in process.djangode_urls
*/
var filters = exports.filters = {
@@ -198,7 +199,7 @@ var filters = exports.filters = {
slice: function (value, arg) {
if (!(value instanceof Array)) { return []; }
var parts = (arg || '').split(/:/g);
-
+
if (parts[1] === '') {
parts[1] = value.length;
}
@@ -325,7 +326,7 @@ var nodes = exports.nodes = {
context.set('forloop', forloop);
function inner(p, c, idx, list, next) {
- process.mixin(forloop, {
+ mixin(forloop, {
counter: idx + 1,
counter0: idx,
revcounter: list.length - idx,
@@ -501,7 +502,7 @@ var nodes = exports.nodes = {
},
FirstOfNode: function (/*...*/) {
-
+
var choices = Array.prototype.slice.apply(arguments);
return function (context, callback) {
@@ -544,7 +545,7 @@ var nodes = exports.nodes = {
LoadNode: function (path, package) {
return function (context, callback) {
- process.mixin(context.filters, package.filters);
+ mixin(context.filters, package.filters);
callback(false, '');
}
},
@@ -613,7 +614,7 @@ var nodes = exports.nodes = {
var url = string_utils.regex_to_string(match, replacements.map(function (x) { return context.get(x); }));
if (url[0] !== '/') { url = '/' + url; }
-
+
if (item_name) {
context.set( item_name, url);
callback(false, '');
@@ -638,7 +639,7 @@ var tags = exports.tags = {
},
'for': function (parser, token) {
-
+
var parts = get_args_from_token(token, { exclude: 2, mustbe: { 2: 'in', 4: 'reversed'} });
var itemname = parts[0],
@@ -653,7 +654,7 @@ var tags = exports.tags = {
return nodes.ForNode(node_list, empty_list, itemname, listname, isReversed);
},
-
+
'if': function (parser, token) {
var parts = token.split_contents();
@@ -686,7 +687,7 @@ var tags = exports.tags = {
}
var node_list, else_list;
-
+
node_list = parser.parse('else', 'end' + token.type);
if (parser.next_token().type === 'else') {
else_list = parser.parse('end' + token.type);
@@ -700,7 +701,7 @@ var tags = exports.tags = {
var parts = get_args_from_token(token);
var node_list, else_list;
-
+
node_list = parser.parse('else', 'end' + token.type);
if (parser.next_token().type === 'else') {
else_list = parser.parse('end' + token.type);
@@ -714,7 +715,7 @@ var tags = exports.tags = {
var parts = get_args_from_token(token, { argcount: 2 });
var node_list, else_list;
-
+
node_list = parser.parse('else', 'end' + token.type);
if (parser.next_token().type === 'else') {
else_list = parser.parse('end' + token.type);
@@ -728,7 +729,7 @@ var tags = exports.tags = {
var parts = get_args_from_token(token, { argcount: 2 });
var node_list, else_list;
-
+
node_list = parser.parse('else', 'end' + token.type);
if (parser.next_token().type === 'else') {
else_list = parser.parse('end' + token.type);
@@ -787,7 +788,7 @@ var tags = exports.tags = {
parser.delete_first_token();
return nodes.AutoescapeNode(node_list, parts[0]);
},
-
+
'block': function (parser, token) {
var parts = get_args_from_token(token, { argcount: 1 });
var node_list = parser.parse('end' + token.type);
@@ -805,7 +806,7 @@ var tags = exports.tags = {
parser.delete_first_token();
return nodes.WithNode(node_list, parts[0], parts[1], parts[2]);
},
-
+
'now': simple_tag(nodes.NowNode, { argcount: 1 }),
'include': simple_tag(nodes.IncludeNode, { argcount: 1 }),
'load': function (parser, token) {
@@ -816,7 +817,7 @@ var tags = exports.tags = {
}
var package = require(name);
- process.mixin(parser.tags, package.tags);
+ mixin(parser.tags, package.tags);
return nodes.LoadNode(name, package);
},
@@ -1,9 +1,10 @@
var sys = require('sys');
var fs = require('fs');
var template = require('./template');
+var mixin = require('../utils/mixin').mixin;
-process.mixin(GLOBAL, require('../utils/test').dsl);
-process.mixin(GLOBAL, require('./template_defaults'));
+mixin(GLOBAL, require('../utils/test').dsl);
+mixin(GLOBAL, require('./template_defaults'));
function write_file(path, content) {
var file = fs.openSync(path, process.O_WRONLY | process.O_TRUNC | process.O_CREAT, 0666);
@@ -67,7 +68,7 @@ testcase('variable')
testcase('ifnode')
- setup(function () { return { obj: {a: true, b: false }}; });
+ setup(function () { return { obj: {a: true, b: false }}; });
make_parse_and_execute_test('hest', '{% if a %}hest{% endif %}');
make_parse_and_execute_test('', '{% if b %}hest{% endif %}');
@@ -84,12 +85,12 @@ testcase('comment')
make_parse_and_execute_test('', '{% comment %} do not parse {% hest %} any of this{% endcomment %}');
testcase('cycle')
- setup(function () { return { obj: { c: 'C', items: [1,2,3,4,5,6,7,8,9] }}; });
+ setup(function () { return { obj: { c: 'C', items: [1,2,3,4,5,6,7,8,9] }}; });
make_parse_and_execute_test('a1 b2 C3 a4 b5 C6 a7 b8 C9 ',
'{% for item in items %}{% cycle \'a\' "b" c %}{{ item }} {% endfor %}');
- make_parse_and_execute_test('a H b J c H a',
- '{% cycle "a" "b" "c" as tmp %} {% cycle "H" "J" as tmp2 %} ' +
+ make_parse_and_execute_test('a H b J c H a',
+ '{% cycle "a" "b" "c" as tmp %} {% cycle "H" "J" as tmp2 %} ' +
'{% cycle tmp %} {% cycle tmp2 %} {% cycle tmp %} {% cycle tmp2 %} {%cycle tmp %}',
'should work with as tag'
);
@@ -106,7 +107,7 @@ testcase('block and extend')
write_file('/tmp/block_test_1.html', 'Joel is a slug');
write_file('/tmp/block_test_2.html', 'Her er en dejlig {% block test %}hest{% endblock %}.');
write_file('/tmp/block_test_3.html',
- '{% block test1 %}hest{% endblock %}.'
+ '{% block test1 %}hest{% endblock %}.'
+ '{% block test2 %} noget {% endblock %}'
);
write_file('/tmp/block_test_4.html',
@@ -172,7 +173,7 @@ testcase('with')
var t = template.parse('{% with test.sub.func as tmp %}{{ tmp }}:{{ tmp }}{% endwith %}');
var cnt = 0;
var o = { test: { sub: { func: function () { cnt++; return cnt; } } } }
-
+
t.render(o, function (error, result) {
if (error) {
fail( error, complete );
@@ -185,7 +186,7 @@ testcase('with')
});
testcase('ifchanged')
- setup(function () { return {obj: { list:['hest','giraf','giraf','hestgiraf'] }}; });
+ setup(function () { return {obj: { list:['hest','giraf','giraf','hestgiraf'] }}; });
make_parse_and_execute_test('hestgirafhestgiraf',
'{% for item in list %}{% ifchanged %}{{ item }}{% endifchanged %}{%endfor%}'
);
@@ -194,7 +195,7 @@ testcase('ifchanged')
);
testcase('ifequal')
- setup(function () { return {obj:{item: 'hest', other: 'hest', fish: 'laks' } }; });
+ setup(function () { return {obj:{item: 'hest', other: 'hest', fish: 'laks' } }; });
make_parse_and_execute_test('giraf', '{% ifequal "hest" "hest" %}giraf{%endifequal %}');
make_parse_and_execute_test('giraf', '{% ifequal item "hest" %}giraf{%endifequal %}');
@@ -203,7 +204,7 @@ testcase('ifequal')
make_parse_and_execute_test('tapir', '{% ifequal item fish %}giraf{% else %}tapir{%endifequal %}');
testcase('ifnotequal')
- setup(function () { return {obj:{item: 'hest', other: 'hest', fish: 'laks' } }; });
+ setup(function () { return {obj:{item: 'hest', other: 'hest', fish: 'laks' } }; });
make_parse_and_execute_test('laks', '{% ifnotequal "hest" "giraf" %}laks{%endifnotequal %}');
make_parse_and_execute_test('laks', '{% ifnotequal item "giraf" %}laks{%endifnotequal %}');
@@ -221,7 +222,7 @@ testcase('now')
t.render({}, function (error, result) {
if (error) {
fail(error, complete);
- } else {
+ } else {
assertEquals(expected, result, complete);
}
end_async_test(complete);
@@ -262,7 +263,7 @@ testcase('spaceless')
'{% spaceless %}<p>\n <a href="foo/">Foo</a>\n </p>{% endspaceless %}');
testcase('widthratio')
- setup(function () { return {obj:{this_value: 175, max_value: 200 } }; });
+ setup(function () { return {obj:{this_value: 175, max_value: 200 } }; });
make_parse_and_execute_test('88', '{% widthratio this_value max_value 100 %}');
testcase('regroup')
@@ -284,7 +285,7 @@ testcase('regroup')
'<li>Male:<ul><li>George Bush</li><li>Bill Clinton</li></ul></li>' +
'<li>Female:<ul><li>Margaret Thatcher</li><li>Condoleezza Rice</li></ul></li>' +
'<li>Unknown:<ul><li>Pat Smith</li></ul></li></ul>',
- '{% regroup people by gender as gender_list %}' +
+ '{% regroup people by gender as gender_list %}' +
'<ul>{% for gender in gender_list %}<li>{{ gender.grouper }}:' +
'<ul>{% for item in gender.list %}<li>{{ item.first_name }} {{ item.last_name }}</li>{% endfor %}' +
'</ul></li>{% endfor %}</ul>');
Oops, something went wrong. Retry.

0 comments on commit b5dcde9

Please sign in to comment.