Permalink
Browse files

Merge tag 'v0.11.2' of git://github.com/paularmstrong/swig

* **Fixed** Update support for underscore@1.3.3 [gh-70] [gh-71]
  • Loading branch information...
andris-silis committed Apr 13, 2012
2 parents e8cfdf4 + b40f61f commit 732d3b47675cee86287bf9c98fc4e2124d55572f
Showing with 92 additions and 211 deletions.
  1. +31 −1 History.md
  2. +9 −7 Makefile
  3. +7 −8 docs/custom-tags.md
  4. +5 −6 index.js
  5. +3 −2 lib/dateformat.js
  6. +6 −7 lib/filters.js
  7. +17 −2 lib/filters.test.js
  8. +3 −3 lib/helpers.js
  9. +2 −2 lib/parser.js
  10. +7 −0 lib/parser.test.js
  11. +0 −2 lib/tags/for.js
  12. +2 −2 package.json
  13. +0 −5 scripts/config-lint.js
  14. +0 −5 scripts/config-test.js
  15. +0 −35 scripts/runlint.js
  16. +0 −124 scripts/runtests.js
View
@@ -1,5 +1,35 @@
+[0.11.2](https://github.com/paularmstrong/swig/tree/v0.11.2) / 2012-04-10
+-------------------------------------------------------------------------
+
+* **Fixed** Update support for underscore@1.3.3 [gh-70] [gh-71]
+
+[Documentation](https://github.com/paularmstrong/swig/tree/v0.11.2/docs)
+
+[0.11.1](https://github.com/paularmstrong/swig/tree/v0.11.1) / 2012-04-01
+-------------------------------------------------------------------------
+
+* **Fixed** Duplicate (string) tokens were being removed when extending a base template. [gh-67]
+
+[Documentation](https://github.com/paularmstrong/swig/tree/v0.11.1/docs)
+
+[0.11.0](https://github.com/paularmstrong/swig/tree/v0.11.0) / 2012-02-27
+-------------------------------------------------------------------------
+
+* **Added** Support for Windows style paths [gh-57]
+* **Added** `ignore missing` tokens to include tag
+* **Changed** include tag `with context` to only work if `context` is an object
+* **Changed** `autoescape` tag controls no longer 'yes' or 'no'. Use `true` and `false`
+* **Changed** parser is now passed into tags as an argument
+* **Changed** don't require passing context object when rendering template
+* **Fixed** dateformats `N` and `w` [gh-59]
+* **Fixed** number changing to string after add filter or set from variable [gh-53] [gh-58]
+* **Fixed** speed decrease caused by loop.cycle fixed
+* **Fixed** Ensure set tag bubbles through extends and blocks
+
+[Documentation](https://github.com/paularmstrong/swig/tree/v0.11.0/docs)
+
[0.10.0](https://github.com/paularmstrong/swig/tree/v0.10.0) / 2012-02-13
-------------------------------------------------------------------------
+-------------------------------------------------------------------------
* **Added** loop.index0, loop.revindex, loop.revindex0, and loop.cycle [gh-48]
* **Added** init config `extensions` for 3rd party extension access in custom tags [gh-44]
View
@@ -6,14 +6,16 @@ all:
browser:
@scripts/browser.sh
+tests := $(shell find . -name '*.test.js' ! -path "*node_modules/*" ! -path "*dist/*")
+reporter = skip_passed
test:
- @node tests/speed.js
- @node scripts/runtests.js
-
-testf:
- @node_modules/nodeunit/bin/nodeunit ${file}
+ @node_modules/nodeunit/bin/nodeunit --reporter ${reporter} ${tests}
+files := $(shell find . -name '*.js' ! -path "*node_modules/*" ! -path "*dist/*")
lint:
- @node scripts/runlint.js
+ @node_modules/nodelint/nodelint ${files} --config=scripts/config-lint.js
+
+speed:
+ @node tests/speed.js
-.PHONY: all browser test lint
+.PHONY: all browser test lint speed
View
@@ -10,14 +10,13 @@ First, make sure to include your node.js file that declares your tags in the swi
Requirements <a name="requirements" href="#requirements">#</a>
------------
-First, include the Swig parser and helpers.
+First, include the helpers.
- var parser = require('swig/lib/parser'),
- helpers = require('swig/lib/helpers');
+ var helpers = require('swig/lib/helpers');
Define your tag and whether or not it requires an "end" tag:
- exports.mytag = function (indent, parentBlock) {
+ exports.mytag = function (indent, parentBlock, parser) {
return 'output';
};
exports.mytag.ends = true;
@@ -27,15 +26,15 @@ A Really Simple Tag <a name="example" href="#example">#</a>
To parse a swig variable with or without filters into a variable token, eg. `bar` or `foo|lowercase`
- exports.mytag = function (indent, parentBlock) {
+ exports.mytag = function (indent, parentBlock, parser) {
var myArg = parser.parseVariable(this.args[0]);
return 'output';
};
exports.mytag.ends = true;
Use a parsed variable token with `helpers.setVar()` to bind a variable in your current scope into the templates scope. The `setVar` method cleans up variable output, applies filters and escaping for clean output:
- exports.mytag = function (indent, parentBlock) {
+ exports.mytag = function (indent, parentBlock, parser) {
var myArg = parser.parseVariable(this.args[0]),
output = '';
output += helpers.setVar(name, myArg);
@@ -45,7 +44,7 @@ Use a parsed variable token with `helpers.setVar()` to bind a variable in your c
To parse the inner content of a tag for outputting, use `parser.compile.apply(this, [indent, parentBlock])`:
- exports.mytag = function (indent, parentBlock) {
+ exports.mytag = function (indent, parentBlock, parser) {
var myArg = parser.parseVariable(this.args[0]),
output = [];
@@ -87,7 +86,7 @@ To access a third-party library or method that is defined outside of your templa
Once you've added it, your custom tag can reference the `i18next` extension via the `_ext` object:
- exports.trans = function (indent, parentBlock) {
+ exports.trans = function (indent, parentBlock, parser) {
var myArg = parser.parseVariable(this.args[0]),
output = [];
output.push(helpers.setVar('__myArg', myArg));
View
@@ -91,12 +91,11 @@ function createTemplate(data, id) {
template.render = function (context, parents) {
if (_config.allowErrors) {
return render.call(this, context, parents, _config.filters, _, _config.extensions);
- } else {
- try {
- return render.call(this, context, parents, _config.filters, _, _config.extensions);
- } catch (e) {
- return new TemplateError(e);
- }
+ }
+ try {
+ return render.call(this, context, parents, _config.filters, _, _config.extensions);
+ } catch (e) {
+ return new TemplateError(e);
}
};
View
@@ -112,14 +112,15 @@ exports.l = function (input) {
return _days.full[input.getDay()];
};
exports.N = function (input) {
- return input.getDay();
+ var d = input.getDay();
+ return (d >= 1) ? d + 1 : 7;
};
exports.S = function (input) {
var d = input.getDate();
return (d % 10 === 1 && d !== 11 ? 'st' : (d % 10 === 2 && d !== 12 ? 'nd' : (d % 10 === 3 && d !== 13 ? 'rd' : 'th')));
};
exports.w = function (input) {
- return input.getDay() - 1;
+ return input.getDay();
};
exports.z = function (input, offset, abbr) {
var year = input.getFullYear(),
View
@@ -99,9 +99,8 @@ exports.escape = exports.e = function (input, type) {
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
- } else {
- return input;
}
+ return input;
};
exports.first = function (input) {
@@ -119,15 +118,16 @@ exports.first = function (input) {
exports.join = function (input, separator) {
if (_.isArray(input)) {
return input.join(separator);
- } else if (typeof input === 'object') {
+ }
+
+ if (typeof input === 'object') {
var out = [];
_.each(input, function (value, key) {
out.push(value);
});
return out.join(separator);
- } else {
- return input;
}
+ return input;
};
exports.json_encode = function (input) {
@@ -171,9 +171,8 @@ exports.replace = function (input, search, replacement, flags) {
exports.reverse = function (input) {
if (_.isArray(input)) {
return input.reverse();
- } else {
- return input;
}
+ return input;
};
exports.striptags = function (input) {
View
@@ -60,9 +60,9 @@ exports.date = function (test) {
testFormat('D', 'Tue');
testFormat('j', '6');
testFormat('l', 'Tuesday');
- testFormat('N', '2');
+ testFormat('N', '3');
testFormat('S', 'th');
- testFormat('w', '1');
+ testFormat('w', '2');
testFormat('z', '248');
testFilter(test, 'date("z", 480)', { v: makeDate(480, 2011, 0, 1) }, '0', 'z');
testFilter(test, 'date("z", 480)', { v: makeDate(480, 2011, 11, 31) }, '364', 'z');
@@ -112,6 +112,21 @@ exports.date = function (test) {
testFormat('r', 'Tue, 06 Sep 2011 16:05:02 GMT');
testFormat('U', '1315325102');
+ // More complete S ordinal testing
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 1) }, 'st', 'S 1st');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 2) }, 'nd', 'S 2nd');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 3) }, 'rd', 'S 3rd');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 4) }, 'th', 'S 4th');
+ testFilter(test, 'date("w", 420)', { v: makeDate(420, 2011, 8, 4) }, '0', 'w 0');
+ testFilter(test, 'date("N", 420)', { v: makeDate(420, 2011, 8, 4) }, '7', 'N 7');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 10) }, 'th', 'S 10th');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 11) }, 'th', 'S 11th');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 12) }, 'th', 'S 12th');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 13) }, 'th', 'S 13th');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 21) }, 'st', 'S 21st');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 22) }, 'nd', 'S 22nd');
+ testFilter(test, 'date("S", 420)', { v: makeDate(420, 2011, 8, 23) }, 'rd', 'S 23rd');
+
test.done();
};
View
@@ -116,9 +116,8 @@ function check(variable, context) {
output[output.length - 1] = _.last(output).replace(/\] !== "undefined"$/, '_' + prop + '] !== "undefined"');
chain = chain.replace(/\]$/, '_' + prop + ']');
return;
- } else {
- chain += '[___' + prop + ']';
}
+ chain += '[___' + prop + ']';
} else {
chain += '[' + prop + ']';
}
@@ -149,7 +148,8 @@ exports.escapeVarName = function (variable, context) {
if (exports.isLiteral(variable)) {
return variable;
- } else if (typeof context === 'string' && context.length) {
+ }
+ if (typeof context === 'string' && context.length) {
variable = context + '.' + variable;
}
View
@@ -258,7 +258,7 @@ exports.parse = function (data, tags, autoescape) {
line: curline,
name: tagname,
compile: tags[tagname],
- parent: _.uniq(stack[stack.length - 2]),
+ parent: _.uniq(stack[stack.length - 2] || []),
strip: {
before: stripBefore,
after: stripAfter,
@@ -347,7 +347,7 @@ exports.compile = function compile(indent, parentBlock) {
if (tokens.length && tokens[0].name === 'extends') {
this.blocks = _.extend({}, this.parent.blocks, this.blocks);
- this.tokens = _.union(sets, this.parent.tokens);
+ this.tokens = sets.concat(this.parent.tokens);
}
sets = tokens = null;
}
View
@@ -396,5 +396,12 @@ exports.Compiling = testCase({
eval('var _output = "";' + parser.compile.call(template, ''));
}, 'block should throw if nested');
test.done();
+ },
+
+ 'duplicate strings are not removed when extended': function (test) {
+ var dummy = swig.compile('"{{ e }}"{{ f }}"{{ g }}"{{ h }}', { filename: 'foo' }),
+ tpl = '{% extends "foo" %}';
+ test.strictEqual(swig.compile(tpl)({ e: 'e', f: 'f', g: 'g', h: 'h' }), '"e"f"g"h', 'render extended');
+ test.done();
}
});
View
@@ -40,7 +40,6 @@ module.exports = function (indent, parentBlock, parser) {
out = '(function () {\n' +
' var loop = {}, __loopKey, __loopIndex = 0, __loopLength = 0,' +
' __ctx_operand = _context["' + operand1 + '"],\n' +
- ' __ctx_cycle = (typeof loop_cycle !== "undefined") ? loop_cycle : null,\n' +
' loop_cycle = function() {\n' +
' var args = _.toArray(arguments), i = loop.index0 % args.length;\n' +
' return args[i];\n' +
@@ -65,7 +64,6 @@ module.exports = function (indent, parentBlock, parser) {
loopShared +
' }\n' +
' }\n' +
- ' loop_cycle = __ctx_cycle;\n' +
' _context["' + operand1 + '"] = __ctx_operand;\n' +
'})();\n';
View
@@ -1,6 +1,6 @@
{
"name": "swig",
- "version": "0.10.0",
+ "version": "0.11.2",
"description": "A fast django-like templating engine for node.js and browsers.",
"keywords": ["template", "templating", "html", "django", "express", "block"],
"repository": {
@@ -31,4 +31,4 @@
"bugs": {
"url": "https://github.com/paularmstrong/swig/issues"
}
-}
+}
View
@@ -1,8 +1,3 @@
-module.exports = {
- root: __dirname + '/../',
- pathIgnore: ['*node_modules*', '*browser/underscore*', '*dist/browser/*', '*dist/test*']
-};
-
var options = {
adsafe: false,
bitwise: true,
View
@@ -1,5 +0,0 @@
-module.exports = {
- root: __dirname + '/../',
- testRunner: 'default',
- pathIgnore: ['*node_modules*', '*dist/test*']
-};
View
@@ -1,35 +0,0 @@
-var util = require('util'),
- child_process = require('child_process'),
- configFile = __dirname + '/config-lint',
- ignore = '',
- config,
- root,
- i;
-
-process.argv.forEach(function (val, index, array) {
- if (index < 2) {
- return;
- }
-
- if (val === '-c') {
- configFile = process.argv[~~index + 1];
- }
-});
-
-config = require(configFile);
-
-function runLint(error, stdout, stderr) {
- var files = stdout.trim().replace(/\n/g, ' ');
-
- child_process.exec('node ' + __dirname + '/../node_modules/nodelint/nodelint ' + files + ' --config ' + configFile + '.js', { cwd: config.root }, function (error, stdout, stderr) {
- util.puts(stdout);
- });
-}
-
-i = config.pathIgnore.length;
-while (i) {
- i -= 1;
- ignore += ' ! -path "' + config.pathIgnore[i] + '"';
-}
-
-child_process.exec('find . -name "*.js"' + ignore, { cwd: config.root }, runLint);
Oops, something went wrong.

0 comments on commit 732d3b4

Please sign in to comment.