Skip to content

Commit

Permalink
Commit 82 (v0.9.82 - Beta)
Browse files Browse the repository at this point in the history
Feature improvements:

- New tag.contentCtx() method allows custom tags to set the data context
  in wrapped blocks.

- Added {{else}} support on {{range}} (range.js)

Documentation:

- New documentation and samples for custom get/set property on compiled
  View Model:
  http://www.jsviews.com/#viewmodelsapi@ismanagersample
  http://www.jsviews.com/#samples/computed/team-manager

Bug fixes:

- Some minor bug fixes

Unit tests:

- Several additional unit tests
  • Loading branch information
BorisMoore committed Oct 29, 2016
1 parent 6e5e393 commit 543ec2d
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 64 deletions.
20 changes: 13 additions & 7 deletions jsrender-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! JsRender v0.9.81 (Beta): http://jsviews.com/#jsrender */
/*! JsRender v0.9.82 (Beta): 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 @@ -19,7 +19,7 @@ if (typeof exports !== 'object' ) {

//========================== Top-level vars ==========================

var versionNumber = "v0.9.81",
var versionNumber = "v0.9.82",

// global var is the this object, which is window when running in the usual browser environment

Expand Down Expand Up @@ -458,7 +458,8 @@ function getResource(resourceType, itemName) {

function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) {
parentView = parentView || topView;
var tag, tag_, tagDef, template, tags, attr, parentTag, i, l, itemRet, tagCtx, tagCtxCtx, content, callInit, mapDef, thisMap, args, props, initialTmpl, tagDataMap,
var tag, tag_, tagDef, template, tags, attr, parentTag, i, l, itemRet, tagCtx, tagCtxCtx,
content, callInit, mapDef, thisMap, args, props, initialTmpl, tagDataMap, contentCtx,
ret = "",
linkCtx = parentView.linkCtx || 0,
ctx = parentView.ctx,
Expand Down Expand Up @@ -599,7 +600,11 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) {
args = [parentView]; // no arguments - (e.g. {{else}}) get data context from view.
}
if (itemRet === undefined) {
itemRet = tagCtx.render(args[0], true) || (isUpdate ? undefined : "");
contentCtx = args[0]; // Default data context for wrapped block content is the first argument. Defined tag.contentCtx function to override this.
if (tag.contentCtx) {
contentCtx = tag.contentCtx(contentCtx) || contentCtx;
}
itemRet = tagCtx.render(contentCtx, true) || (isUpdate ? undefined : "");
}
// No return value from render, and no template/content tagCtx.render(...), so return undefined
ret = ret ? ret + (itemRet || "") : itemRet; // If no rendered content, this will be undefined
Expand Down Expand Up @@ -1248,7 +1253,7 @@ function renderContent(data, context, noIteration, parentView, key, onRender) {
}

if (tmpl) {
if (!view && data && data._is === "view") {
if (!parentView && data && data._is === "view") {
view = data; // When passing in a view to render or link (and not passing in a parent view) use the passed-in view as parentView
}

Expand Down Expand Up @@ -1380,7 +1385,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
newView = swapContent
? view
: (key !== undefined && view)
|| new View(context, "array", view, data, tmpl, key, onRender);
|| new View(context, "array", view, data, tmpl, key, onRender, contentTmpl);
if (view && view._.useKey) {
// Parent is not an 'array view'
newView._.bnd = !tag || tag._.bnd && tag; // For array views that are data bound for collection change events, set the
Expand All @@ -1395,7 +1400,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
if (itemVar) {
setItemVar(data[i]); // use modified ctx with user-named ~item
}
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, onRender, contentTmpl);
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, onRender, newView.content);

itemResult = tmpl.fn(data[i], childView, $sub);
result += newView._.onRender ? newView._.onRender(itemResult, childView) : itemResult;
Expand All @@ -1409,6 +1414,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
newView = swapContent ? view : new View(newCtx, tmplName || "data", view, data, tmpl, key, onRender, contentTmpl);
if (tag && !tag.flow) {
newView.tag = tag;
tag.view = newView;
}
result += tmpl.fn(data, newView, $sub);
}
Expand Down
20 changes: 13 additions & 7 deletions jsrender.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! JsRender v0.9.81 (Beta): http://jsviews.com/#jsrender */
/*! JsRender v0.9.82 (Beta): 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 = "v0.9.81",
var versionNumber = "v0.9.82",
jsvStoreName, rTag, rTmplString, topView, $views, $expando,

//TODO tmplFnsCache = {},
Expand Down Expand Up @@ -483,7 +483,8 @@ function getResource(resourceType, itemName) {

function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) {
parentView = parentView || topView;
var tag, tag_, tagDef, template, tags, attr, parentTag, i, l, itemRet, tagCtx, tagCtxCtx, content, callInit, mapDef, thisMap, args, props, initialTmpl, tagDataMap,
var tag, tag_, tagDef, template, tags, attr, parentTag, i, l, itemRet, tagCtx, tagCtxCtx,
content, callInit, mapDef, thisMap, args, props, initialTmpl, tagDataMap, contentCtx,
ret = "",
linkCtx = parentView.linkCtx || 0,
ctx = parentView.ctx,
Expand Down Expand Up @@ -624,7 +625,11 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) {
args = [parentView]; // no arguments - (e.g. {{else}}) get data context from view.
}
if (itemRet === undefined) {
itemRet = tagCtx.render(args[0], true) || (isUpdate ? undefined : "");
contentCtx = args[0]; // Default data context for wrapped block content is the first argument. Defined tag.contentCtx function to override this.
if (tag.contentCtx) {
contentCtx = tag.contentCtx(contentCtx) || contentCtx;
}
itemRet = tagCtx.render(contentCtx, true) || (isUpdate ? undefined : "");
}
// No return value from render, and no template/content tagCtx.render(...), so return undefined
ret = ret ? ret + (itemRet || "") : itemRet; // If no rendered content, this will be undefined
Expand Down Expand Up @@ -1297,7 +1302,7 @@ function renderContent(data, context, noIteration, parentView, key, onRender) {
}

if (tmpl) {
if (!view && data && data._is === "view") {
if (!parentView && data && data._is === "view") {
view = data; // When passing in a view to render or link (and not passing in a parent view) use the passed-in view as parentView
}

Expand Down Expand Up @@ -1429,7 +1434,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
newView = swapContent
? view
: (key !== undefined && view)
|| new View(context, "array", view, data, tmpl, key, onRender);
|| new View(context, "array", view, data, tmpl, key, onRender, contentTmpl);
if (view && view._.useKey) {
// Parent is not an 'array view'
newView._.bnd = !tag || tag._.bnd && tag; // For array views that are data bound for collection change events, set the
Expand All @@ -1444,7 +1449,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
if (itemVar) {
setItemVar(data[i]); // use modified ctx with user-named ~item
}
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, onRender, contentTmpl);
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, onRender, newView.content);

itemResult = tmpl.fn(data[i], childView, $sub);
result += newView._.onRender ? newView._.onRender(itemResult, childView) : itemResult;
Expand All @@ -1458,6 +1463,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
newView = swapContent ? view : new View(newCtx, tmplName || "data", view, data, tmpl, key, onRender, contentTmpl);
if (tag && !tag.flow) {
newView.tag = tag;
tag.view = newView;
}
result += tmpl.fn(data, newView, $sub);
}
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": "v0.9.81",
"version": "v0.9.82",
"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
22 changes: 14 additions & 8 deletions test/browserify/bundles/1-bundle.js

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions test/browserify/bundles/12-nested-bundle.js

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions test/browserify/bundles/2-bundle.js

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions test/browserify/bundles/3-bundle.js

Large diffs are not rendered by default.

20 changes: 13 additions & 7 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 v0.9.81 (Beta): http://jsviews.com/#jsrender */
/*! JsRender v0.9.82 (Beta): 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 = "v0.9.81",
var versionNumber = "v0.9.82",
jsvStoreName, rTag, rTmplString, topView, $views, $expando,

//TODO tmplFnsCache = {},
Expand Down Expand Up @@ -484,7 +484,8 @@ function getResource(resourceType, itemName) {

function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) {
parentView = parentView || topView;
var tag, tag_, tagDef, template, tags, attr, parentTag, i, l, itemRet, tagCtx, tagCtxCtx, content, callInit, mapDef, thisMap, args, props, initialTmpl, tagDataMap,
var tag, tag_, tagDef, template, tags, attr, parentTag, i, l, itemRet, tagCtx, tagCtxCtx,
content, callInit, mapDef, thisMap, args, props, initialTmpl, tagDataMap, contentCtx,
ret = "",
linkCtx = parentView.linkCtx || 0,
ctx = parentView.ctx,
Expand Down Expand Up @@ -625,7 +626,11 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) {
args = [parentView]; // no arguments - (e.g. {{else}}) get data context from view.
}
if (itemRet === undefined) {
itemRet = tagCtx.render(args[0], true) || (isUpdate ? undefined : "");
contentCtx = args[0]; // Default data context for wrapped block content is the first argument. Defined tag.contentCtx function to override this.
if (tag.contentCtx) {
contentCtx = tag.contentCtx(contentCtx) || contentCtx;
}
itemRet = tagCtx.render(contentCtx, true) || (isUpdate ? undefined : "");
}
// No return value from render, and no template/content tagCtx.render(...), so return undefined
ret = ret ? ret + (itemRet || "") : itemRet; // If no rendered content, this will be undefined
Expand Down Expand Up @@ -1298,7 +1303,7 @@ function renderContent(data, context, noIteration, parentView, key, onRender) {
}

if (tmpl) {
if (!view && data && data._is === "view") {
if (!parentView && data && data._is === "view") {
view = data; // When passing in a view to render or link (and not passing in a parent view) use the passed-in view as parentView
}

Expand Down Expand Up @@ -1430,7 +1435,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
newView = swapContent
? view
: (key !== undefined && view)
|| new View(context, "array", view, data, tmpl, key, onRender);
|| new View(context, "array", view, data, tmpl, key, onRender, contentTmpl);
if (view && view._.useKey) {
// Parent is not an 'array view'
newView._.bnd = !tag || tag._.bnd && tag; // For array views that are data bound for collection change events, set the
Expand All @@ -1445,7 +1450,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
if (itemVar) {
setItemVar(data[i]); // use modified ctx with user-named ~item
}
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, onRender, contentTmpl);
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, onRender, newView.content);

itemResult = tmpl.fn(data[i], childView, $sub);
result += newView._.onRender ? newView._.onRender(itemResult, childView) : itemResult;
Expand All @@ -1459,6 +1464,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
newView = swapContent ? view : new View(newCtx, tmplName || "data", view, data, tmpl, key, onRender, contentTmpl);
if (tag && !tag.flow) {
newView.tag = tag;
tag.view = newView;
}
result += tmpl.fn(data, newView, $sub);
}
Expand Down
20 changes: 13 additions & 7 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 v0.9.81 (Beta): http://jsviews.com/#jsrender */
/*! JsRender v0.9.82 (Beta): 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 = "v0.9.81",
var versionNumber = "v0.9.82",
jsvStoreName, rTag, rTmplString, topView, $views, $expando,

//TODO tmplFnsCache = {},
Expand Down Expand Up @@ -484,7 +484,8 @@ function getResource(resourceType, itemName) {

function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) {
parentView = parentView || topView;
var tag, tag_, tagDef, template, tags, attr, parentTag, i, l, itemRet, tagCtx, tagCtxCtx, content, callInit, mapDef, thisMap, args, props, initialTmpl, tagDataMap,
var tag, tag_, tagDef, template, tags, attr, parentTag, i, l, itemRet, tagCtx, tagCtxCtx,
content, callInit, mapDef, thisMap, args, props, initialTmpl, tagDataMap, contentCtx,
ret = "",
linkCtx = parentView.linkCtx || 0,
ctx = parentView.ctx,
Expand Down Expand Up @@ -625,7 +626,11 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) {
args = [parentView]; // no arguments - (e.g. {{else}}) get data context from view.
}
if (itemRet === undefined) {
itemRet = tagCtx.render(args[0], true) || (isUpdate ? undefined : "");
contentCtx = args[0]; // Default data context for wrapped block content is the first argument. Defined tag.contentCtx function to override this.
if (tag.contentCtx) {
contentCtx = tag.contentCtx(contentCtx) || contentCtx;
}
itemRet = tagCtx.render(contentCtx, true) || (isUpdate ? undefined : "");
}
// No return value from render, and no template/content tagCtx.render(...), so return undefined
ret = ret ? ret + (itemRet || "") : itemRet; // If no rendered content, this will be undefined
Expand Down Expand Up @@ -1298,7 +1303,7 @@ function renderContent(data, context, noIteration, parentView, key, onRender) {
}

if (tmpl) {
if (!view && data && data._is === "view") {
if (!parentView && data && data._is === "view") {
view = data; // When passing in a view to render or link (and not passing in a parent view) use the passed-in view as parentView
}

Expand Down Expand Up @@ -1430,7 +1435,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
newView = swapContent
? view
: (key !== undefined && view)
|| new View(context, "array", view, data, tmpl, key, onRender);
|| new View(context, "array", view, data, tmpl, key, onRender, contentTmpl);
if (view && view._.useKey) {
// Parent is not an 'array view'
newView._.bnd = !tag || tag._.bnd && tag; // For array views that are data bound for collection change events, set the
Expand All @@ -1445,7 +1450,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
if (itemVar) {
setItemVar(data[i]); // use modified ctx with user-named ~item
}
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, onRender, contentTmpl);
childView = new View(newCtx, "item", newView, data[i], tmpl, (key || 0) + i, onRender, newView.content);

itemResult = tmpl.fn(data[i], childView, $sub);
result += newView._.onRender ? newView._.onRender(itemResult, childView) : itemResult;
Expand All @@ -1459,6 +1464,7 @@ function renderWithViews(tmpl, data, context, noIteration, view, key, onRender,
newView = swapContent ? view : new View(newCtx, tmplName || "data", view, data, tmpl, key, onRender, contentTmpl);
if (tag && !tag.flow) {
newView.tag = tag;
tag.view = newView;
}
result += tmpl.fn(data, newView, $sub);
}
Expand Down
Loading

0 comments on commit 543ec2d

Please sign in to comment.