rails-tables 0.4.1 → 0.4.2
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.
- data/README.md +32 -0
- data/app/tables/column.rb +8 -3
- data/app/tables/datatable.rb +8 -2
- data/lib/rails-tables/version.rb +1 -1
- metadata +2 -2
- data/README.rdoc +0 -3
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
RailsTables
|
2
|
+
===========
|
3
|
+
|
4
|
+
A clean jQuery datatables DSL
|
5
|
+
-----------------------------
|
6
|
+
|
7
|
+
[RailsTables][rails-tables] is a simple DSL built on top of [jquery-datatables-rails][jqd-rails] to quickly compose performant [jQuery datatables][jqd] for your Rails app. It is inspired by, and was born as an abstraction of, the pattern used in Ryan Bates's [datatables Railscast][jqd-railscast]. It's powered by the indomitable ActiveRecord extension [Squeel][squeel].
|
8
|
+
|
9
|
+
[rails-tables]: https://github.com/christhekeele/rails-tables (RailsTables)
|
10
|
+
[jqd]: http://datatables.net/ (jQuery Datatables)
|
11
|
+
[jqd-rails]: https://github.com/rweng/jquery-datatables-rails (jQuery Datatables for Rails)
|
12
|
+
[jqd-railscast]: http://railscasts.com/episodes/340-datatables (Episode #340: Datatables)
|
13
|
+
[squeel]: https://github.com/ernie/squeel (Squeel: ActiveRecord 3, improved)
|
14
|
+
|
15
|
+
Version: 0.4.2
|
16
|
+
|
17
|
+
Please refer to the [RailsTables Wiki][wiki] for:
|
18
|
+
|
19
|
+
- [Installation][wiki-installation]
|
20
|
+
- [Quick Start][wiki-quick-start]
|
21
|
+
- [Customization][wiki-customization]
|
22
|
+
- [Contributions][wiki-contributions]
|
23
|
+
- [Feedback][wiki-feedback]
|
24
|
+
- [Change Log][wiki-change-log]
|
25
|
+
|
26
|
+
[wiki]: https://github.com/christhekeele/rails-tables/wiki (RailsTables Wiki)
|
27
|
+
[wiki-installation]: https://github.com/christhekeele/rails-tables/wiki/Installation (RailsTables Installation)
|
28
|
+
[wiki-quick-start]: https://github.com/christhekeele/rails-tables/wiki/Quick_Start (RailsTables Quick Start)
|
29
|
+
[wiki-customization]: https://github.com/christhekeele/rails-tables/wiki/Customization (RailsTables Customization)
|
30
|
+
[wiki-contributions]: https://github.com/christhekeele/rails-tables/wiki/Contributions (RailsTables Contributions)
|
31
|
+
[wiki-feedback]: https://github.com/christhekeele/rails-tables/wiki/Feedback (RailsTables Feedback)
|
32
|
+
[wiki-change-log]: https://github.com/christhekeele/rails-tables/wiki/Change_Log (RailsTables Change Log)
|
data/app/tables/column.rb
CHANGED
@@ -14,11 +14,12 @@ class Column
|
|
14
14
|
self.blank_value = attributes.fetch(:blank_value, '–')
|
15
15
|
|
16
16
|
define_singleton_method :render do |view, object|
|
17
|
+
related = object
|
17
18
|
self.column_source.split('.').each do |relation|
|
18
|
-
|
19
|
+
related = related.try(:send, relation)
|
19
20
|
end
|
20
21
|
if self.render_with.kind_of? Symbol
|
21
|
-
content = self.send(self.render_with, view,
|
22
|
+
content = self.send(self.render_with, view, related)
|
22
23
|
else
|
23
24
|
content = self.render_with.call(view, object)
|
24
25
|
end
|
@@ -39,8 +40,12 @@ class Column
|
|
39
40
|
view.link_to property, property if not property.nil?
|
40
41
|
end
|
41
42
|
def related_link_list(view, objects)
|
42
|
-
objects.map{ |object| related_link(view, object).strip }.
|
43
|
+
objects.reject(&:blank?).map{ |object| related_link(view, object).strip }.join(', ') if not objects.nil?
|
43
44
|
end
|
45
|
+
# def unique_related_link_list(view, objects, field)
|
46
|
+
# binding.pry if objects.length > 1
|
47
|
+
# related_link_list(view, objects.uniq{|o| o.send(field)} )
|
48
|
+
# end
|
44
49
|
def time(view, object)
|
45
50
|
property = object.try(:send, self.method)
|
46
51
|
property.strftime("%I:%M%p") if not property.nil?
|
data/app/tables/datatable.rb
CHANGED
@@ -62,9 +62,14 @@ class_attribute :columns, :column_factory
|
|
62
62
|
@columns ||= self.column_factory.map{ |new_column| Column.new(self.model, new_column[:name], new_column[:args]) }
|
63
63
|
end
|
64
64
|
|
65
|
+
class_attribute :joins
|
66
|
+
self.joins = []
|
67
|
+
def self.join(join)
|
68
|
+
self.joins += [join.to_s]
|
69
|
+
end
|
65
70
|
attr_accessor :joins
|
66
71
|
def joins
|
67
|
-
@joins ||= self.columns.map(&:column_source).reject(&:blank?).uniq
|
72
|
+
@joins ||= (self.columns.map(&:column_source).reject(&:blank?) + self.class.joins).uniq
|
68
73
|
end
|
69
74
|
attr_accessor :searches
|
70
75
|
def searches
|
@@ -76,7 +81,8 @@ private
|
|
76
81
|
def objects
|
77
82
|
query = self.model.uniq
|
78
83
|
self.joins.each do |join|
|
79
|
-
query = query.joins{ join.split('.').inject(self, :__send__).outer }
|
84
|
+
query = query.joins{ join.split('.').inject(self, :__send__).outer }
|
85
|
+
query = query.includes{ join.split('.').inject(self, :__send__).outer }
|
80
86
|
end
|
81
87
|
if sortable
|
82
88
|
sort_expression = sort
|
data/lib/rails-tables/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -126,7 +126,7 @@ files:
|
|
126
126
|
- lib/tasks/rails-tables_tasks.rake
|
127
127
|
- MIT-LICENSE
|
128
128
|
- Rakefile
|
129
|
-
- README.
|
129
|
+
- README.md
|
130
130
|
homepage: https://github.com/christhekeele/rails-tables
|
131
131
|
licenses: []
|
132
132
|
post_install_message:
|
data/README.rdoc
DELETED