backbone_pageable_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alexey Astafyev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # BackbonePageableRails
2
+
3
+ Gem for backbone-pageable.js
4
+
5
+ More info about backbone-pageable [http://github.com/wyuenho/backbone-pageable](http://github.com/wyuenho/backbone-pageable)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'backbone_pageable_rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install backbone_pageable_rails
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'backbone_pageable_rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "backbone_pageable_rails"
8
+ gem.version = BackbonePageableRails::VERSION
9
+ gem.authors = ["Alexey Astafyev"]
10
+ gem.email = ["av.astafyev@gmail.com"]
11
+ gem.description = %q{Gem for backbone-pageable.js}
12
+ gem.summary = %q{Gem for backbone-pageable.js}
13
+ #gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "rails-backbone"
21
+ end
@@ -0,0 +1,6 @@
1
+ require "backbone_pageable_rails/version"
2
+ require "backbone_pageable_rails/engine"
3
+
4
+ module BackbonePageableRails
5
+
6
+ end
@@ -0,0 +1,5 @@
1
+ module BackbonePageableRails
2
+ class Engine < ::Rails::Engine
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module BackbonePageableRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ /*
2
+ backbone-pageable 1.3.1
3
+ http://github.com/wyuenho/backbone-pageable
4
+
5
+ Copyright (c) 2013 Jimmy Yuen Ho Wong
6
+ Licensed under the MIT @license.
7
+ */
8
+ !function(e){if("object"==typeof exports)module.exports=e(require("underscore"),require("backbone"));else if("function"==typeof define&&define.amd)define(["underscore","backbone"],e);else if("undefined"!=typeof _&&"undefined"!=typeof Backbone){var t=Backbone.PageableCollection,r=Backbone.PageableCollection=e(_,Backbone);Backbone.PageableCollection.noConflict=function(){return Backbone.PageableCollection=t,r}}}(function(e,t){"use strict";function r(t,r){if(!e.isNumber(t)||e.isNaN(t)||!e.isFinite(t)||~~t!==t)throw new TypeError("`"+r+"` must be a finite integer");return t}function s(e){for(var t,r,s,a,i={},n=decodeURIComponent,o=e.split("&"),l=0,c=o.length;c>l;l++){var u=o[l];t=u.split("="),r=t[0],s=t[1]||!0,r=n(r),a=i[r],g(a)?a.push(s):i[r]=a?[a,s]:s}return i}var a=e.extend,i=e.omit,n=e.clone,o=e.each,l=e.pick,c=e.contains,u=e.isEmpty,f=e.pairs,h=e.invert,g=e.isArray,d=e.isFunction,P=e.isObject,v=e.keys,p=e.isUndefined,m=e.result,k=Math.ceil,y=Math.floor,b=Math.max,S=t.Collection.prototype,_=/[\s'"]/g,C=/[<>\s'"]/g,R=t.Collection.extend({state:{firstPage:1,lastPage:null,currentPage:null,pageSize:25,totalPages:null,totalRecords:null,sortKey:null,order:-1},mode:"server",queryParams:{currentPage:"page",pageSize:"per_page",totalPages:"total_pages",totalRecords:"total_entries",sortKey:"sort_by",order:"order",directions:{"-1":"asc",1:"desc"}},constructor:function(e,r){t.Collection.apply(this,arguments),r=r||{};var s=this.mode=r.mode||this.mode||x.mode,i=a({},x.queryParams,this.queryParams,r.queryParams||{});i.directions=a({},x.queryParams.directions,this.queryParams.directions,i.directions||{}),this.queryParams=i;var o=this.state=a({},x.state,this.state,r.state||{});o.currentPage=null==o.currentPage?o.firstPage:o.currentPage,g(e)||(e=e?[e]:[]),"server"==s||null!=o.totalRecords||u(e)||(o.totalRecords=e.length),this.switchMode(s,a({fetch:!1,resetState:!1,models:e},r));var l=r.comparator;if(o.sortKey&&!l&&this.setSorting(o.sortKey,o.order,r),"server"!=s){var c=this.fullCollection;l&&r.full&&(delete this.comparator,c.comparator=l),r.full&&c.sort(),e&&!u(e)&&(this.getPage(o.currentPage),e.splice.apply(e,[0,e.length].concat(this.models)))}this._initState=n(this.state)},_makeFullCollection:function(e,r){var s,a,i,n=["url","model","sync","comparator"],o=this.constructor.prototype,l={};for(s=0,a=n.length;a>s;s++)i=n[s],p(o[i])||(l[i]=o[i]);var c=new(t.Collection.extend(l))(e,r);for(s=0,a=n.length;a>s;s++)i=n[s],this[i]!==o[i]&&(c[i]=this[i]);return c},_makeCollectionEventHandler:function(e,t){return function(r,s,i,l){var c=e._handlers;o(v(c),function(r){var s=c[r];e.off(r,s),t.off(r,s)});var u=n(e.state),f=u.firstPage,h=0===f?u.currentPage:u.currentPage-1,g=u.pageSize,d=h*g,P=d+g;if("add"==r){var m,y,b,S,l=l||{};if(i==t)y=t.indexOf(s),y>=d&&P>y&&(S=e,m=b=y-d);else{m=e.indexOf(s),y=d+m,S=t;var b=p(l.at)?y:l.at+d}if(++u.totalRecords,e.state=e._checkState(u),S){S.add(s,a({},l||{},{at:b}));var _=m>=g?s:!p(l.at)&&P>b&&e.length>g?e.at(g):null;if(_){var C=i._events.add||[],R={onAdd:!0};if(C.length){var x=C[C.length-1],w=x.callback;x.callback=function(){try{w.apply(this,arguments),e.remove(_,R)}finally{x.callback=w}}}else e.remove(_,R)}}}if("remove"==r)if(l.onAdd)delete l.onAdd;else{if(--u.totalRecords){var q=u.totalPages=k(u.totalRecords/g);u.lastPage=0===f?q-1:q,u.currentPage>q&&(u.currentPage=u.lastPage)}else u.totalRecords=null,u.totalPages=null;e.state=e._checkState(u);var z,E=l.index;i==e?((z=t.at(P))&&e.push(z),t.remove(s)):E>=d&&P>E&&(e.remove(s),z=t.at(h*(g+E)),z&&e.push(z))}if("reset"==r)if(l=i,i=s,i===e&&null==l.from&&null==l.to){var K=t.models.slice(0,d),B=t.models.slice(d+e.models.length);t.reset(K.concat(e.models).concat(B),l)}else i===t&&((u.totalRecords=t.models.length)||(u.totalRecords=null,u.totalPages=null),"client"==e.mode&&(u.lastPage=u.currentPage=u.firstPage),e.state=e._checkState(u),e.reset(t.models.slice(d,P),a({},l,{parse:!1})));"sort"==r&&(l=i,i=s,i===t&&e.reset(t.models.slice(d,P),a({},l,{parse:!1}))),o(v(c),function(r){var s=c[r];o([e,t],function(e){e.on(r,s);var t=e._events[r]||[];t.unshift(t.pop())})})}},_checkState:function(e){var t=this.mode,s=this.links,a=e.totalRecords,i=e.pageSize,n=e.currentPage,o=e.firstPage,l=e.totalPages;if(null!=a&&null!=i&&null!=n&&null!=o&&("infinite"==t?s:!0)){if(a=r(a,"totalRecords"),i=r(i,"pageSize"),n=r(n,"currentPage"),o=r(o,"firstPage"),1>i)throw new RangeError("`pageSize` must be >= 1");if(l=e.totalPages=k(a/i),0>o||o>1)throw new RangeError("`firstPage must be 0 or 1`");if(e.lastPage=0===o?b(0,l-1):l,"infinite"==t){if(!s[n+""])throw new RangeError("No link found for page "+n)}else if(o>n||l>0&&(o?n>l:n>=l))throw new RangeError("`currentPage` must be firstPage <= currentPage "+(o?">":">=")+" totalPages if "+o+"-based. Got "+n+".")}return e},setPageSize:function(e,t){e=r(e,"pageSize"),t=t||{first:!1};var s=this.state,n=k(s.totalRecords/e),o=b(s.firstPage,y(n*(s.firstPage?s.currentPage:s.currentPage+1)/s.totalPages));return s=this.state=this._checkState(a({},s,{pageSize:e,currentPage:t.first?s.firstPage:o,totalPages:n})),this.getPage(s.currentPage,i(t,["first"]))},switchMode:function(t,r){if(!c(["server","client","infinite"],t))throw new TypeError('`mode` must be one of "server", "client" or "infinite"');r=r||{fetch:!0,resetState:!0};var s=this.state=r.resetState?n(this._initState):this._checkState(a({},this.state));this.mode=t;var l,u=this,f=this.fullCollection,h=this._handlers=this._handlers||{};if("server"==t||f)"server"==t&&f&&(o(v(h),function(e){l=h[e],u.off(e,l),f.off(e,l)}),delete this._handlers,this._fullComparator=f.comparator,delete this.fullCollection);else{f=this._makeFullCollection(r.models||[]),f.pageableCollection=this,this.fullCollection=f;var g=this._makeCollectionEventHandler(this,f);o(["add","remove","reset","sort"],function(t){h[t]=l=e.bind(g,{},t),u.on(t,l),f.on(t,l)}),f.comparator=this._fullComparator}if("infinite"==t)for(var d=this.links={},P=s.firstPage,p=k(s.totalRecords/s.pageSize),m=0===P?b(0,p-1):p||P,y=s.firstPage;m>=y;y++)d[y]=this.url;else this.links&&delete this.links;return r.fetch?this.fetch(i(r,"fetch","resetState")):this},hasPrevious:function(){var e=this.state,t=e.currentPage;return"infinite"!=this.mode?t>e.firstPage:!!this.links[t-1]},hasNext:function(){var e=this.state,t=this.state.currentPage;return"infinite"!=this.mode?t<e.lastPage:!!this.links[t+1]},getFirstPage:function(e){return this.getPage("first",e)},getPreviousPage:function(e){return this.getPage("prev",e)},getNextPage:function(e){return this.getPage("next",e)},getLastPage:function(e){return this.getPage("last",e)},getPage:function(e,t){var s=this.mode,n=this.fullCollection;t=t||{fetch:!1};var o=this.state,l=o.firstPage,c=o.currentPage,f=o.lastPage,h=o.pageSize,g=e;switch(e){case"first":g=l;break;case"prev":g=c-1;break;case"next":g=c+1;break;case"last":g=f;break;default:g=r(e,"index")}this.state=this._checkState(a({},o,{currentPage:g})),t.from=c,t.to=g;var d=(0===l?g:g-1)*h,P=n&&n.length?n.models.slice(d,d+h):[];return"client"!=s&&("infinite"!=s||u(P))||t.fetch?("infinite"==s&&(t.url=this.links[g]),this.fetch(i(t,"fetch"))):this.reset(P,i(t,"fetch"))},getPageByOffset:function(e,t){if(0>e)throw new RangeError("`offset must be > 0`");e=r(e);var s=y(e/this.state.pageSize);return 0!==this.state.firstPage&&s++,s>this.state.lastPage&&(s=this.state.lastPage),this.getPage(s,t)},sync:function(e,r,s){var i=this;if("infinite"==i.mode){var n=s.success,o=i.state.currentPage;s.success=function(e,t,r){var l=i.links,c=i.parseLinks(e,a({xhr:r},s));c.first&&(l[i.state.firstPage]=c.first),c.prev&&(l[o-1]=c.prev),c.next&&(l[o+1]=c.next),n&&n(e,t,r)}}return(S.sync||t.sync).call(i,e,r,s)},parseLinks:function(e,t){var r={},a=t.xhr.getResponseHeader("Link");if(a){var i=["first","prev","previous","next","last"];o(a.split(","),function(e){var t=e.split(";"),s=t[0].replace(C,""),a=t.slice(1);o(a,function(e){var t=e.split("="),a=t[0].replace(_,""),n=t[1].replace(_,"");"rel"==a&&c(i,n)&&("previous"==n?r.prev=s:r[n]=s)})});var l,u,f=r.last||"";if(u=(l=f.indexOf("?"))?f.slice(l+1):""){var h=s(u),g=n(this.state),d=this.queryParams,P=g.pageSize,v=1*h[d.totalRecords],p=1*h[d.currentPage],m=h[d.totalPages];v||(p?v=(0===g.firstPage?p+1:p)*P:m&&(v=m*P)),v&&(g.totalRecords=v),this.state=this._checkState(g)}}return delete r.last,r},parse:function(e,t){var r=this.parseState(e,n(this.queryParams),n(this.state),t);return r&&(this.state=this._checkState(a({},this.state,r))),this.parseRecords(e,t)},parseState:function(t,r,s){if(t&&2===t.length&&P(t[0])&&g(t[1])){var a=n(s),l=t[0];return o(f(i(r,"directions")),function(t){var r=t[0],s=t[1],i=l[s];p(i)||e.isNull(i)||(a[r]=l[s])}),l.order&&(a.order=1*h(r.directions)[l.order]),a}},parseRecords:function(e){return e&&2===e.length&&P(e[0])&&g(e[1])?e[1]:e},fetch:function(e){e=e||{};var t=this._checkState(this.state),r=this.mode;"infinite"!=r||e.url||(e.url=this.links[t.currentPage]);var o=e.data||{},c=m(e,"url")||m(this,"url")||"",u=c.indexOf("?");-1!=u&&(a(o,s(c.slice(u+1))),c=c.slice(0,u)),e.url=c,e.data=o;var h,g,P,k,y="client"==this.mode?l(this.queryParams,"sortKey","order"):i(l(this.queryParams,v(x.queryParams)),"directions"),b=f(y),_=n(this);for(h=0;h<b.length;h++)g=b[h],P=g[0],k=g[1],k=d(k)?k.call(_):k,null!=t[P]&&null!=k&&(o[k]=t[P]);t.sortKey&&t.order?o[y.order]=this.queryParams.directions[t.order+""]:t.sortKey||delete o[y.order];var C=f(i(this.queryParams,v(x.queryParams)));for(h=0;h<C.length;h++)g=C[h],k=g[1],k=d(k)?k.call(_):k,null!=k&&(o[g[0]]=k);var R=this.fullCollection,w=this.links;if("server"!=r){var q=this,z=e.success;return e.success=function(s,i,n){n=n||{},p(e.silent)?delete n.silent:n.silent=e.silent;var o=s.models,l=t.currentPage;if("client"==r)R.reset(o,n);else if(w[l]){var c=t.pageSize,u=(0===t.firstPage?l:l-1)*c,f=R.models,h=f.slice(0,u),g=f.slice(u+c);f=h.concat(o).concat(g);var d=R.set||R.update;d.call(R,f,a({silent:!0},n)),R.trigger("reset",R,n)}else R.add(o,a({at:R.length},n));z&&z(s,i,n)},S.fetch.call(q,a({},e,{silent:!0}))}return S.fetch.call(this,e)},_makeComparator:function(e,t,r){var s=this.state;return e=e||s.sortKey,t=t||s.order,e&&t?(r||(r=function(e,t){return e.get(t)}),function(s,a){var i,n=r(s,e),o=r(a,e);return 1===t&&(i=n,n=o,o=i),n===o?0:o>n?-1:1}):void 0},setSorting:function(e,t,r){var s=this.state;s.sortKey=e,s.order=t=t||s.order;var i=this.fullCollection,n=!1,o=!1;e||(n=o=!0);var l=this.mode;r=a({side:"client"==l?l:"server",full:!0},r);var c=this._makeComparator(e,t,r.sortValue),u=r.full,f=r.side;return"client"==f?u?(i&&(i.comparator=c),n=!0):(this.comparator=c,o=!0):"server"!=f||u||(this.comparator=c),n&&delete this.comparator,o&&i&&delete i.comparator,this}}),x=R.prototype;return R});
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backbone_pageable_rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Alexey Astafyev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ none: false
21
+ prerelease: false
22
+ name: rails-backbone
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ none: false
29
+ type: :runtime
30
+ description: Gem for backbone-pageable.js
31
+ email:
32
+ - av.astafyev@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - CHANGELOG
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - backbone_pageable_rails.gemspec
44
+ - lib/backbone_pageable_rails.rb
45
+ - lib/backbone_pageable_rails/engine.rb
46
+ - lib/backbone_pageable_rails/version.rb
47
+ - vendor/assets/javascript/backbone-pageable.min.js
48
+ homepage:
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ segments:
60
+ - 0
61
+ hash: 3690318121028249319
62
+ none: false
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ segments:
69
+ - 0
70
+ hash: 3690318121028249319
71
+ none: false
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.24
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Gem for backbone-pageable.js
78
+ test_files: []