sortablecolumns 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/README.txt +8 -7
- data/Rakefile +17 -0
- data/lib/sortablecolumns.rb +1 -1
- data/test/sortablecolumns_test.rb +5 -4
- metadata +3 -3
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -47,7 +47,7 @@ Say we have a Person model (or a custom SQL query result) with the following col
|
|
47
47
|
|
48
48
|
We're going to call this sorter "mysorter". This will be the name of the YAML file and the name passed into the sortable_columns method in the model.
|
49
49
|
|
50
|
-
|
50
|
+
==== Model:
|
51
51
|
|
52
52
|
class Person < ActiveRecord::Base
|
53
53
|
sortable_columns :mysorter
|
@@ -63,10 +63,11 @@ In model:
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
YAML file:
|
66
|
+
==== YAML file:
|
67
67
|
|
68
|
-
The YAML file needs to be in an ordered format (i.e., it gets loaded into Ruby
|
69
|
-
of the columns in the YAML file determines their
|
68
|
+
The YAML file needs to be in an ordered format (i.e., it gets loaded into Ruby
|
69
|
+
as an Array). The order of the columns in the YAML file determines their
|
70
|
+
display order when rendered as HTML.
|
70
71
|
|
71
72
|
-
|
72
73
|
firstname:
|
@@ -150,7 +151,7 @@ You can also have extra parameters in the url that are attributes in the results
|
|
150
151
|
|
151
152
|
...where person_id is a field (method) in the result set that will be invoked.
|
152
153
|
|
153
|
-
|
154
|
+
==== Controller:
|
154
155
|
|
155
156
|
def index #plain HTML table
|
156
157
|
@people = Person.find_for_mysorter(options=params.dup)
|
@@ -176,7 +177,7 @@ In the controller:
|
|
176
177
|
end
|
177
178
|
end
|
178
179
|
|
179
|
-
|
180
|
+
==== View:
|
180
181
|
|
181
182
|
<%= print_table(@people, :mysorter %>
|
182
183
|
Or if you want alternating styles for table rows:
|
@@ -192,7 +193,7 @@ Also make sure the table is inside a div with the same id as specified in the co
|
|
192
193
|
|
193
194
|
* YUI4Rails gem if you want to use YUI datatables
|
194
195
|
|
195
|
-
==
|
196
|
+
== DISCLAIMER
|
196
197
|
|
197
198
|
This is beta-quality software. It works well according to my tests, but the API may change and other features may be added.
|
198
199
|
|
data/Rakefile
CHANGED
@@ -19,4 +19,21 @@ rule '' do |t|
|
|
19
19
|
system "cd test && ruby sortablecolumns_test.rb"
|
20
20
|
end
|
21
21
|
|
22
|
+
ALLISON = "/opt/local/lib/ruby/gems/1.8/gems/allison-2.0.3/lib/allison.rb"
|
23
|
+
|
24
|
+
Rake::RDocTask.new do |rd|
|
25
|
+
rd.main = "README.txt"
|
26
|
+
rd.rdoc_dir = "doc"
|
27
|
+
rd.rdoc_files.include(
|
28
|
+
"README.txt",
|
29
|
+
"History.txt",
|
30
|
+
"Manifest.txt",
|
31
|
+
"lib/**/*.rb")
|
32
|
+
rd.title = "SortableColumns RDoc"
|
33
|
+
|
34
|
+
rd.options << '-S' # inline source
|
35
|
+
|
36
|
+
rd.template = ALLISON if File.exist?(ALLISON)
|
37
|
+
end
|
38
|
+
|
22
39
|
# vim: syntax=Ruby
|
data/lib/sortablecolumns.rb
CHANGED
@@ -73,9 +73,6 @@ class Dude < Person
|
|
73
73
|
firstname
|
74
74
|
end
|
75
75
|
|
76
|
-
def person_id
|
77
|
-
id
|
78
|
-
end
|
79
76
|
end
|
80
77
|
|
81
78
|
class SubPerson < Person
|
@@ -352,6 +349,10 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
|
|
352
349
|
registered_at = DateTime.new(2008,5,1,7,30)
|
353
350
|
@dude = Dude.create(:firstname => "The Dude", :lastname => "Lebowski", :age => 45,
|
354
351
|
:description => "The Dude Speaks", :created_at => created_at, :registered_at => registered_at)
|
352
|
+
|
353
|
+
#make sure a find_by_sql query works with an arbitrary attribute (person_id in this case)
|
354
|
+
query = "select p.*, '23445' as person_id from people p where id = #{@dude.id}"
|
355
|
+
@dude = Dude.find_by_sql(query).first
|
355
356
|
|
356
357
|
@expected_person_row = "<tr><td class=\"left\"><a href=\"http://test.host/people/show/1\">Billy</a></td><td>Jones</td><td class=\"center\">24</td><td class=\"left\"><p>Billy is an awesome guy.\n<br />However, he is also a punk. <a href=\"http://www.google.com\">www.google.com</a></p></td><td class=\"right\">£1 234,57</td><td><a href=\"http://test.host/people/edit/1\">Edit</a></td><td><a href=\"http://test.host/people/destroy/1\" onclick=\"if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;\">Delete</a></td></tr>"
|
357
358
|
@expected_person_row_alternate = @expected_person_row.gsub(/<tr>/, "<tr class=\"even\">")
|
@@ -423,7 +424,7 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
|
|
423
424
|
#
|
424
425
|
# Where person_id is a field in the result set (in this test, there's a mock method instead)
|
425
426
|
|
426
|
-
expected = "<td><a href=\"http://test.host/dudes/print_view?person_id
|
427
|
+
expected = "<td><a href=\"http://test.host/dudes/print_view?person_id=23445\">Print</a></td>"
|
427
428
|
assert_equal expected, @view.print_col(@dude, :dude_report, :print_view)
|
428
429
|
end
|
429
430
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sortablecolumns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Donovan - http://www.bryandonovan.com
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-05-
|
12
|
+
date: 2008-05-05 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
requirements: []
|
67
67
|
|
68
68
|
rubyforge_project: sortablecolumns
|
69
|
-
rubygems_version: 1.1.
|
69
|
+
rubygems_version: 1.1.1
|
70
70
|
signing_key:
|
71
71
|
specification_version: 2
|
72
72
|
summary: Sortable HTML tables for Rails
|