85d3d710 by Michael Richards

Implement configuration option for setting a data attribute prefix. [Closes #4]

1 parent f81c4d1a
......@@ -60,11 +60,23 @@
this.build = __bind(this.build, this);
this.bindingRegExp = __bind(this.bindingRegExp, this);
this.build();
}
View.prototype.bindingRegExp = function() {
var prefix;
prefix = Rivets.config.prefix;
if (prefix) {
return new RegExp("^data-" + prefix + "-");
} else {
return /^data-/;
}
};
View.prototype.build = function() {
var attribute, context, keypath, node, path, type, _i, _len, _ref, _results;
var attribute, context, dataRegExp, keypath, node, path, type, _i, _len, _ref, _results;
this.bindings = [];
_ref = this.el.getElementsByTagName('*');
_results = [];
......@@ -76,8 +88,9 @@
_results1 = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
attribute = _ref1[_j];
if (/^data-/.test(attribute.name)) {
type = attribute.name.replace('data-', '');
dataRegExp = new RegExp(this.data, 'g');
if (this.bindingRegExp().test(attribute.name)) {
type = attribute.name.replace(this.bindingRegExp(), '');
path = attribute.value.split('.');
context = this.contexts[path.shift()];
keypath = path.join('.');
......
......@@ -37,14 +37,20 @@ class Rivets.View
constructor: (@el, @contexts) ->
@build()
# The regular expression used to match Rivets.js data binding attributes.
bindingRegExp: =>
prefix = Rivets.config.prefix
if prefix then new RegExp("^data-#{prefix}-") else /^data-/
# Parses and builds new Rivets.Binding instances for the data bindings.
build: =>
@bindings = []
for node in @el.getElementsByTagName '*'
for attribute in node.attributes
if /^data-/.test attribute.name
type = attribute.name.replace 'data-', ''
dataRegExp = new RegExp(@data, 'g')
if @bindingRegExp().test attribute.name
type = attribute.name.replace @bindingRegExp(), ''
path = attribute.value.split '.'
context = @contexts[path.shift()]
keypath = path.join '.'
......