JasonKing-good_sort 0.1.1 → 0.1.3

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.markdown CHANGED
@@ -27,7 +27,7 @@ Then add it to your `config/environment.rb`:
27
27
 
28
28
  ### git submodule
29
29
 
30
- $ git submodule add git://github.com/JasonKing/good_sort.git vendor/plugins/good_sort
30
+ git submodule add git://github.com/JasonKing/good_sort.git vendor/plugins/good_sort
31
31
 
32
32
  Usage
33
33
  -----
@@ -114,7 +114,7 @@ There's also no requirement to cram it all in on one line, you can have multiple
114
114
  This produces a `:order` hash suitable to be merged into your `Model.find` (or
115
115
  `Model.paginate`) parameters based on the `:field` and `:down` input parameters.
116
116
 
117
- ### ActionView::Base#sort\_headers\_for( model\_name, header\_array, options = {} )
117
+ ### ActionView::Base#sort\_headers\_for( model\_name, header\_array, options = {}, &block )
118
118
 
119
119
  With no options, this will create `<th>` elements for each element of the
120
120
  header_array, they will be given an id which, for the `name` field of our
@@ -142,3 +142,7 @@ follows:
142
142
  * **:html** - Options pass to the `link\_to\_remote` as the third argument, see the docs for `link\_to\_remote` for these, defaults below:
143
143
  * **:title** - Defaults to "Sort by #{sort\_field\_tag}". If you embed the sort\_field\_tag attribute in your string then that will be replaced with the field\_name.titlize for you, eg: :title => "Order by #{sort\_field\_tag}" If you want anything fancier then you can override `sort\_header\_title` and do whatever you want.
144
144
  * **:html** - No point in setting this, it is overridden with the link URL.
145
+
146
+ Finally, if you pass a block, then it will be yielded to for each field in your
147
+ header\_array, and you can provide different text to be displayed for as many of
148
+ the headings as you like.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: JasonKing-good_sort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason King
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-01 00:00:00 -07:00
12
+ date: 2009-04-02 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -31,6 +31,7 @@ files:
31
31
  - lib/good_sort/will_paginate.rb
32
32
  - lib/good_sort.rb
33
33
  - test/good_sort_test.rb
34
+ - test/good_sort_view.rb
34
35
  - test/test_helper.rb
35
36
  - LICENSE
36
37
  has_rdoc: true
data/VERSION.yml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- :patch: 1
3
- :major: 0
4
- :minor: 1
@@ -1,83 +0,0 @@
1
- require 'test_helper'
2
- require 'good_sort/sorter'
3
- require 'active_support'
4
-
5
- class GoodSortSorterTest < Test::Unit::TestCase
6
- include GoodSort::Sorter
7
- def columns_hash; { 'foo' => true, 'bar' => true }; end
8
- def class_name; "foobar"; end
9
-
10
- def reflect_on_association(a)
11
- ass = mock()
12
- ass.stubs(:belongs_to?).returns(a.to_sym == :ass_exist)
13
-
14
- ass.stubs(:class_name).returns('ass_exists')
15
-
16
- ass_klass = mock()
17
- ass_klass.stubs(:column_names).returns( %w{name last_name} )
18
-
19
- ass.stubs(:klass).returns(ass_klass)
20
-
21
- ass
22
- end
23
-
24
- def test_sort_on_our_attributes
25
- sort_on :foo, :bar
26
- assert_equal 2, sort_fields.length
27
- assert_equal( { :order => 'foo' }, sort_fields[:foo])
28
- assert_equal( { :order => 'bar' }, sort_fields[:bar])
29
- end
30
-
31
- def test_association_sort_fields
32
- sort_on :ass_exist => :last_name
33
- assert_equal 'ass_exists.last_name', sort_fields[:ass_exist][:order]
34
- end
35
-
36
- def test_default_association_sort_field
37
- sort_on :ass_exist
38
- assert_equal 'ass_exists.name', sort_fields[:ass_exist][:order]
39
- end
40
-
41
- def test_argument_errors
42
- assert_raise ArgumentError do
43
- sort_on :ass_imaginary
44
- end
45
-
46
- assert_raise ArgumentError do
47
- sort_on false
48
- end
49
-
50
- assert_raise ArgumentError do
51
- sort_on :ass_exist => :nonexistent
52
- end
53
- end
54
-
55
- def test_multiple_declarations
56
- sort_on :foo
57
- sort_on :bar
58
- assert_equal 2, sort_fields.length
59
- assert_equal( { :order => 'foo' }, sort_fields[:foo])
60
- assert_equal( { :order => 'bar' }, sort_fields[:bar])
61
- end
62
-
63
- def test_sort_by
64
- sort_on :foo
65
- assert_equal( { :order => 'foo' }, sort_by( :field => 'foo', :down => '' ))
66
- assert_equal( { :order => 'foo DESC'}, sort_by( :field => 'foo', :down => 'true' ))
67
- assert_raise ArgumentError do
68
- sort_by( :field => 'bar', :down => '' )
69
- end
70
- assert_nil sort_by nil
71
- assert_nil sort_by( :field => 'foo' )
72
- assert_nil sort_by( :down => '' )
73
- assert_nil sort_by( :down => 'true' )
74
-
75
- sort_on :ass_exist
76
- assert_equal( { :joins => :ass_exist, :order => 'ass_exists.name' }, sort_by( :field => 'ass_exist', :down => '' ))
77
- assert_equal( { :joins => :ass_exist, :order => 'ass_exists.name DESC' }, sort_by( :field => 'ass_exist', :down => 'true' ))
78
- end
79
-
80
- def teardown
81
- GoodSort::Sorter.send :class_variable_set, :@@sort_fields, {}
82
- end
83
- end