Skip to content

Commit

Permalink
custom rules by regexp, #43
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Bardanov committed Feb 6, 2015
1 parent 7e8eaa4 commit ff605ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion templates/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1 class="dialog-title">Documents toolbar settings</h1>
<div class="_row">
<span>Apply to</span>
<input data-bind="value: name"/>
<div class="muted">You can apply rules to set of files. Example: *.css</div>
<div class="muted">You can apply rules to set of files. Example: *.css. Use <a href="http://www.w3schools.com/jsref/jsref_obj_regexp.asp">RegExp</a> to construct complex rules.</div>
</div>
<div class="_row">
<input type="checkbox" data-bind="checked: forThisProjectOnly"/>
Expand Down
16 changes: 14 additions & 2 deletions viewmodels/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ define(function(require, exports, module){

return _.find(rules, function(rule){
var query = rule.name.replace('*', ''),
currentProject;
currentProject, filterByFile, filterByRegex,
flags, pattern, regex;

if (rule.project){
currentProject = self.getCurrentProjectName();
Expand All @@ -229,7 +230,18 @@ define(function(require, exports, module){
}
}

return file._name.indexOf(query) >= 0;
filterByFile = file._name.indexOf(query) >= 0;

if (query.indexOf('/') !== -1){
flags = query.replace(/.*\/([gimy]*)$/, '$1');
pattern = query.replace(new RegExp('^/(.*?)/'+flags+'$'), '$1');
regex = new RegExp(pattern, flags);
filterByRegex = !!file._parentPath.match(regex) || !!file._name.match(regex);
} else {
filterByRegex = false;
}

return filterByFile || filterByRegex;
});
}

Expand Down

0 comments on commit ff605ad

Please sign in to comment.