Skip to content

Commit

Permalink
Renamed plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Artyom 'Sleepwalker' Fedosov committed Feb 17, 2015
1 parent c7d30b6 commit 6d056c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright © 2014 Artyom Fedosov <[email protected]>
Copyright © 2015 Artyom Fedosov <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the «Software»), to deal in
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Underscore.ExtendedWhere
#Underscore.Excerpt

Smarter select from [Underscore.js][] and [Backbone.js][] collections.
Smarter select query from [Underscore.js][] and [Backbone.js][] collections.

```
var kitties = felids.extendedWhere({
var kitties = felids.excerpt({
species: 'cat',
aggressive: {'operator': '==', value: false}, // Has not remarks
ageInDays: {'operator': '<', value: 50}
Expand Down
18 changes: 10 additions & 8 deletions underscore.extendedwhere.js → underscore.excerpt.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/*
* Underscore.ExtendedWhere, v1.0
* (c) 2014 Artyom "Sleepwalker" Fedosov <[email protected]>
* https://github.com/asleepwalker/underscore.extendedwhere
* Underscore.Excerpt, v1.0.1
* (c) 2015 Artyom "Sleepwalker" Fedosov <[email protected]>
* https://github.com/asleepwalker/underscore.excerpt
*/

_.extendedWhere = function(list, attrs, after) {
_.excerpt = function(list, attrs, after) {
var direct = {},
expressions = {},
matched = [];

for (var key in attrs) {
if (_.has(attrs[key], 'operator') && _.has(attrs[key], 'value'))
if (_.has(attrs[key], 'operator') && _.has(attrs[key], 'value')) {
expressions[key] = attrs[key];
else direct[key] = attrs[key];
} else {
direct[key] = attrs[key];
}
}

matched = list.where(direct);
Expand All @@ -35,7 +37,7 @@ _.extendedWhere = function(list, attrs, after) {
};

if (Backbone) {
Backbone.Collection.prototype.extendedWhere = function(attrs, after) {
return _.extendedWhere(this, attrs, after);
Backbone.Collection.prototype.excerpt = function(attrs, after) {
return _.excerpt(this, attrs, after);
};
}

0 comments on commit 6d056c4

Please sign in to comment.