Skip to content

Commit

Permalink
Remove unnecessay todo's & fix window object, generate new dist
Browse files Browse the repository at this point in the history
  • Loading branch information
umakantp committed Sep 21, 2017
1 parent 6dd99bc commit a1ea47b
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 31 deletions.
41 changes: 23 additions & 18 deletions dist/jsmart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Max Miroshnikov <miroshnikov at gmail dot com>
* https://opensource.org/licenses/MIT
*
* Date: 2017-09-13T17:30Z
* Date: 2017-09-21T08:56Z
*/
(function (factory) {
'use strict'
Expand Down Expand Up @@ -636,8 +636,6 @@
}
}
} else if ((!!newTree) && (newTree.constructor === Object)) {
// TODO :: figure out, how we would we get this done by
// only getting tree (no value should be needed.)
value += newTree.value
newTree = newTree.tree
tree = tree.concat(newTree)
Expand Down Expand Up @@ -1748,9 +1746,13 @@
res = this.applyFilters(this.variableFilters, res)
if (this.tplModifiers.length) {
// Write in global scope __t() function is called, it works.
// TODO:: Refactor this code.
window.__t = function () { return res }
res = this.process(this.tplModifiers, data)
if (window && window.document) {
window.__t = function () { return res }
} else {
// Node.js like environment?!
global['__t'] = function () { return res }
}
res = this.process(this.tplModifiers[this.tplModifiers.length - 1], data)
if (typeof res !== 'undefined') {
data = res.data
res = res.tpl
Expand Down Expand Up @@ -1834,9 +1836,10 @@
if (node.optype === 'binary') {
arg2 = params[1]
if (node.op === '=') {
// TODO:: why do not we return the var value?
// Var value is returned, but also set inside data.
// we use the data and override ours.
this.getVarValue(node.params.__parsed[0], data, arg2)
return ''
return {tpl: '', data: data}
} else if (node.op.match(/(\+=|-=|\*=|\/=|%=)/)) {
arg1 = this.getVarValue(node.params.__parsed[0], data)
switch (node.op) {
Expand Down Expand Up @@ -2033,13 +2036,13 @@

setfilter: {
process: function (node, data) {
this.tplModifiers = node.params
this.tplModifiers.push(node.params)
var s = this.process(node.subTree, data)
if (typeof s !== 'undefined') {
data = s.data
s = s.tpl
}
this.tplModifiers = []
this.tplModifiers.pop()
return {tpl: s, data: data}
}
},
Expand Down Expand Up @@ -2348,19 +2351,19 @@ var version = '3.0.0'
// Blocks in the current smarty object.
block: {},

// TODO:: Yet to figure out, what it is.
// Used to store state of break;
'break': false,

// All the capture blocks in the current smarty object.
capture: {},

// TODO:: Yet to figure out, what it is.
// Used to store state of continue
'continue': false,

// Current counter information. Smarty like feature.
counter: {},

// TODO:: Yet to figure out, what it is.
// Use by {cycle} custom function to store array and cycle info.
cycle: {},

// All the foreach blocks in the current smarty object.
Expand Down Expand Up @@ -3991,8 +3994,8 @@ var version = '3.0.0'
for (; found && (pos + found.index) <= width; found = line.slice(pos).match(/\s+/)) {
pos += found.index + found[0].length
}
pos = pos || (breakWords ? width : (found ? found.index + found[0].length : line.length))
parts += line.slice(0, pos).replace(/\s+$/, '') // + wrapWith;
pos = (breakWords ? (width - 1) : (pos || (found ? found.index + found[0].length : line.length)))
parts += line.slice(0, pos).replace(/\s+$/, '')
if (pos < line.length) {
parts += wrapWith
}
Expand Down Expand Up @@ -4058,6 +4061,8 @@ jSmart.prototype.registerPlugin(
} else {
if (window && window.document) {
func = window[fname]
} else if (global) {
func = global[fname]
}
}

Expand Down Expand Up @@ -4473,9 +4478,9 @@ jSmart.prototype.registerPlugin(
var address = params.__get('address', null)
var encode = params.__get('encode', 'none')
var text = params.__get('text', address)
var cc = phpJs.rawUrlEncode(params.__get('cc', '')).replace('%40', '@')
var bcc = phpJs.rawUrlEncode(params.__get('bcc', '')).replace('%40', '@')
var followupto = phpJs.rawUrlEncode(params.__get('followupto', '')).replace('%40', '@')
var cc = phpJs.rawUrlEncode(params.__get('cc', '')).replace(/%40/g, '@').replace(/%2C/g, ',')
var bcc = phpJs.rawUrlEncode(params.__get('bcc', '')).replace(/%40/g, '@').replace(/%2C/g, ',')
var followupto = phpJs.rawUrlEncode(params.__get('followupto', '')).replace(/%40/g, '@').replace(/%2C/g, ',')
var subject = phpJs.rawUrlEncode(params.__get('subject', ''))
var newsgroups = phpJs.rawUrlEncode(params.__get('newsgroups', ''))
var extra = params.__get('extra', '')
Expand Down
2 changes: 1 addition & 1 deletion dist/jsmart.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/requirejs/js/jsmart.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/simple/jsmart.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ define(['parser/parser', 'processor/processor', 'util/objectmerge'], function (j
// Blocks in the current smarty object.
block: {},

// TODO:: Yet to figure out, what it is.
// Used to store state of break;
'break': false,

// All the capture blocks in the current smarty object.
capture: {},

// TODO:: Yet to figure out, what it is.
// Used to store state of continue
'continue': false,

// Current counter information. Smarty like feature.
counter: {},

// TODO:: Yet to figure out, what it is.
// Use by {cycle} custom function to store array and cycle info.
cycle: {},

// All the foreach blocks in the current smarty object.
Expand Down
2 changes: 2 additions & 0 deletions src/inbuiltModifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ define(['./core'], function (jSmart) {
} else {
if (window && window.document) {
func = window[fname]
} else if (global) {
func = global[fname]
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,6 @@ define(['../util/objectmerge', '../util/trimallquotes', '../util/evalstring', '.
}
}
} else if ((!!newTree) && (newTree.constructor === Object)) {
// TODO :: figure out, how we would we get this done by
// only getting tree (no value should be needed.)
value += newTree.value
newTree = newTree.tree
tree = tree.concat(newTree)
Expand Down
13 changes: 9 additions & 4 deletions src/processor/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,12 @@ define(['../util/findinarray', '../util/isemptyobject', '../util/countproperties
res = this.applyFilters(this.variableFilters, res)
if (this.tplModifiers.length) {
// Write in global scope __t() function is called, it works.
// TODO:: Refactor this code.
window.__t = function () { return res }
if (window && window.document) {
window.__t = function () { return res }
} else {
// Node.js like environment?!
global['__t'] = function () { return res }
}
res = this.process(this.tplModifiers[this.tplModifiers.length - 1], data)
if (typeof res !== 'undefined') {
data = res.data
Expand Down Expand Up @@ -383,9 +387,10 @@ define(['../util/findinarray', '../util/isemptyobject', '../util/countproperties
if (node.optype === 'binary') {
arg2 = params[1]
if (node.op === '=') {
// TODO:: why do not we return the var value?
// Var value is returned, but also set inside data.
// we use the data and override ours.
this.getVarValue(node.params.__parsed[0], data, arg2)
return ''
return {tpl: '', data: data}
} else if (node.op.match(/(\+=|-=|\*=|\/=|%=)/)) {
arg1 = this.getVarValue(node.params.__parsed[0], data)
switch (node.op) {
Expand Down
2 changes: 1 addition & 1 deletion test/build-in-functions/section-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ define(['jSmart'], function (jSmart) {
it('test nested section', function () {
tpl = '{section name=person loop=$ids}'
tpl += '----------------\\n'
tpl += 'id: {$ids[person]}\\n';
tpl += 'id: {$ids[person]}\\n'
tpl += '{section name=name loop=$names[person]}'
tpl += '{$names[person][name]}\\n'
tpl += '{/section}'
Expand Down

0 comments on commit a1ea47b

Please sign in to comment.