Skip to content

Commit 1b20265

Browse files
committed
Commit 69 (v1.0.0-rc.69 - Release Candidate)
Bug Fix: BorisMoore/jsviews#315
1 parent 2844c61 commit 1b20265

File tree

10 files changed

+44
-35
lines changed

10 files changed

+44
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ or
370370
{{/if}}
371371
```
372372
373-
<h3><i>Node.js features</i></h3>
373+
<h3><i>Node.js Integration</i></h3>
374374
375375
On Node.js *JsRender* provides built-in ***Express***, ***Hapi*** and ***Browserify*** integration. This makes it easy to register templates as simple `.html` files on the file system, and then load and render them either server-side, client-side or both.
376376

jsrender-node.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! JsRender v1.0.0-rc.68 (Beta - Release Candidate): http://jsviews.com/#jsrender */
1+
/*! JsRender v1.0.0-rc.69 (Beta - Release Candidate): http://jsviews.com/#jsrender */
22
/*! **VERSION FOR NODE.JS** (For WEB see http://jsviews.com/download/jsrender.js) */
33
/*
44
* Best-of-breed templating in browser or on Node.js.
@@ -94,6 +94,7 @@ var versionNumber = "v1.0.0-beta",
9494
tmplFn: tmplFn,
9595
parse: parseParams,
9696
extend: $extend,
97+
extendCtx: extendCtx,
9798
syntaxErr: syntaxError,
9899
onStore: {},
99100
_ths: tagHandlersFromProps,
@@ -200,7 +201,7 @@ function $viewsDelimiters(openChars, closeChars, link) {
200201
delimCloseChar0 = closeChars ? closeChars.charAt(0) : delimCloseChar0;
201202
delimCloseChar1 = closeChars ? closeChars.charAt(1) : delimCloseChar1;
202203
linkChar = link || linkChar;
203-
openChars = "\\" + delimOpenChar0 + "(\\" + linkChar + ")?\\" + delimOpenChar1; // Default is "{^{"
204+
openChars = "\\" + delimOpenChar0 + "(\\" + linkChar + ")?\\" + delimOpenChar1; // Default is "{^{"
204205
closeChars = "\\" + delimCloseChar0 + "\\" + delimCloseChar1; // Default is "}}"
205206
// Build regex with new delimiters
206207
// tag (followed by / space or }) or cvtr+colon or html or code
@@ -612,7 +613,7 @@ function View(context, type, parentView, data, template, key, contentTmpl, onRen
612613
// If the data is an array, this is an 'array view' with a views array for each child 'item view'
613614
// If the data is not an array, this is an 'item view' with a views 'hash' object for any child nested views
614615
// ._.useKey is non zero if is not an 'array view' (owning a data array). Use this as next key for adding to child views hash
615-
self_ = self._ = {
616+
self_ = self._ = {
616617
key: 0,
617618
useKey: isArray ? 0 : 1,
618619
id: "" + viewId++,
@@ -696,7 +697,7 @@ function compileTag(name, tagDef, parentTmpl) {
696697
render: tagDef
697698
};
698699
} else if ("" + tagDef === tagDef) {
699-
tagDef = {template: tagDef};
700+
tagDef = {template: tagDef};
700701
}
701702
if (baseTag = tagDef.baseTag) {
702703
tagDef.flow = !!tagDef.flow; // Set flow property, so defaults to false even if baseTag has flow=true
@@ -1057,7 +1058,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
10571058
if (view) {
10581059
contentTmpl = contentTmpl || view.content; // The wrapped content - to be added as #content property on views, below
10591060
onRender = onRender || view._.onRender;
1060-
context = context || view.ctx;
1061+
context = extendCtx(context, view.ctx);
10611062
}
10621063

10631064
if (key === true) {
@@ -1095,7 +1096,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
10951096
for (i = 0, l = data.length; i < l; i++) {
10961097
// Create a view for each data item.
10971098
if (itemVar) {
1098-
setItemVar(data[i]); // use modified ctx with user-named ~item
1099+
setItemVar(data[i]); // use modified ctx with user-named ~item
10991100
}
11001101
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, contentTmpl, onRender);
11011102

jsrender.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! JsRender v1.0.0-rc.68 (Beta - Release Candidate): http://jsviews.com/#jsrender */
1+
/*! JsRender v1.0.0-rc.69 (Beta - Release Candidate): http://jsviews.com/#jsrender */
22
/*! **VERSION FOR WEB** (For NODE.JS see http://jsviews.com/download/jsrender-node.js) */
33
/*
44
* Best-of-breed templating in browser or on Node.js.
@@ -118,6 +118,7 @@ var versionNumber = "v1.0.0-beta",
118118
tmplFn: tmplFn,
119119
parse: parseParams,
120120
extend: $extend,
121+
extendCtx: extendCtx,
121122
syntaxErr: syntaxError,
122123
onStore: {},
123124
_ths: tagHandlersFromProps,
@@ -224,7 +225,7 @@ function $viewsDelimiters(openChars, closeChars, link) {
224225
delimCloseChar0 = closeChars ? closeChars.charAt(0) : delimCloseChar0;
225226
delimCloseChar1 = closeChars ? closeChars.charAt(1) : delimCloseChar1;
226227
linkChar = link || linkChar;
227-
openChars = "\\" + delimOpenChar0 + "(\\" + linkChar + ")?\\" + delimOpenChar1; // Default is "{^{"
228+
openChars = "\\" + delimOpenChar0 + "(\\" + linkChar + ")?\\" + delimOpenChar1; // Default is "{^{"
228229
closeChars = "\\" + delimCloseChar0 + "\\" + delimCloseChar1; // Default is "}}"
229230
// Build regex with new delimiters
230231
// tag (followed by / space or }) or cvtr+colon or html or code
@@ -636,7 +637,7 @@ function View(context, type, parentView, data, template, key, contentTmpl, onRen
636637
// If the data is an array, this is an 'array view' with a views array for each child 'item view'
637638
// If the data is not an array, this is an 'item view' with a views 'hash' object for any child nested views
638639
// ._.useKey is non zero if is not an 'array view' (owning a data array). Use this as next key for adding to child views hash
639-
self_ = self._ = {
640+
self_ = self._ = {
640641
key: 0,
641642
useKey: isArray ? 0 : 1,
642643
id: "" + viewId++,
@@ -720,7 +721,7 @@ function compileTag(name, tagDef, parentTmpl) {
720721
render: tagDef
721722
};
722723
} else if ("" + tagDef === tagDef) {
723-
tagDef = {template: tagDef};
724+
tagDef = {template: tagDef};
724725
}
725726
if (baseTag = tagDef.baseTag) {
726727
tagDef.flow = !!tagDef.flow; // Set flow property, so defaults to false even if baseTag has flow=true
@@ -1113,7 +1114,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
11131114
if (view) {
11141115
contentTmpl = contentTmpl || view.content; // The wrapped content - to be added as #content property on views, below
11151116
onRender = onRender || view._.onRender;
1116-
context = context || view.ctx;
1117+
context = extendCtx(context, view.ctx);
11171118
}
11181119

11191120
if (key === true) {
@@ -1151,7 +1152,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
11511152
for (i = 0, l = data.length; i < l; i++) {
11521153
// Create a view for each data item.
11531154
if (itemVar) {
1154-
setItemVar(data[i]); // use modified ctx with user-named ~item
1155+
setItemVar(data[i]); // use modified ctx with user-named ~item
11551156
}
11561157
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, contentTmpl, onRender);
11571158

@@ -1865,6 +1866,7 @@ if (!(jsr || $ && $.render)) {
18651866
$extend(jq, $); // map over from jsrender namespace to jQuery namespace
18661867
$ = jq;
18671868
$.fn.render = $fnRender;
1869+
delete $.jsrender;
18681870
}
18691871
};
18701872

jsrender.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsrender.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsrender",
3-
"version": "v1.0.0-rc.68",
3+
"version": "v1.0.0-rc.69",
44
"description": "Best-of-breed templating in browser or on Node.js (with Express 4, Hapi and Browserify integration)",
55
"main": "./jsrender-node.js",
66
"browser": "./jsrender.js",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Run
22
$ gulp bundle
3-
to generated browserify client bundles used in the unit tests: test/unit-tests-browserify.html
3+
to generate browserify client bundles used in the unit tests: test/unit-tests-browserify.html

test/unit-tests/tests-jsrender-amd-scriptloader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/*global test, equal, module, ok*/
22
(function(global, jQuery, undefined) {
33
"use strict";
4-
if (!window.attachEvent || window.addEventListener) { // Running RequireJS in qunit async test seems to fail in IE8
5-
6-
module("AMD Script Loader");
74

85
function undefine() { // Undefine registered modules from previously run tests.
96
require.undef("jsrender");
107
require.undef("jquery");
118
delete window.jQuery;
129
}
1310

11+
if (!window.attachEvent || window.addEventListener) { // Running RequireJS in qunit async test seems to fail in IE8
12+
13+
module("AMD Script Loader");
14+
1415
test("Loading JsRender, without jQuery, using RequireJS", function(assert) {
1516
var done = assert.async(),
1617
jq = window.jQuery;

test/unit-tests/tests-jsrender-no-jquery.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,11 @@ test("", function() {
661661
}
662662

663663
// ................................ Assert ..................................
664-
ok(tmpl.useViews === false && message.indexOf("data") > 0,
664+
ok(tmpl.useViews === false && message.indexOf("undefined") > 0,
665665
"A simple template with useViews=false will not provide access to the views through allowCode");
666666

667667
// ................................ Act ..................................
668+
message = "";
668669
tmpl.useViews = true;
669670

670671
// ................................ Assert ..................................
@@ -687,22 +688,26 @@ test("", function() {
687688
});
688689

689690
// ................................ Assert ..................................
690-
equal(tmpl.useViews && tmpl.render({towns: towns}), "Seattle, Paris and Delhi",
691-
"Recompiling the template with useViews: true will create a template that has tmpl.useViews = true, which renders with views");
691+
tmpl = $.templates(
692+
"{{:#type}} "
693+
+ "{{for towns}}"
694+
+ "{{>name}}"
695+
+ "{{*:view.index===view.parent.data.length-2 ? ' and ' : view.index<view.parent.data.length-2 ? ', ': ''}}"
696+
+ "{{/for}}");
697+
698+
var html = tmpl.render({towns: towns});
699+
700+
equal(tmpl.useViews && html, "data Seattle, Paris and Delhi",
701+
"Recompiling the template with useViews: true will create a template that has tmpl.useViews = true, which renders with a 'data' view");
692702

693703
// ................................ Act ..................................
694704
tmpl.useViews = false;
695705

696-
try {
697-
tmpl.render({towns: towns});
698-
}
699-
catch (e) {
700-
message = e.message;
701-
}
706+
html = tmpl.render({towns: towns});
702707

703708
// ................................ Assert ..................................
704-
ok(message.indexOf("data") > 0,
705-
"If tmpl.useViews set to false (for an existing template - without recompiling), the template renders without views");
709+
equal(!tmpl.useViews && html, "top Seattle, Paris and Delhi",
710+
"If tmpl.useViews set to false (for an existing template - without recompiling), the template renders without a 'data' view");
706711

707712
// ................................ Act ..................................
708713
$.views.settings.useViews = true;
@@ -712,8 +717,8 @@ test("", function() {
712717
$.views.settings.useViews = false;
713718

714719
// ................................ Assert ..................................
715-
equal(tmpl.useViews && tmpl.render({towns: towns}), "Seattle, Paris and Delhi",
716-
"If $.views.settings.useViews was true when the template is compiled, then the template renders with views, even if $.views.settings.useViews is not longer set to true");
720+
equal(tmpl.useViews && tmpl.render({towns: towns}), "data Seattle, Paris and Delhi",
721+
"If $.views.settings.useViews was true when the template was compiled, then the template renders with views, even if $.views.settings.useViews is no longer set to true");
717722

718723
// =============================== Arrange ===============================
719724
$.views.settings.useViews = false;

tmplify/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! JsRender tmplify submodule v1.0.0-rc.68 (Beta - Release Candidate): http://jsviews.com/#jsrender */
1+
/*! JsRender tmplify submodule v1.0.0-rc.69 (Beta - Release Candidate): http://jsviews.com/#jsrender */
22
/*! Browserify transform for JsRender templates */
33
/*
44
* Copyright 2015, Boris Moore

0 commit comments

Comments
 (0)