Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 732d3b47675cee86287bf9c98fc4e2124d55572f 2 parents e8cfdf4 + b40f61f
@andris-silis authored
View
32 History.md
@@ -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
16 Makefile
@@ -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
15 docs/custom-tags.md
@@ -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,7 +26,7 @@ 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';
};
@@ -35,7 +34,7 @@ To parse a swig variable with or without filters into a variable token, eg. `bar
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
11 index.js
@@ -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
5 lib/dateformat.js
@@ -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
13 lib/filters.js
@@ -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
19 lib/filters.test.js
@@ -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
6 lib/helpers.js
@@ -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
4 lib/parser.js
@@ -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
7 lib/parser.test.js
@@ -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
2  lib/tags/for.js
@@ -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
4 package.json
@@ -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
5 scripts/config-lint.js
@@ -1,8 +1,3 @@
-module.exports = {
- root: __dirname + '/../',
- pathIgnore: ['*node_modules*', '*browser/underscore*', '*dist/browser/*', '*dist/test*']
-};
-
var options = {
adsafe: false,
bitwise: true,
View
5 scripts/config-test.js
@@ -1,5 +0,0 @@
-module.exports = {
- root: __dirname + '/../',
- testRunner: 'default',
- pathIgnore: ['*node_modules*', '*dist/test*']
-};
View
35 scripts/runlint.js
@@ -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);
View
124 scripts/runtests.js
@@ -1,124 +0,0 @@
-var util = require('util'),
- child_process = require('child_process'),
- nodeunit = require('nodeunit'),
- configFile = __dirname + '/config-test',
- ignore = '',
- path = require('path'),
- fs = require('fs'),
- track = require(__dirname + '/../node_modules/nodeunit/lib/track'),
- utils = require(__dirname + '/../node_modules/nodeunit/lib/utils'),
- AssertionError = require(__dirname + '/../node_modules/nodeunit/lib/assert').AssertionError,
- config,
- i,
- l;
-
-process.argv.forEach(function (val, index, array) {
- if (index < 2) {
- return;
- }
-
- if (val === '-c') {
- configFile = process.argv[~~index + 1];
- }
-});
-
-config = require(configFile);
-
-/*!
- * Nodeunit
- * Copyright (c) 2010 Caolan McMahon
- * MIT Licensed
- */
-function run(files, options) {
-
- if (!options) {
- options = JSON.parse(fs.readFileSync(__dirname + '/../node_modules/nodeunit/bin/nodeunit.json', 'utf8'));
- }
-
- var content,
- names,
- i = 0,
- error = function (str) {
- return options.error_prefix + str + options.error_suffix;
- },
- ok = function (str) {
- return options.ok_prefix + str + options.ok_suffix;
- },
- bold = function (str) {
- return options.bold_prefix + str + options.bold_suffix;
- },
- assertion_message = function (str) {
- return options.assertion_prefix + str + options.assertion_suffix;
- },
- start = new Date().getTime(),
- paths = files.map(function (p) {
- return path.join(process.cwd(), p);
- }),
- tracker = track.createTracker(function (tracker) {
- if (tracker.unfinished()) {
- console.log('');
- console.log(error(bold(
- 'FAILURES: Undone tests (or their setups/teardowns): '
- )));
- names = tracker.names();
- for (i; i < names.length; i += 1) {
- console.log('- ' + names[i]);
- }
- console.log('');
- console.log('To fix this, make sure all tests call test.done()');
- process.reallyExit(tracker.unfinished());
- }
- });
-
- nodeunit.runFiles(paths, {
- testspec: options.testspec,
- moduleStart: function (name) {
- console.log('\n' + bold(name));
- },
- testDone: function (name, assertions) {
- tracker.remove(name);
-
- if (!assertions.failures()) {
- console.log('' + name);
- } else {
- console.log(error('' + name) + '\n');
- assertions.forEach(function (a) {
- if (a.failed()) {
- a = utils.betterErrors(a);
- if (a.error instanceof AssertionError && a.message) {
- console.log('Assertion Message: ' + assertion_message(a.message));
- }
- console.log(a.error.stack + '\n');
- }
- });
- }
- },
- done: function (assertions, end) {
- end = end || new Date().getTime();
- var duration = end - start;
- if (assertions.failures()) {
- console.log('\n' + bold(error('FAILURES: ')) + assertions.failures() + '/' + assertions.length + ' assertions failed (' + assertions.duration + 'ms)');
- process.exit(1);
- } else {
- console.log('\n' + bold(ok('OK: ')) + assertions.length + ' assertions (' + assertions.duration + 'ms)');
- }
- },
- testStart: function (name) {
- tracker.put(name);
- }
- });
-}
-
-function runTests(error, stdout, stderr) {
- var tests = stdout.trim().split("\n");
- if (tests.length && tests[0] !== '') {
- run(tests);
- }
-}
-
-l = config.pathIgnore.length;
-for (i = 0; i < l; i += 1) {
- ignore += ' ! -path "' + config.pathIgnore[i] + '"';
-}
-
-child_process.exec('find . -name "*.test.js" ' + ignore, { cwd: config.root }, runTests);
Please sign in to comment.
Something went wrong with that request. Please try again.