flexible_datatables 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a13f848d1e7169a66d108830a47d8289e6476c33
4
- data.tar.gz: 3d2bfa335369d77870971e5085a5a70bb26171ed
3
+ metadata.gz: 22a22794a1f6a65928133accc5770f4f8bcc2567
4
+ data.tar.gz: afeb755aaa7c2f7525a2c9f3c9a19aea0d17e197
5
5
  SHA512:
6
- metadata.gz: d1dae4b484f9791480a47c4a9ffdb968f074f5c09bf13a9e21a4b9aa347a21a05e479e38b2ddfe2bcd468d54249f4c536fa48d9c1f29d5ab2f3dbd15f3122759
7
- data.tar.gz: eb9b00b5cf65177cd9f05671a4b51ebe91e9319e68c3ce5cf0f031f0e765486d26cafb827c0550230a67bab8df1f985ef2cb53ede217e7cda5393cfe6c9f720b
6
+ metadata.gz: f1da69724072382a1b800f9e5eb7d7264a0e3095469b2da4538997963c6c210355b1192ced4aca938296b79b476298ef4974ca71cecb5abc28088604030385a2
7
+ data.tar.gz: 534c1713cd72815d2b4a1f6c4e4fd529aa10d45173def7ba4032152efea5308969a0795ff164a768e455d2f5f02ee3d0bfb51fd1c0efd56f9843d537c17c0461
data/CHANGELOG CHANGED
@@ -3,7 +3,18 @@ Change Log
3
3
 
4
4
  All notable changes to the project are documented in this file.
5
5
 
6
- [1.0.0] - 2015-02-14
6
+ [v1.0.1] - 2015-02-15
7
7
  --------------------
8
8
 
9
- Version 1 release of the library.
9
+ ca4badc Don't use 'blank?', which is an enhancement to Ruby from Rails, because obviously the code won't work outside of Rails
10
+ e621434 refer to the default DummyPaginator using the full namespace
11
+ 4bb3085 Instantiate a Settings object when Configurator is defined, so default settings are available without needing to call Configurator.configuration first
12
+ 513db65 pull in paginators and configurator definitions first
13
+ 95d38a5 tweak file list
14
+ 2308215 use rdoc for the README
15
+
16
+ [v1.0.0] - 2015-02-14
17
+ --------------------
18
+
19
+ 38c6db1 initial commit
20
+
data/CHANGELOG.md CHANGED
@@ -3,7 +3,18 @@ Change Log
3
3
 
4
4
  All notable changes to the project are documented in this file.
5
5
 
6
- [1.0.0] - 2015-02-14
6
+ [v1.0.1] - 2015-02-15
7
7
  --------------------
8
8
 
9
- Version 1 release of the library.
9
+ ca4badc Don't use 'blank?', which is an enhancement to Ruby from Rails, because obviously the code won't work outside of Rails
10
+ e621434 refer to the default DummyPaginator using the full namespace
11
+ 4bb3085 Instantiate a Settings object when Configurator is defined, so default settings are available without needing to call Configurator.configuration first
12
+ 513db65 pull in paginators and configurator definitions first
13
+ 95d38a5 tweak file list
14
+ 2308215 use rdoc for the README
15
+
16
+ [v1.0.0] - 2015-02-14
17
+ --------------------
18
+
19
+ 38c6db1 initial commit
20
+
data/README.rdoc ADDED
@@ -0,0 +1,107 @@
1
+ = Flexible Datatables
2
+ Easily integrate {JQuery Datatables}[https://www.datatables.net] (with Ajax) into your Ruby / Rails web applications.
3
+
4
+ == Introduction
5
+ Flexible Datatables wraps array-like objects (ActiveRecord::Relation collections, etc) that JQuery Datatables can read (via ajax) from your Ruby / Rails web application.
6
+
7
+ == Features
8
+ * Any arbitrary array-like collection of data, from plain old ruby arrays to complicated ActiveRecord (or Arel, or plain SQL) query results, can be passed on to JQuery Datatables with very little configuration overhead.
9
+ * Server-side pagination with {Kaminari}[https://github.com/amatsuda/kaminari] can be used, out of the box.
10
+
11
+ == Background
12
+ This library was inspired by Ryan Bates' excellent {Railscast episode}[http://railscasts.com/episodes/340-datatables] and the {ajax-datatables-rails}[https://github.com/antillas21/ajax-datatables-rails] gem.
13
+
14
+ So why not just use {ajax-datatables-rails}[https://github.com/antillas21/ajax-datatables-rails]?
15
+
16
+ 1. I wanted to be free to use (abuse) SQL to generate the result set to be passed to DataTables. The {ajax-datatables-rails}[https://github.com/antillas21/ajax-datatables-rails] library constructs ActiveRecord queries on the application's behalf, based on user-supplied column names.
17
+ 2. I also wanted to the ability to sort on any kind of column, from integer column types to non-string / non-text based columns, to aggregate functions, and so on.
18
+ 3. Although I usually choose PostgreSQL as my Rails DB backend of choice, I wanted to be able to pass in any kind of array-like collection (or even use a different database backend altogether).
19
+
20
+ == Installation
21
+ 1. First, make sure you have {DataTables}[https://www.datatables.net] installed.
22
+ You have a few choices here. If you are integrating DataTables with a Rails project, the easiest route is via the {jquery-datatables-rails}[https://github.com/rweng/jquery-datatables-rails] gem. Be sure to follow the installation instructions if you choose this route.
23
+ You can also use {bower}[https://github.com/rharriso/bower-rails], or you can even leverage DataTables' {cdn}[https://cdn.datatables.net/].
24
+
25
+ 2. Add this line to your application's <tt>Gemfile</tt>:
26
+
27
+ gem 'flexible_datatables'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install flexible_datatables
36
+
37
+ 3. (optional) Create the file <tt>config/initializers/flexible_datatables.rb</tt>. You can use this to override default values (such as the choice of pagination).
38
+
39
+ FlexibleDatatables.configuration do |settings|
40
+ # settings.paginator = FlexibleDatatables::KaminariPaginator
41
+ settings.paginator = FlexibleDatatables::SimplePaginator
42
+ # settings.items_per_page = 10
43
+ end
44
+
45
+ == Usage
46
+ === Rails
47
+ <b>NOTE</b>
48
+
49
+ Flexible Datatables isn't required if you wish to use DataTables to transform an html <tt>table</tt> without using ajax (see the first part of the {DataTables RailsCast}[http://railscasts.com/episodes/340-datatables?view=asciicast] for reference).
50
+
51
+ The benefit of using Flexible Datatables comes when one wishes to have DataTables tables displaying data from a Rails backend using ajax.
52
+
53
+ ==== Controller
54
+ 1. Flexible Datatables requires the <tt>draw</tt>, <tt>start</tt>, <tt>length</tt>, and <tt>order</tt> keys from the <tt>params</tt> hash. Initialize a new <tt>FlexibleDatatables::Datatable</tt> object and pass in those values.
55
+
56
+ datatable = FlexibleDatatables::Datatable.new(params.slice(:draw, :start, :length, :order))
57
+
58
+ 2. Pass in a collection of objects (which can come from anywhere; an array, an ActiveRecord query, etc)
59
+
60
+ datatable.collection = MyModel.all
61
+
62
+ 3. Tell your <tt>Datatable</tt> object what your columns are and how to arrange them into rows.
63
+
64
+ datatable.format_grid(%w(first_column, second_column, third_column) do |record|
65
+ [record.first_column, record.second_column, record.third_column]
66
+ end
67
+
68
+ 4. Instruct Rails to render your <tt>Datatable</tt> object as <tt>JSON</tt>. Your controller may look something like this:
69
+
70
+ respond_to do |format|
71
+ format.html
72
+ format.json do
73
+ datatable = FlexibleDatatables::Datatable.new(params.slice(:draw, :start, :length, :order))
74
+ datatable.collection = MyModel.all
75
+ datatable.format_grid(%w(first_column, second_column, third_column) do |record|
76
+ [record.first_column, record.second_column, record.third_column]
77
+ end
78
+ render json: datatable
79
+ end
80
+ end
81
+
82
+ ==== View
83
+ 1. Define a <tt>table</tt> with an <tt>id</tt> attribute.
84
+ 2. Give the <tt>table</tt> a <tt>data-source</tt> attribute that points to the route that DataTables will use to get the json data over ajax.
85
+ 3. Give this <tt>table</tt> a <tt>thead</tt> with some header columns, and an empty <tt>tbody</tt> declaration.
86
+
87
+ ==== JavaScript
88
+ Finally, in a javascript file, call <tt>.DataTable()</tt> and pass in values for the <tt>processing</tt>, <tt>serverSide</tt>, <tt>ajax</tt>, and <tt>pagingType</tt> parameters.
89
+
90
+ $ ->
91
+ $('#my_table_id').DataTable
92
+ processing: true
93
+ serverSide: true
94
+ ajax: $('#my_table_id').data('source')
95
+ pagingType: "full_numbers"
96
+
97
+ == Contributing
98
+
99
+ 1. Fork it
100
+ 2. Create your feature branch (<tt>git checkout -b my-new-feature</tt>)
101
+ 3. Commit your changes (<tt>git commit -am 'Added some feature'</tt>)
102
+ 4. Push to the branch (<tt>git push origin my-new-feature</tt>)
103
+ 5. Create new Pull Request
104
+
105
+ == License
106
+
107
+ GPL-3.0+
@@ -1,3 +1,8 @@
1
+ require 'ostruct'
2
+ require 'flexible_datatables/paginators'
3
+ require 'flexible_datatables/configurator'
4
+ require 'flexible_datatables/datatable'
5
+
1
6
  module FlexibleDatatables
2
7
  def self.configuration
3
8
  Configurator.configuration do |config|
@@ -9,8 +14,3 @@ module FlexibleDatatables
9
14
  Configurator.settings
10
15
  end
11
16
  end
12
-
13
- require 'ostruct'
14
- require 'flexible_datatables/datatable'
15
- require 'flexible_datatables/configurator'
16
- require 'flexible_datatables/paginators'
@@ -5,12 +5,12 @@ module FlexibleDatatables
5
5
 
6
6
  def initialize
7
7
  @items_per_page = 10
8
- @paginator = DummyPaginator
8
+ @paginator = ::FlexibleDatatables::DummyPaginator
9
9
  end
10
10
  end
11
11
 
12
+ @@settings = Settings.new
12
13
  def self.configuration
13
- @@settings ||= Settings.new
14
14
  yield(@@settings)
15
15
  end
16
16
 
@@ -21,8 +21,8 @@ module FlexibleDatatables
21
21
  }
22
22
  end
23
23
 
24
- def format_grid(cols)
25
- @columns = cols unless cols.blank?
24
+ def format_grid(cols = [])
25
+ @columns = cols unless cols.empty?
26
26
  records = collection.order("#{sort_column} #{sort_direction}")
27
27
  @grid = paginate(records).map { |record| yield(record) }
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module FlexibleDatatables
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexible_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Corning
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-14 00:00:00.000000000 Z
11
+ date: 2015-02-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Flexible Datatables wraps array-like objects (ActiveRecord::Relation
14
14
  collections, etc) that JQuery Datatables can read (via ajax) from your Ruby / Rails
@@ -20,7 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - CHANGELOG
22
22
  - CHANGELOG.md
23
- - README.md
23
+ - README.rdoc
24
24
  - lib/flexible_datatables.rb
25
25
  - lib/flexible_datatables/configurator.rb
26
26
  - lib/flexible_datatables/datatable.rb
@@ -55,3 +55,4 @@ specification_version: 4
55
55
  summary: Easily integrate JQuery Datatables (with Ajax) into your Ruby / Rails web
56
56
  applications.
57
57
  test_files: []
58
+ has_rdoc:
data/README.md DELETED
@@ -1,112 +0,0 @@
1
- # Flexible Datatables
2
-
3
- Easily integrate [JQuery Datatables](https://www.datatables.net) (with Ajax) into your Ruby / Rails web applications.
4
-
5
- ## Introduction
6
- Flexible Datatables wraps array-like objects (ActiveRecord::Relation collections, etc) that JQuery Datatables can read (via ajax) from your Ruby / Rails web application.
7
-
8
- ## Features
9
- * Any arbitrary array-like collection of data, from plain old ruby arrays to complicated ActiveRecord (or Arel, or plain SQL) query results, can be passed on to JQuery Datatables with very little configuration overhead.
10
- * Server-side pagination with [Kaminari](https://github.com/amatsuda/kaminari) can be used, out of the box.
11
-
12
- ## Background
13
- This library was inspired by Ryan Bates' excellent [Railscast episode](http://railscasts.com/episodes/340-datatables) and the [ajax-datatables-rails](https://github.com/antillas21/ajax-datatables-rails) gem.
14
-
15
- So why not just use [ajax-datatables-rails](https://github.com/antillas21/ajax-datatables-rails)?
16
-
17
- 1. I wanted to be free to use (abuse) SQL to generate the result set to be passed to DataTables. The [ajax-datatables-rails](https://github.com/antillas21/ajax-datatables-rails) library constructs ActiveRecord queries on the application's behalf, based on user-supplied column names.
18
- 2. I also wanted to the ability to sort on any kind of column, from integer column types to non-string / non-text based columns, to aggregate functions, and so on.
19
- 3. Although I usually choose PostgreSQL as my Rails DB backend of choice, I wanted to be able to pass in any kind of array-like collection (or even use a different database backend altogether).
20
-
21
- ## Installation
22
- 1. First, make sure you have [DataTables](https://www.datatables.net) installed.
23
-
24
- You have a few choices here. If you are integrating DataTables with a Rails project, the easiest route is via the [jquery-datatables-rails](https://github.com/rweng/jquery-datatables-rails) gem. Be sure to follow the installation instructions if you choose this route.
25
-
26
- You can also use [bower](https://github.com/rharriso/bower-rails), or you can even leverage DataTables' [cdn](https://cdn.datatables.net/).
27
-
28
- 2. Add this line to your application's `Gemfile`:
29
-
30
- gem 'flexible_datatables'
31
-
32
- And then execute:
33
-
34
- $ bundle
35
-
36
- Or install it yourself as:
37
-
38
- $ gem install flexible_datatables
39
- 3. (optional) Create the file `config/initializers/flexible_datatables.rb`. You can use this to override default values (such as the choice of pagination).
40
- ```ruby
41
- FlexibleDatatables.configuration do |settings|
42
- # settings.paginator = FlexibleDatatables::KaminariPaginator
43
- settings.paginator = FlexibleDatatables::SimplePaginator
44
- # settings.items_per_page = 10
45
- end
46
- ```
47
-
48
- ## Usage
49
- ### Rails
50
- *NOTE*
51
-
52
- Flexible Datatables isn't required if you wish to use DataTables to transform an html `table` without using ajax (see the first part of the [DataTables RailsCast](http://railscasts.com/episodes/340-datatables?view=asciicast) for reference).
53
-
54
- The benefit of using Flexible Datatables comes when one wishes to have DataTables tables displaying data from a Rails backend using ajax.
55
-
56
- #### Controller
57
- Flexible Datatables requires the `draw`, `start`, `length`, and `order` keys from the `params` hash. Initialize a new `FlexibleDatatables::Datatable` object and pass in those values.
58
- ```ruby
59
- datatable = FlexibleDatatables::Datatable.new(params.slice(:draw, :start, :length, :order))
60
- ```
61
- Pass in a collection of objects (which can come from anywhere; an array, an ActiveRecord query, etc)
62
- ```ruby
63
- datatable.collection = MyModel.all
64
- ```
65
- Tell your `Datatable` object what your columns are and how to arrange them into rows.
66
- ```ruby
67
- datatable.format_grid(%w(first_column, second_column, third_column) do |record|
68
- [record.first_column, record.second_column, record.third_column]
69
- end
70
- ```
71
- Instruct Rails to render your `Datatable` object as `JSON`. Your controller may look something like this:
72
- ```ruby
73
- respond_to do |format|
74
- format.html
75
- format.json do
76
- datatable = FlexibleDatatables::Datatable.new(params.slice(:draw, :start, :length, :order))
77
- datatable.collection = MyModel.all
78
- datatable.format_grid(%w(first_column, second_column, third_column) do |record|
79
- [record.first_column, record.second_column, record.third_column]
80
- end
81
- render json: datatable
82
- end
83
- end
84
- ```
85
-
86
- #### View
87
- Define a `table` with an `id` attribute.
88
- Give the `table` a `data-source` attribute that points to the route that DataTables will use to get the json data over ajax.
89
- Give this `table` a `thead` with some header columns, and an empty `tbody` declaration.
90
-
91
- #### JavaScript
92
- Finally, in a javascript file, call `.DataTable()` and pass in values for the `processing`, `serverSide`, `ajax`, and `pagingType` parameters.
93
- ```Coffeescript
94
- $ ->
95
- $('#my_table_id').DataTable
96
- processing: true
97
- serverSide: true
98
- ajax: $('#my_table_id').data('source')
99
- pagingType: "full_numbers"
100
- ```
101
-
102
- ## Contributing
103
-
104
- 1. Fork it
105
- 2. Create your feature branch (`git checkout -b my-new-feature`)
106
- 3. Commit your changes (`git commit -am 'Added some feature'`)
107
- 4. Push to the branch (`git push origin my-new-feature`)
108
- 5. Create new Pull Request
109
-
110
- ## License
111
-
112
- GPL-3.0+