page_wrapper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +66 -9
- data/lib/page_wrapper/version.rb +1 -1
- data/lib/templates/model_page.rb +6 -5
- data/lib/templates/page_template.handlebars +7 -5
- data/lib/templates/page_view.js.coffee +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,24 +1,81 @@
|
|
1
|
-
|
1
|
+
## Page Wrapper ##
|
2
2
|
|
3
|
-
|
3
|
+
Page Wrapper helps you add pagination to a list of resources fetched
|
4
|
+
from a Rails server and rendered using Ember and Ember Data.
|
4
5
|
|
5
|
-
|
6
|
+
It contains:
|
7
|
+
|
8
|
+
* a page model class intended to be extended to wrap a list of resources
|
9
|
+
into a page
|
10
|
+
* a set of Ember classes to help fetching, browsing, sorting and
|
11
|
+
filtering the list of resources within an Ember application
|
12
|
+
* a generator for all the Ruby and CoffeeScript files you need to paginate
|
13
|
+
those resources
|
14
|
+
|
15
|
+
It requires a 3.1+ rails or rails-api application and a model to
|
16
|
+
paginate. There are no constraint on which ORM or plain old Ruby object
|
17
|
+
to use, or which tool to paginate or filter on the Ruby side. It is up
|
18
|
+
to you to code or integrate that part (i.e.: Active Record + Kaminari,
|
19
|
+
Mongoid + Kaminari, Remotely + Kaminari, etc...).
|
20
|
+
|
21
|
+
Finaly it is delegating most of the work to a set of great Ruby gems and
|
22
|
+
JavaScript libraries:
|
23
|
+
|
24
|
+
* [Rails API](https://github.com/spastorino/rails-api) or [Rails](http://rubyonrails.org/) for the web server
|
25
|
+
* [Active Model Serializers](https://github.com/josevalim/active_model_serializers/) to serialize the page instance and its collection
|
26
|
+
* [Ember Rails](https://github.com/emberjs/ember-rails) that comes with
|
27
|
+
[Ember](http://emberjs.com/) and [Ember Data](https://github.com/emberjs/data) for fetching the data from the browser and rendering the collections and browse it page by page
|
28
|
+
|
29
|
+
## Getting Started ##
|
30
|
+
|
31
|
+
Page Wrapper works with Rails 3.1 onwards and Ember Rails 0.6.0+.
|
6
32
|
|
7
33
|
Add this line to your application's Gemfile:
|
8
34
|
|
9
|
-
|
35
|
+
```ruby
|
36
|
+
gem 'page_wrapper'
|
37
|
+
```
|
10
38
|
|
11
39
|
And then execute:
|
12
40
|
|
13
|
-
|
41
|
+
```console
|
42
|
+
$ bundle
|
43
|
+
```
|
44
|
+
|
45
|
+
After you install Page Wrapper and add it to your Gemfile, you need to
|
46
|
+
run the generator. Assuming you want to paginate *Movie* resources:
|
47
|
+
|
48
|
+
```console
|
49
|
+
rails generate page_wrapper:page movie
|
50
|
+
```
|
51
|
+
|
52
|
+
This command will generate the Ruby and Ember classes required to
|
53
|
+
paginate a **Movie** model and add a route to the index action of the
|
54
|
+
new server movie page controller.
|
14
55
|
|
15
|
-
|
56
|
+
At that point you just need to update your Ember application routing
|
57
|
+
manager to route to the new front-end movie page controller. Here is an
|
58
|
+
example of a single page with an outlet setup to contain the list of
|
59
|
+
movies:
|
16
60
|
|
17
|
-
|
61
|
+
```coffeescript
|
62
|
+
# app/assets/javascripts/routes/app_router.js.coffee
|
18
63
|
|
19
|
-
|
64
|
+
App.Router = Ember.Router.extend
|
65
|
+
location: 'hash'
|
20
66
|
|
21
|
-
|
67
|
+
root: Ember.State.extend
|
68
|
+
index: Ember.State.extend
|
69
|
+
route: '/'
|
70
|
+
connectOutlets: (router) ->
|
71
|
+
controller = router.get('applicationController')
|
72
|
+
controller.connectOutlet(App.MoviePageView, App.MoviePageController::firstPage())
|
73
|
+
moviePageController = router.get('moviePageController')
|
74
|
+
moviePageController.set('target', moviePageController)
|
75
|
+
```
|
76
|
+
After reloading your application you should now look at the first page
|
77
|
+
and be able to interact with the pagination control to navigate
|
78
|
+
the collection page by page.
|
22
79
|
|
23
80
|
## Contributing
|
24
81
|
|
data/lib/page_wrapper/version.rb
CHANGED
data/lib/templates/model_page.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
<%- names = class_name.underscore.pluralize -%>
|
1
2
|
class <%= class_name.camelize %>Page < PageWrapper::Model
|
2
|
-
attr_reader :<%=
|
3
|
+
attr_reader :<%= names %>
|
3
4
|
|
4
5
|
def fetch_records(page, options)
|
5
6
|
# TODO: customize the logic below and consider moving it into
|
6
7
|
# a class method <%= class_name.camelize %>.paginated_query
|
7
8
|
# and simplify this method to a one-liner:
|
8
9
|
#
|
9
|
-
# @<%=
|
10
|
+
# @<%= names %> = <%= class_name.camelize %>.paginated_query(page, options)
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
@<%= names %> = <%= class_name.camelize %>.page(page)
|
13
|
+
@<%= names %> = @<%= names %>.per(options[:per_page]) if options[:per_page]
|
14
|
+
@<%= names %>
|
14
15
|
end
|
15
16
|
end
|
@@ -7,17 +7,19 @@
|
|
7
7
|
<table class="table table-bordered table-striped">
|
8
8
|
<thead>
|
9
9
|
<tr>
|
10
|
-
<th>
|
11
|
-
<th>
|
10
|
+
<th>Id</th>
|
11
|
+
<th>Title</th>
|
12
|
+
<th>Year</th>
|
12
13
|
</tr>
|
13
14
|
</thead>
|
14
15
|
|
15
16
|
<tbody>
|
16
17
|
{{#if controller.content.isLoaded}}
|
17
|
-
{{#each controller.currentPage.<%= class_name.
|
18
|
+
{{#each controller.currentPage.<%= class_name.underscore.pluralize %>}}
|
18
19
|
<tr>
|
19
|
-
<td>{{
|
20
|
-
<td>{{
|
20
|
+
<td>{{id}}</td>
|
21
|
+
<td>{{title}}</td>
|
22
|
+
<td>{{year}}</td>
|
21
23
|
</tr>
|
22
24
|
{{/each}}
|
23
25
|
{{/if}}
|
@@ -1,2 +1,2 @@
|
|
1
1
|
App.<%= class_name.camelize %>PageView = Ember.View.extend
|
2
|
-
templateName: '<%= class_name.underscore %>'
|
2
|
+
templateName: '<%= class_name.underscore %>_page'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
segments:
|
90
90
|
- 0
|
91
|
-
hash:
|
91
|
+
hash: 1937236751138719714
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
none: false
|
94
94
|
requirements:
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
segments:
|
99
99
|
- 0
|
100
|
-
hash:
|
100
|
+
hash: 1937236751138719714
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
103
|
rubygems_version: 1.8.23
|