Skip to content

Commit

Permalink
v.1.2.0 contd
Browse files Browse the repository at this point in the history
* JS/PY: empty function now behaves exactly like PHP's function ie true also for string with value "0"
  • Loading branch information
Nikos M committed Feb 2, 2019
1 parent fa5a90b commit c239f20
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __1.2.0__
* add new template function `striptags` to strip `html tags` from string
* add custom `pluralForm` callable (per context) for current locale. It specifies whether a `singular` or `plural` string is to be used based on numeric value given (eg a-la wordpress) (see manual how to set or clear)
* `locale`/`xlocale` methods slightly changed signature and can accept an optional `array`/`list` of arguments which will be used to format the string to be localised a-la `sprintf` functionality (done automaticaly) (NOTE: limited `sprintf` support for python implementation)
* JS/PY: `empty` function behaves now exactly like PHP's function, ie it returns `true` also for string with value `"0"`


__1.1.10__
Expand Down
3 changes: 2 additions & 1 deletion src/js/Contemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,8 @@ function RE( r, f )
}
function empty( o )
{
if ( !o || !Boolean(o) ) return true;
// exactly like php's empty function
if ( !o || !Boolean(o) || "0"===o ) return true;
var to_string = toString.call(o);
if ( (o instanceof Array || o instanceof String || '[object Array]' === to_string || '[object String]' === to_string) && !o.length ) return true;
if ( (o instanceof Object || '[object Object]' === to_string) && !Keys(o).length ) return true;
Expand Down
2 changes: 1 addition & 1 deletion src/js/Contemplate.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/python/Contemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2314,8 +2314,9 @@ def haskey( v, *args ):
return True

def empty( v ):
# exactly like php's function
#return bool(v) or (isinstance(v, (tuple,list,str,dict)) and 0 == len(v))
return not bool(v)
return (isinstance(v, str) and "0" == v) or not bool(v)

#def iif( cond_, then_, else_=None ):
# return then_ if cond_ else else_
Expand Down
2 changes: 1 addition & 1 deletion tests/js/Contemplate.min.js

Large diffs are not rendered by default.

0 comments on commit c239f20

Please sign in to comment.