Skip to content

Commit

Permalink
v2.3.15
Browse files Browse the repository at this point in the history
  • Loading branch information
amarcruz committed Dec 10, 2015
1 parent 3459a5e commit 5ceb562
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 113 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Changelog for riot-tmpl
# riot-tmpl Changes

### v2.3.15
- Regression of optimized regexes not working in IE9/10.
- Fix [riot#1416](https://github.com/riot/riot/issues/1416): Issue with space in expression of `each`.
- Fix [riot#1416](https://github.com/riot/riot/issues/1416) : Issue with space in expression of `each`.
- Fix: when calling the compiler with different brackets, `brackets.array` changes the global configuration (`riot.settings.brackets`).
- Both, `brackets` and `tmpl`, has a new property `version` (string).
- Brackets changes in browsers though `riot.settings.brackets` has immediate effect and always reflect the brackets in use, the `brackets.settings` property is not neccesary and will be removed in v2.4.0

### v2.3.14
- Fix #11: Can't output expressions without evaluation.
- Fix #11 : Can't output expressions without evaluation.
- Fixed issues with regex detection in brackets.js and revision of other regexes.
- Fixed issues with istanbul and new versions of npm in the Makefile.
- Revision of devDependencies, including istanbul for npm 2/3 compatibility.
Expand Down
36 changes: 25 additions & 11 deletions dist/es6.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,19 @@ var brackets = (function (UNDEF) {
_pairs = _create(pair)
_regex = pair === DEFAULT ? _loopback : _rewrite
_pairs[9] = _regex(/^\s*{\^?\s*([$\w]+)(?:\s*,\s*(\S+))?\s+in\s+(\S.*)\s*}/)
_pairs[10] = _regex(/(^|[^\\]){=[\S\s]*?}/)
_brackets._rawOffset = _pairs[0].length
}
_brackets.settings.brackets = cachedBrackets = pair
cachedBrackets = pair
}

function _brackets(reOrIdx) {
_reset(_brackets.settings.brackets)
return reOrIdx instanceof RegExp ? _regex(reOrIdx) : _pairs[reOrIdx]
}

_brackets.split = function split(str, tmpl, _bp) {
// istanbul ignore next: _bp is for the compiler
if (!_bp) {
_reset(_brackets.settings.brackets)
_bp = _pairs
}
if (!_bp) _bp = _pairs

var
parts = [],
Expand Down Expand Up @@ -167,9 +164,26 @@ var brackets = (function (UNDEF) {
}

_brackets.array = function array(pair) {
if (!pair) pair = _brackets.settings.brackets
return _create(pair)
return _create(pair || cachedBrackets)
}

var _settings
function _setSettings(o) {
var b
o = o || {}
b = o.brackets
Object.defineProperty(o, 'brackets', {
set: _reset,
get: function () { return cachedBrackets },
enumerable: true
})
_settings = o
_reset(b)
}
Object.defineProperty(_brackets, 'settings', {
set: _setSettings,
get: function () { return _settings }
})

/* istanbul ignore next: in the node version riot is not in the scope */
_brackets.settings = typeof riot !== 'undefined' && riot.settings || {}
Expand All @@ -179,8 +193,6 @@ var brackets = (function (UNDEF) {
_brackets.R_MLCOMMS = MLCOMMS
_brackets.S_QBLOCKS = S_QBSRC

_reset(_brackets.settings.brackets)

return _brackets

})()
Expand Down Expand Up @@ -208,7 +220,7 @@ var tmpl = (function () {
}

_tmpl.haveRaw = function (src) {
return brackets(/(^|[^\\]){=[\S\s]*?}/).test(src)
return brackets(10).test(src)
}

_tmpl.hasExpr = brackets.hasExpr
Expand Down Expand Up @@ -395,5 +407,7 @@ var tmpl = (function () {

})()

tmpl.version = brackets.version = 'WIP'

export default {tmpl, brackets}

36 changes: 25 additions & 11 deletions dist/riot.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,19 @@ var brackets = (function (UNDEF) {
_pairs = _create(pair)
_regex = pair === DEFAULT ? _loopback : _rewrite
_pairs[9] = _regex(/^\s*{\^?\s*([$\w]+)(?:\s*,\s*(\S+))?\s+in\s+(\S.*)\s*}/)
_pairs[10] = _regex(/(^|[^\\]){=[\S\s]*?}/)
_brackets._rawOffset = _pairs[0].length
}
_brackets.settings.brackets = cachedBrackets = pair
cachedBrackets = pair
}

function _brackets(reOrIdx) {
_reset(_brackets.settings.brackets)
return reOrIdx instanceof RegExp ? _regex(reOrIdx) : _pairs[reOrIdx]
}

_brackets.split = function split(str, tmpl, _bp) {
// istanbul ignore next: _bp is for the compiler
if (!_bp) {
_reset(_brackets.settings.brackets)
_bp = _pairs
}
if (!_bp) _bp = _pairs

var
parts = [],
Expand Down Expand Up @@ -167,9 +164,26 @@ var brackets = (function (UNDEF) {
}

_brackets.array = function array(pair) {
if (!pair) pair = _brackets.settings.brackets
return _create(pair)
return _create(pair || cachedBrackets)
}

var _settings
function _setSettings(o) {
var b
o = o || {}
b = o.brackets
Object.defineProperty(o, 'brackets', {
set: _reset,
get: function () { return cachedBrackets },
enumerable: true
})
_settings = o
_reset(b)
}
Object.defineProperty(_brackets, 'settings', {
set: _setSettings,
get: function () { return _settings }
})

/* istanbul ignore next: in the node version riot is not in the scope */
_brackets.settings = typeof riot !== 'undefined' && riot.settings || {}
Expand All @@ -179,8 +193,6 @@ var brackets = (function (UNDEF) {
_brackets.R_MLCOMMS = MLCOMMS
_brackets.S_QBLOCKS = S_QBSRC

_reset(_brackets.settings.brackets)

return _brackets

})()
Expand Down Expand Up @@ -208,7 +220,7 @@ var tmpl = (function () {
}

_tmpl.haveRaw = function (src) {
return brackets(/(^|[^\\]){=[\S\s]*?}/).test(src)
return brackets(10).test(src)
}

_tmpl.hasExpr = brackets.hasExpr
Expand Down Expand Up @@ -395,3 +407,5 @@ var tmpl = (function () {

})()

tmpl.version = brackets.version = 'WIP'

36 changes: 25 additions & 11 deletions dist/tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,19 @@
_pairs = _create(pair)
_regex = pair === DEFAULT ? _loopback : _rewrite
_pairs[9] = _regex(/^\s*{\^?\s*([$\w]+)(?:\s*,\s*(\S+))?\s+in\s+(\S.*)\s*}/)
_pairs[10] = _regex(/(^|[^\\]){=[\S\s]*?}/)
_brackets._rawOffset = _pairs[0].length
}
_brackets.settings.brackets = cachedBrackets = pair
cachedBrackets = pair
}

function _brackets(reOrIdx) {
_reset(_brackets.settings.brackets)
return reOrIdx instanceof RegExp ? _regex(reOrIdx) : _pairs[reOrIdx]
}

_brackets.split = function split(str, tmpl, _bp) {
// istanbul ignore next: _bp is for the compiler
if (!_bp) {
_reset(_brackets.settings.brackets)
_bp = _pairs
}
if (!_bp) _bp = _pairs

var
parts = [],
Expand Down Expand Up @@ -165,10 +162,27 @@
}

_brackets.array = function array(pair) {
if (!pair) pair = _brackets.settings.brackets
return _create(pair)
return _create(pair || cachedBrackets)
}

var _settings
function _setSettings(o) {
var b
o = o || {}
b = o.brackets
Object.defineProperty(o, 'brackets', {
set: _reset,
get: function () { return cachedBrackets },
enumerable: true
})
_settings = o
_reset(b)
}
Object.defineProperty(_brackets, 'settings', {
set: _setSettings,
get: function () { return _settings }
})

/* istanbul ignore next: in the node version riot is not in the scope */
_brackets.settings = typeof riot !== 'undefined' && riot.settings || {}
_brackets.set = _reset
Expand All @@ -177,8 +191,6 @@
_brackets.R_MLCOMMS = MLCOMMS
_brackets.S_QBLOCKS = S_QBSRC

_reset(_brackets.settings.brackets)

return _brackets

})()
Expand Down Expand Up @@ -206,7 +218,7 @@
}

_tmpl.haveRaw = function (src) {
return brackets(/(^|[^\\]){=[\S\s]*?}/).test(src)
return brackets(10).test(src)
}

_tmpl.hasExpr = brackets.hasExpr
Expand Down Expand Up @@ -393,6 +405,8 @@

})()

tmpl.version = brackets.version = 'WIP'

/* istanbul ignore else */
if (typeof module === 'object' && module.exports) {
module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ With a numeric parameter, returns a value based on current brackets according to
* 1: right bracket (`}`)
* 2: left escaped bracket (`{`)*
* 3: right escaped bracket (`}`)*
* 4: RegExp which matches an unescaped barckets pair (`/(?:^\|[^\\]){[^}]*}/`)\*\*
* 4: RegExp which matches a brackets pair (`/{[^}]*}/`)\*\*

\* only characters `[]()*+?.^$|` are escaped.

Expand All @@ -96,7 +96,7 @@ _parameters_
* `brackets_pair` : string - (optional) new custom brackets pair. The start and end is separated with a space character.

**NOTE:**
`riot.settings.brackets` and `brackets.settings` will be deprecated in future versions, please use `brackets.set` in new code.
From v2.3.15, changes in `riot.settings.brackets` are detected resulting in a call to `brackets.set` and the reconfiguration is immediate.


### `R_MLCOMMS` property
Expand Down
4 changes: 2 additions & 2 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ Ref: [riot#871](https://github.com/riot/riot/issues/871), [riot#1189](https://gi

## The new brackets function

brackets 2.3 combines the behavior of brackets 2.2 with a new one, based on a function to make immediate, more secure changes to custom brackets. There is a performance penalty in supporting both schemes, but compatibility is maintained.
brackets 2.3 combines the behavior of brackets 2.2 with a new one, based on a function to make immediate, more secure changes to custom brackets. ~~There is a performance penalty in supporting both schemes, but compatibility is maintained.~~

If riot is available when `brackets` is instantiated, `brackets` uses the configuration in `riot.settings`. In this way, `brackets` works as in previous versions and the reconfiguration is delayed to the first use.
If riot is not available, you can change the brackets through the new `brackets.set` function, which accepts the same parameter as `riot.settings.brackets` and makes the reconfiguration immediately.

**NOTE:**
`breackets.set` is the recommended and long term option to change the brackets, it is likely that `riot.settings` is deprecated in future versions.
From v2.3.15, brackets changes in browsers via `riot.settings.brackets` has immediate effect and always reflect the brackets in use, the `brackets.settings` property is not neccesary and will be removed in v2.4.0

It is all, syntax and behavior are the same as older versions: `brackets(regex_or_number)`.

Expand Down
36 changes: 25 additions & 11 deletions lib/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
//#set $_RIX_CLOSE = 7
//#set $_RIX_PAIR = 8
//#set $_RIX_LOOP = 9
//#set $_RIX_RAW = 10
//#ifndef $_RIX_TEST
var
$_RIX_TEST = 4, // DONT'T FORGET SYNC THE #set BLOCK!!!
$_RIX_ESC = 5,
$_RIX_OPEN = 6,
$_RIX_CLOSE = 7,
$_RIX_PAIR = 8,
$_RIX_LOOP = 9
$_RIX_LOOP = 9,
$_RIX_RAW = 10
//#endif

var brackets = (function (UNDEF) {
Expand Down Expand Up @@ -132,9 +134,10 @@ var brackets = (function (UNDEF) {
_pairs = _create(pair)
_regex = pair === DEFAULT ? _loopback : _rewrite
_pairs[$_RIX_LOOP] = _regex(/^\s*{\^?\s*([$\w]+)(?:\s*,\s*(\S+))?\s+in\s+(\S.*)\s*}/)
_pairs[$_RIX_RAW] = _regex(/(^|[^\\]){=[\S\s]*?}/)
_brackets._rawOffset = _pairs[0].length
}
_brackets.settings.brackets = cachedBrackets = pair // always set these
cachedBrackets = pair // always set these
}

// "Exported" functions
Expand All @@ -150,7 +153,6 @@ var brackets = (function (UNDEF) {
* @returns {RegExp|string} - Based on the received parameter
*/
function _brackets(reOrIdx) {
_reset(_brackets.settings.brackets)
return reOrIdx instanceof RegExp ? _regex(reOrIdx) : _pairs[reOrIdx]
}

Expand All @@ -166,10 +168,7 @@ var brackets = (function (UNDEF) {
*/
_brackets.split = function split(str, tmpl, _bp) {
// istanbul ignore next: _bp is for the compiler
if (!_bp) {
_reset(_brackets.settings.brackets)
_bp = _pairs
}
if (!_bp) _bp = _pairs

// Template text is easy: closing brackets are ignored, all we have to do is find
// the first unescaped bracket. The real work is with the expressions...
Expand Down Expand Up @@ -276,14 +275,31 @@ var brackets = (function (UNDEF) {
* @returns {Array} - Brackets array in internal format
*/
_brackets.array = function array(pair) {
if (!pair) pair = _brackets.settings.brackets // fix #1314
return _create(pair)
return _create(pair || cachedBrackets) // fix #1314
}

// Inmediate execution
// --------------------------------------------------------------------------

// Mirrors the `riot.settings`, you can assign this if riot is not in context
var _settings
function _setSettings(o) {
var b
o = o || {}
b = o.brackets
Object.defineProperty(o, 'brackets', {
set: _reset,
get: function () { return cachedBrackets },
enumerable: true
})
_settings = o
_reset(b)
}
Object.defineProperty(_brackets, 'settings', {
set: _setSettings,
get: function () { return _settings }
})

/* istanbul ignore next: in the node version riot is not in the scope */
_brackets.settings = typeof riot !== 'undefined' && riot.settings || {}
_brackets.set = _reset // or better use this
Expand All @@ -293,8 +309,6 @@ var brackets = (function (UNDEF) {
_brackets.R_MLCOMMS = MLCOMMS
_brackets.S_QBLOCKS = S_QBSRC

_reset(_brackets.settings.brackets) // set the initial state

return _brackets

})()
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

//#include tmpl

tmpl.version = brackets.version = 'WIP'

//#if NODE

// support CommonJS, AMD & browser
Expand Down
Loading

0 comments on commit 5ceb562

Please sign in to comment.