Skip to content

Commit

Permalink
v1.0.8 release
Browse files Browse the repository at this point in the history
Sync with changes in v1.0.8 for JsViews

Feature improvements:
  - Improvements (and associated bug fixes) when converters return arrays.
    With minor breakng change for some advanced scenarios:

    Converters which return arrays now have an improved heuristic behavior
    to determine whether to return the array (retArray) as value for the
    first argument, or as an array of values for multiple bindTo/bindFrom
    targets.
    (If bindTo/bindFrom is an array of length l, l > 1 and the converter
    is returning an array retArray of length l, then treat retArray as an
    array of values for the multiple targets bindTo/bindFrom targets)
    In addition the heurisic default behavior can be overidden by setting
    retArray.arg0 = true/false.

    See http://jsviews.com/#tagsapi@bindto

Additional small corrections or improvements to documentation, and some
additional unit tests...
  • Loading branch information
BorisMoore committed Oct 25, 2020
1 parent 3c0b14b commit 81dc0f6
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 52 deletions.
10 changes: 5 additions & 5 deletions jsrender-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! JsRender v1.0.7: http://jsviews.com/#jsrender */
/*! JsRender v1.0.8: http://jsviews.com/#jsrender */
/*! **VERSION FOR NODE.JS** (For WEB see http://jsviews.com/download/jsrender.js) */
/*
* Best-of-breed templating in browser or on Node.js.
Expand All @@ -20,7 +20,7 @@ if (typeof exports !== 'object' ) {
//========================== Top-level vars ==========================

// global var is the this object, which is window when running in the usual browser environment
var versionNumber = "v1.0.7",
var versionNumber = "v1.0.8",
$, jsvStoreName, rTag, rTmplString, topView, $views,
_ocp = "_ocp", // Observable contextual parameter

Expand Down Expand Up @@ -590,8 +590,8 @@ function convertArgs(tagElse, bound) { // tag.cvtArgs() or tag.cvtArgs(tagElse?,
}
bindFrom = bindFrom || [0];
l = bindFrom.length;
if (!$isArray(converter) || converter.length !== l) {
converter = [converter];
if (!$isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) {
converter = [converter]; // Returning converter as first arg, even if converter value is an array
bindFrom = [0];
l = 1;
}
Expand Down Expand Up @@ -981,7 +981,7 @@ View.prototype = {
if ($subSettings._cchCt > this.cache._ct) {
this.cache = {_ct: $subSettings._cchCt};
}
return this.cache[key] || (this.cache[key] = cpFnStore[key](this.data, this, $sub));
return this.cache[key] !== undefined ? this.cache[key] : (this.cache[key] = cpFnStore[key](this.data, this, $sub));
},
_is: "view"
};
Expand Down
10 changes: 5 additions & 5 deletions jsrender.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! JsRender v1.0.7: http://jsviews.com/#jsrender */
/*! JsRender v1.0.8: http://jsviews.com/#jsrender */
/*! **VERSION FOR WEB** (For NODE.JS see http://jsviews.com/download/jsrender-node.js) */
/*
* Best-of-breed templating in browser or on Node.js.
Expand Down Expand Up @@ -44,7 +44,7 @@ var setGlobals = $ === false; // Only set globals if script block in browser (no

$ = $ && $.fn ? $ : global.jQuery; // $ is jQuery passed in by CommonJS loader (Browserify), or global jQuery.

var versionNumber = "v1.0.7",
var versionNumber = "v1.0.8",
jsvStoreName, rTag, rTmplString, topView, $views, $expando,
_ocp = "_ocp", // Observable contextual parameter

Expand Down Expand Up @@ -617,8 +617,8 @@ function convertArgs(tagElse, bound) { // tag.cvtArgs() or tag.cvtArgs(tagElse?,
}
bindFrom = bindFrom || [0];
l = bindFrom.length;
if (!$isArray(converter) || converter.length !== l) {
converter = [converter];
if (!$isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) {
converter = [converter]; // Returning converter as first arg, even if converter value is an array
bindFrom = [0];
l = 1;
}
Expand Down Expand Up @@ -1008,7 +1008,7 @@ View.prototype = {
if ($subSettings._cchCt > this.cache._ct) {
this.cache = {_ct: $subSettings._cchCt};
}
return this.cache[key] || (this.cache[key] = cpFnStore[key](this.data, this, $sub));
return this.cache[key] !== undefined ? this.cache[key] : (this.cache[key] = cpFnStore[key](this.data, this, $sub));
},
_is: "view"
};
Expand Down
4 changes: 2 additions & 2 deletions jsrender.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jsrender.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsrender",
"version": "v1.0.7",
"version": "v1.0.8",
"description": "Best-of-breed templating in browser or on Node.js (with Express 4, Hapi and Browserify integration)",
"main": "./jsrender-node.js",
"browser": "./jsrender.js",
Expand Down
12 changes: 6 additions & 6 deletions test/browserify/bundles/1-bundle.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/browserify/bundles/12-nested-bundle.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/browserify/bundles/2-bundle.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/browserify/bundles/3-bundle.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions test/browserify/bundles/htm-jsrender-tmpl-bundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/*! JsRender v1.0.7: http://jsviews.com/#jsrender */
/*! JsRender v1.0.8: http://jsviews.com/#jsrender */
/*! **VERSION FOR WEB** (For NODE.JS see http://jsviews.com/download/jsrender-node.js) */
/*
* Best-of-breed templating in browser or on Node.js.
Expand Down Expand Up @@ -45,7 +45,7 @@ var setGlobals = $ === false; // Only set globals if script block in browser (no

$ = $ && $.fn ? $ : global.jQuery; // $ is jQuery passed in by CommonJS loader (Browserify), or global jQuery.

var versionNumber = "v1.0.7",
var versionNumber = "v1.0.8",
jsvStoreName, rTag, rTmplString, topView, $views, $expando,
_ocp = "_ocp", // Observable contextual parameter

Expand Down Expand Up @@ -618,8 +618,8 @@ function convertArgs(tagElse, bound) { // tag.cvtArgs() or tag.cvtArgs(tagElse?,
}
bindFrom = bindFrom || [0];
l = bindFrom.length;
if (!$isArray(converter) || converter.length !== l) {
converter = [converter];
if (!$isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) {
converter = [converter]; // Returning converter as first arg, even if converter value is an array
bindFrom = [0];
l = 1;
}
Expand Down Expand Up @@ -1009,7 +1009,7 @@ View.prototype = {
if ($subSettings._cchCt > this.cache._ct) {
this.cache = {_ct: $subSettings._cchCt};
}
return this.cache[key] || (this.cache[key] = cpFnStore[key](this.data, this, $sub));
return this.cache[key] !== undefined ? this.cache[key] : (this.cache[key] = cpFnStore[key](this.data, this, $sub));
},
_is: "view"
};
Expand Down
10 changes: 5 additions & 5 deletions test/browserify/bundles/html-jsr-tmpl-bundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/*! JsRender v1.0.7: http://jsviews.com/#jsrender */
/*! JsRender v1.0.8: http://jsviews.com/#jsrender */
/*! **VERSION FOR WEB** (For NODE.JS see http://jsviews.com/download/jsrender-node.js) */
/*
* Best-of-breed templating in browser or on Node.js.
Expand Down Expand Up @@ -45,7 +45,7 @@ var setGlobals = $ === false; // Only set globals if script block in browser (no

$ = $ && $.fn ? $ : global.jQuery; // $ is jQuery passed in by CommonJS loader (Browserify), or global jQuery.

var versionNumber = "v1.0.7",
var versionNumber = "v1.0.8",
jsvStoreName, rTag, rTmplString, topView, $views, $expando,
_ocp = "_ocp", // Observable contextual parameter

Expand Down Expand Up @@ -618,8 +618,8 @@ function convertArgs(tagElse, bound) { // tag.cvtArgs() or tag.cvtArgs(tagElse?,
}
bindFrom = bindFrom || [0];
l = bindFrom.length;
if (!$isArray(converter) || converter.length !== l) {
converter = [converter];
if (!$isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) {
converter = [converter]; // Returning converter as first arg, even if converter value is an array
bindFrom = [0];
l = 1;
}
Expand Down Expand Up @@ -1009,7 +1009,7 @@ View.prototype = {
if ($subSettings._cchCt > this.cache._ct) {
this.cache = {_ct: $subSettings._cchCt};
}
return this.cache[key] || (this.cache[key] = cpFnStore[key](this.data, this, $sub));
return this.cache[key] !== undefined ? this.cache[key] : (this.cache[key] = cpFnStore[key](this.data, this, $sub));
},
_is: "view"
};
Expand Down
9 changes: 6 additions & 3 deletions test/unit-tests/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Configure loading modules from the download directory,
requirejs.config({
"baseUrl": "//www.jsviews.com/download", // Or point to correct local path on your system: "baseUrl": "/",
// "baseUrl": "../../", // Or point to correct local path on your system: "baseUrl": "/",
"baseUrl": "//www.jsviews.com/download", // Or point to correct local path on your system: "baseUrl": "/download",
// "baseUrl": "../../download", // Or point to correct local path on your system: "baseUrl": "/download",
"paths": {
"jquery": "//code.jquery.com/jquery-3.5.1",
"jsrender": "./jsrender"
"jsrender": "./jsrender",
"jquery.observable": "./jquery.observable",
"jquery.views": "./jquery.views",
"jsviews": "./jsviews"
}
});
26 changes: 26 additions & 0 deletions test/unit-tests/tests-jsrender-no-jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ QUnit.test("expressions", function(assert) {
assert.equal($.templates("{{:!true === false}}").render({}), "true", "!true === false");
assert.equal($.templates("{{:false === !true}}").render({}), "true", "false === !true");
assert.equal($.templates("{{:false === !null}}").render({}), "false", "false === !null");
assert.equal($.templates("{{:\"'\" + 1 + '\"' + 2 + '\\' + 3}}").render({}), "'1\"2\\3", "'1\"2\\3");
});

QUnit.module("{{for}}");
Expand Down Expand Up @@ -1233,6 +1234,31 @@ QUnit.test("itemVar", function(assert) {
"itemVar with {{props}}{{else}}{{/props}}, and passing context to nested templates");
});

QUnit.test("contextual parameter", function(assert) {
var teams = [
{title: "The A Team", members: [{name: "Jeff"}, {name: "Maria"}]},
{title: "The B Team", members: [{name: "Francis"}]}
];

assert.equal($.templates(
"{{if members.length ~teamTitle=title ~teamData=#data ~teamIndex=#index}}"
+ "{{for members itemVar='~member'}}"
+ "{{:~teamTitle}} "
+ "{{:~teamData.title}} "
+ "{{:~teamIndex}} "
+ "{{:~member.name}} "
+ "{{/for}}"
+ "{{/if}}"
).render(teams),
"The A Team The A Team 0 Jeff The A Team The A Team 0 Maria The B Team The B Team 1 Francis ",
"contextual parameter passing to inner context");

assert.equal($.templates(
"{^{if 1 ~a='A'+\"B\"+'\"'+\"'\"+\"\\'\"}}{^{:'Inner'+~a}}{{/if}}").render(),
"InnerAB\"'\\'",
"contextual parameter correctly escaping quotes and backslash");
});

QUnit.module("api no jQuery");
QUnit.test("templates", function(assert) {
// ................................ Arrange ..................................
Expand Down
2 changes: 1 addition & 1 deletion typescript/jsrender/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Type definitions for JsRender 1.0
// Version: "v1.0.7"
// Version: "v1.0.8"
// Project: http://www.jsviews.com/#jsrender
// Definitions by: Boris Moore <https://github.com/borismoore>
// Definitions: https://www.jsviews.com/download/typescript/jsrender/index.d.ts
Expand Down

0 comments on commit 81dc0f6

Please sign in to comment.