presenting 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/LICENSE +20 -20
  2. data/README +10 -10
  3. data/Rakefile +22 -22
  4. data/app/assets/javascripts/search.js +13 -13
  5. data/app/assets/stylesheets/details-color.css +7 -7
  6. data/app/assets/stylesheets/details.css +10 -10
  7. data/app/assets/stylesheets/form.css +1 -1
  8. data/app/assets/stylesheets/grid-color.css +71 -71
  9. data/app/assets/stylesheets/grid.css +64 -64
  10. data/app/assets/stylesheets/search-color.css +16 -16
  11. data/app/assets/stylesheets/search.css +45 -45
  12. data/app/controllers/presentation/assets_controller.rb +42 -42
  13. data/app/views/presentations/_details.erb +11 -11
  14. data/app/views/presentations/_field_search.erb +14 -14
  15. data/app/views/presentations/_form.erb +20 -20
  16. data/app/views/presentations/_grid.erb +70 -70
  17. data/app/views/presentations/_search.erb +7 -7
  18. data/lib/presentation/base.rb +31 -31
  19. data/lib/presentation/details.rb +21 -21
  20. data/lib/presentation/field_search.rb +67 -67
  21. data/lib/presentation/form.rb +149 -149
  22. data/lib/presentation/grid.rb +162 -160
  23. data/lib/presentation/search.rb +9 -9
  24. data/lib/presenting/attribute.rb +51 -51
  25. data/lib/presenting/configurable.rb +10 -10
  26. data/lib/presenting/defaults.rb +10 -10
  27. data/lib/presenting/field_set.rb +26 -26
  28. data/lib/presenting/form_helpers.rb +51 -51
  29. data/lib/presenting/helpers.rb +114 -114
  30. data/lib/presenting/sanitize.rb +19 -19
  31. data/lib/presenting/search.rb +185 -185
  32. data/lib/presenting/sorting.rb +87 -87
  33. data/test/attribute_test.rb +61 -61
  34. data/test/configurable_test.rb +20 -20
  35. data/test/details_test.rb +68 -68
  36. data/test/field_search_test.rb +102 -102
  37. data/test/field_set_test.rb +46 -46
  38. data/test/grid_test.rb +246 -239
  39. data/test/helpers_test.rb +72 -72
  40. data/test/presenting_test.rb +15 -15
  41. data/test/r3/Gemfile +7 -7
  42. data/test/r3/Gemfile.lock +86 -82
  43. data/test/r3/config/application.rb +12 -12
  44. data/test/r3/config/boot.rb +6 -6
  45. data/test/r3/config/database.yml +22 -22
  46. data/test/r3/config/environment.rb +5 -5
  47. data/test/r3/config/environments/test.rb +35 -35
  48. data/test/r3/db/test.sqlite3 +0 -0
  49. data/test/r3/log/test.log +336 -0
  50. data/test/r3/public/javascripts/presenting/grid.js +0 -0
  51. data/test/r3/public/javascripts/presenting/search.js +13 -13
  52. data/test/r3/public/stylesheets/presenting/details-color.css +7 -7
  53. data/test/r3/public/stylesheets/presenting/details.css +10 -10
  54. data/test/r3/public/stylesheets/presenting/form.css +1 -1
  55. data/test/r3/public/stylesheets/presenting/grid-color.css +71 -71
  56. data/test/r3/public/stylesheets/presenting/grid.css +64 -64
  57. data/test/r3/public/stylesheets/presenting/search-color.css +16 -16
  58. data/test/r3/public/stylesheets/presenting/search.css +45 -45
  59. data/test/sanitize_test.rb +15 -15
  60. data/test/search_conditions_test.rb +137 -137
  61. data/test/search_test.rb +30 -30
  62. data/test/sorting_test.rb +63 -63
  63. metadata +74 -74
@@ -1,64 +1,64 @@
1
- /** cellspacing **/
2
- .presentation-grid table,
3
- .presentation-grid td,
4
- .presentation-grid th {
5
- border: 0;
6
- border-collapse: collapse;
7
- }
8
-
9
- .presentation-grid table {
10
- width: 100%;
11
- }
12
-
13
- .presentation-grid caption {
14
- text-align: left;
15
- font-weight: bold;
16
- padding-left: 0.2em;
17
- }
18
-
19
- .presentation-grid th {
20
- padding: 0.2em 0.5em 0em 0.2em;
21
- text-align: left;
22
- vertical-align: bottom;
23
- }
24
-
25
- .presentation-grid th a {
26
- text-decoration: none;
27
- }
28
-
29
- .presentation-grid td {
30
- padding: 0.4em 0.5em 0.4em 0.2em;
31
- vertical-align: top;
32
- }
33
-
34
- .presentation-grid ul.actions {
35
- overflow: auto;
36
- zoom: 1;
37
- float: right;
38
- list-style: none;
39
- margin: 0;
40
- padding: 0;
41
- }
42
-
43
- .presentation-grid ul.actions li {
44
- float: left;
45
- }
46
-
47
- .presentation-grid ul.actions li a {
48
- font-weight: normal;
49
- display: block;
50
- padding: 0em 0.3em;
51
- text-decoration: none;
52
- }
53
-
54
- .presentation-grid ul.actions li a:hover {
55
- text-decoration: underline;
56
- }
57
-
58
- .presentation-grid ul.actions li a {
59
- outline: none;
60
- }
61
-
62
- .presentation-grid caption ul.actions {
63
- margin-right: 0.5em;
64
- }
1
+ /** cellspacing **/
2
+ .presentation-grid table,
3
+ .presentation-grid td,
4
+ .presentation-grid th {
5
+ border: 0;
6
+ border-collapse: collapse;
7
+ }
8
+
9
+ .presentation-grid table {
10
+ width: 100%;
11
+ }
12
+
13
+ .presentation-grid caption {
14
+ text-align: left;
15
+ font-weight: bold;
16
+ padding-left: 0.2em;
17
+ }
18
+
19
+ .presentation-grid th {
20
+ padding: 0.2em 0.5em 0em 0.2em;
21
+ text-align: left;
22
+ vertical-align: bottom;
23
+ }
24
+
25
+ .presentation-grid th a {
26
+ text-decoration: none;
27
+ }
28
+
29
+ .presentation-grid td {
30
+ padding: 0.4em 0.5em 0.4em 0.2em;
31
+ vertical-align: top;
32
+ }
33
+
34
+ .presentation-grid ul.actions {
35
+ overflow: auto;
36
+ zoom: 1;
37
+ float: right;
38
+ list-style: none;
39
+ margin: 0;
40
+ padding: 0;
41
+ }
42
+
43
+ .presentation-grid ul.actions li {
44
+ float: left;
45
+ }
46
+
47
+ .presentation-grid ul.actions li a {
48
+ font-weight: normal;
49
+ display: block;
50
+ padding: 0em 0.3em;
51
+ text-decoration: none;
52
+ }
53
+
54
+ .presentation-grid ul.actions li a:hover {
55
+ text-decoration: underline;
56
+ }
57
+
58
+ .presentation-grid ul.actions li a {
59
+ outline: none;
60
+ }
61
+
62
+ .presentation-grid caption ul.actions {
63
+ margin-right: 0.5em;
64
+ }
@@ -1,16 +1,16 @@
1
- .presentation-search label {
2
- color: #666;
3
- }
4
-
5
- .presentation-search fieldset {
6
- border: 1px solid #c5dbf7;
7
- background-color: #e6f2ff;
8
- padding: 2px;
9
- }
10
-
11
- .presentation-search fieldset.submit {
12
- border: 0px;
13
- padding: 0px;
14
- background-color: transparent;
15
- }
16
-
1
+ .presentation-search label {
2
+ color: #666;
3
+ }
4
+
5
+ .presentation-search fieldset {
6
+ border: 1px solid #c5dbf7;
7
+ background-color: #e6f2ff;
8
+ padding: 2px;
9
+ }
10
+
11
+ .presentation-search fieldset.submit {
12
+ border: 0px;
13
+ padding: 0px;
14
+ background-color: transparent;
15
+ }
16
+
@@ -1,45 +1,45 @@
1
- .presentation-search {
2
- overflow: hidden;
3
- zoom: 1;
4
- }
5
-
6
- .presentation-search fieldset {
7
- border: 0;
8
- margin: 0 0.5em 1em 0;
9
- padding: 0;
10
- float: left;
11
- width: 145px;
12
- }
13
-
14
- .presentation-search fieldset label {
15
- font-weight: normal;
16
- margin: 0;
17
- padding: 0;
18
- text-transform: none;
19
- }
20
-
21
- .presentation-search fieldset input,
22
- .presentation-search fieldset select {
23
- padding: 0px;
24
- margin: 0px;
25
- }
26
-
27
- /* for overlabels (requires javascript) */
28
-
29
- .presentation-search .compact label {
30
- display: inline;
31
- }
32
-
33
- .presentation-search .compact fieldset {
34
- position: relative;
35
- width: auto;
36
- }
37
-
38
- .presentation-search .compact fieldset label.overlabel {
39
- display: block;
40
- position: absolute;
41
- top: 0.2em;
42
- left: 0.5em;
43
- z-index: 1;
44
- cursor: text;
45
- }
1
+ .presentation-search {
2
+ overflow: hidden;
3
+ zoom: 1;
4
+ }
5
+
6
+ .presentation-search fieldset {
7
+ border: 0;
8
+ margin: 0 0.5em 1em 0;
9
+ padding: 0;
10
+ float: left;
11
+ width: 145px;
12
+ }
13
+
14
+ .presentation-search fieldset label {
15
+ font-weight: normal;
16
+ margin: 0;
17
+ padding: 0;
18
+ text-transform: none;
19
+ }
20
+
21
+ .presentation-search fieldset input,
22
+ .presentation-search fieldset select {
23
+ padding: 0px;
24
+ margin: 0px;
25
+ }
26
+
27
+ /* for overlabels (requires javascript) */
28
+
29
+ .presentation-search .compact label {
30
+ display: inline;
31
+ }
32
+
33
+ .presentation-search .compact fieldset {
34
+ position: relative;
35
+ width: auto;
36
+ }
37
+
38
+ .presentation-search .compact fieldset label.overlabel {
39
+ display: block;
40
+ position: absolute;
41
+ top: 0.2em;
42
+ left: 0.5em;
43
+ z-index: 1;
44
+ cursor: text;
45
+ }
@@ -1,15 +1,15 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class Presenting::SanitizeTest < Presenting::Test
4
- def test_sanitizing_an_array
5
- assert_equal ['&amp;'], Presenting::Sanitize.h(['&'])
6
- end
7
-
8
- def test_sanitizing_a_hash
9
- assert_equal({'<' => '>'}, Presenting::Sanitize.h({'<' => '>'}))
10
- end
11
-
12
- def test_sanitizing_a_string
13
- assert_equal '&amp;', Presenting::Sanitize.h('&')
14
- end
15
- end
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class Presenting::SanitizeTest < Presenting::Test
4
+ def test_sanitizing_an_array
5
+ assert_equal ['&amp;'], Presenting::Sanitize.h(['&'])
6
+ end
7
+
8
+ def test_sanitizing_a_hash
9
+ assert_equal({'<' => '>'}, Presenting::Sanitize.h({'<' => '>'}))
10
+ end
11
+
12
+ def test_sanitizing_a_string
13
+ assert_equal '&amp;', Presenting::Sanitize.h('&')
14
+ end
15
+ end
@@ -1,137 +1,137 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class SearchConditionsTest < Presenting::Test
4
- def setup
5
- @c = Presenting::Search.new
6
- end
7
-
8
- def test_assigning_a_simple_set_of_fields
9
- @c.fields = [:a]
10
- assert_equal 1, @c.fields.size
11
-
12
- assert_equal 'a', @c.fields[0].name
13
- assert_equal 'a', @c.fields[0].sql
14
- assert_equal '= ?', @c.fields[0].operator
15
- assert_equal '?', @c.fields[0].bind_pattern
16
- end
17
-
18
- def test_assigning_fields_with_custom_patterns
19
- @c.fields = {:a => :begins_with}
20
- assert_equal 1, @c.fields.size
21
-
22
- assert_equal 'a', @c.fields[0].name
23
- assert_equal 'a', @c.fields[0].sql
24
- assert_equal 'LIKE ?', @c.fields[0].operator
25
- assert_equal '?%', @c.fields[0].bind_pattern
26
- end
27
-
28
- def test_assigning_fields_with_full_options
29
- @c.fields = {:a => {:sql => 'foo', :pattern => :begins_with}}
30
- assert_equal 1, @c.fields.size
31
-
32
- assert_equal 'a', @c.fields[0].name
33
- assert_equal 'foo', @c.fields[0].sql
34
- assert_equal 'LIKE ?', @c.fields[0].operator
35
- assert_equal '?%', @c.fields[0].bind_pattern
36
- end
37
-
38
- def test_conditions_with_no_term
39
- @c.fields = [:a, :b]
40
- assert_nil @c.to_sql(nil)
41
- assert_nil @c.to_sql('')
42
- end
43
-
44
- def test_simple_conditions
45
- @c.fields << :a
46
- @c.fields << {:b => :begins_with}
47
- assert_equal ["a = ? OR b LIKE ?", 'foo', 'foo%'], @c.to_sql('foo', :simple)
48
- end
49
-
50
- def test_field_conditions
51
- @c.fields << :a
52
- @c.fields << {:b => :begins_with}
53
- assert_equal ["a = ? AND b LIKE ?", 'foo', 'bar%'], @c.to_sql({'a' => {:value => 'foo'}, 'b' => {:value => 'bar'}}, :field)
54
- end
55
-
56
- def test_field_conditions_with_a_blank_term
57
- @c.fields = [:a, :b]
58
- assert_equal ["a = ?", 'foo'], @c.to_sql({'a' => {:value => 'foo'}, 'b' => {:value => ''}}, :field)
59
- end
60
-
61
- def test_field_conditions_with_space_padded_term
62
- @c.fields = [:a]
63
- assert_equal ["a = ?", 'foo'], @c.to_sql({'a' => {:value => ' foo '}}, :field)
64
- end
65
-
66
- def test_field_conditions_with_only_blank_terms
67
- @c.fields = [:a]
68
- assert_nil @c.to_sql({'a' => {:value => ''}}, :field)
69
- end
70
-
71
- def test_field_conditions_with_null_field
72
- @c.fields << :a
73
- @c.fields << {:b => :null}
74
- assert_equal ["a = ? AND b IS NULL", 'foo'], @c.to_sql({'a' => {:value => 'foo'}, 'b' => {:value => '1'}}, :field)
75
- end
76
-
77
- def test_field_conditions_without_null_field
78
- @c.fields << :a
79
- @c.fields << {:b => :null}
80
- assert_equal ["a = ?", 'foo'], @c.to_sql({'a' => {:value => 'foo'}}, :field)
81
- end
82
-
83
- def test_field_conditions_with_true_field
84
- @c.fields << {:a => :true}
85
- assert_equal ["a = ?", true], @c.to_sql({'a' => {:value => '1'}}, :field)
86
- end
87
- end
88
-
89
- class SearchConditionsFieldTest < Presenting::Test
90
- def setup
91
- @f = Presenting::Search::Field.new
92
- end
93
-
94
- def test_assigning_a_symbol_name
95
- @f.name = :foo
96
- assert_equal 'foo', @f.name
97
- end
98
-
99
- def test_sql_defaults_to_name
100
- @f.name = :foo
101
- assert_equal 'foo', @f.sql
102
- end
103
-
104
- def test_default_operator
105
- assert_equal '= ?', @f.operator
106
- end
107
-
108
- def test_default_bind_pattern
109
- assert_equal '?', @f.bind_pattern
110
- end
111
-
112
- def test_fragment_joins_sql_and_operator
113
- @f.sql = 'foo'
114
- @f.operator = 'bar'
115
- assert_equal "foo bar", @f.fragment
116
- end
117
-
118
- def test_bind_returns_nil_if_operator_has_no_place
119
- @f.operator = 'is null'
120
- assert_equal nil, @f.bind('foo')
121
- end
122
-
123
- def test_bind_returns_term_applied_to_bind_pattern
124
- @f.bind_pattern = '%?%'
125
- assert_equal '%foo%', @f.bind('foo')
126
- end
127
-
128
- def test_bind_with_typecast_to_date
129
- @f.type = :date
130
- assert_equal Time.zone.parse('Apr 20, 2009').to_date, @f.bind('Apr 20, 2009')
131
- end
132
-
133
- def test_bind_with_typecast_to_time
134
- @f.type = :time
135
- assert_equal Time.zone.parse('Apr 20, 2009 11:00am'), @f.bind('Apr 20, 2009 11:00am')
136
- end
137
- end
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SearchConditionsTest < Presenting::Test
4
+ def setup
5
+ @c = Presenting::Search.new
6
+ end
7
+
8
+ def test_assigning_a_simple_set_of_fields
9
+ @c.fields = [:a]
10
+ assert_equal 1, @c.fields.size
11
+
12
+ assert_equal 'a', @c.fields[0].name
13
+ assert_equal 'a', @c.fields[0].sql
14
+ assert_equal '= ?', @c.fields[0].operator
15
+ assert_equal '?', @c.fields[0].bind_pattern
16
+ end
17
+
18
+ def test_assigning_fields_with_custom_patterns
19
+ @c.fields = {:a => :begins_with}
20
+ assert_equal 1, @c.fields.size
21
+
22
+ assert_equal 'a', @c.fields[0].name
23
+ assert_equal 'a', @c.fields[0].sql
24
+ assert_equal 'LIKE ?', @c.fields[0].operator
25
+ assert_equal '?%', @c.fields[0].bind_pattern
26
+ end
27
+
28
+ def test_assigning_fields_with_full_options
29
+ @c.fields = {:a => {:sql => 'foo', :pattern => :begins_with}}
30
+ assert_equal 1, @c.fields.size
31
+
32
+ assert_equal 'a', @c.fields[0].name
33
+ assert_equal 'foo', @c.fields[0].sql
34
+ assert_equal 'LIKE ?', @c.fields[0].operator
35
+ assert_equal '?%', @c.fields[0].bind_pattern
36
+ end
37
+
38
+ def test_conditions_with_no_term
39
+ @c.fields = [:a, :b]
40
+ assert_nil @c.to_sql(nil)
41
+ assert_nil @c.to_sql('')
42
+ end
43
+
44
+ def test_simple_conditions
45
+ @c.fields << :a
46
+ @c.fields << {:b => :begins_with}
47
+ assert_equal ["a = ? OR b LIKE ?", 'foo', 'foo%'], @c.to_sql('foo', :simple)
48
+ end
49
+
50
+ def test_field_conditions
51
+ @c.fields << :a
52
+ @c.fields << {:b => :begins_with}
53
+ assert_equal ["a = ? AND b LIKE ?", 'foo', 'bar%'], @c.to_sql({'a' => {:value => 'foo'}, 'b' => {:value => 'bar'}}, :field)
54
+ end
55
+
56
+ def test_field_conditions_with_a_blank_term
57
+ @c.fields = [:a, :b]
58
+ assert_equal ["a = ?", 'foo'], @c.to_sql({'a' => {:value => 'foo'}, 'b' => {:value => ''}}, :field)
59
+ end
60
+
61
+ def test_field_conditions_with_space_padded_term
62
+ @c.fields = [:a]
63
+ assert_equal ["a = ?", 'foo'], @c.to_sql({'a' => {:value => ' foo '}}, :field)
64
+ end
65
+
66
+ def test_field_conditions_with_only_blank_terms
67
+ @c.fields = [:a]
68
+ assert_nil @c.to_sql({'a' => {:value => ''}}, :field)
69
+ end
70
+
71
+ def test_field_conditions_with_null_field
72
+ @c.fields << :a
73
+ @c.fields << {:b => :null}
74
+ assert_equal ["a = ? AND b IS NULL", 'foo'], @c.to_sql({'a' => {:value => 'foo'}, 'b' => {:value => '1'}}, :field)
75
+ end
76
+
77
+ def test_field_conditions_without_null_field
78
+ @c.fields << :a
79
+ @c.fields << {:b => :null}
80
+ assert_equal ["a = ?", 'foo'], @c.to_sql({'a' => {:value => 'foo'}}, :field)
81
+ end
82
+
83
+ def test_field_conditions_with_true_field
84
+ @c.fields << {:a => :true}
85
+ assert_equal ["a = ?", true], @c.to_sql({'a' => {:value => '1'}}, :field)
86
+ end
87
+ end
88
+
89
+ class SearchConditionsFieldTest < Presenting::Test
90
+ def setup
91
+ @f = Presenting::Search::Field.new
92
+ end
93
+
94
+ def test_assigning_a_symbol_name
95
+ @f.name = :foo
96
+ assert_equal 'foo', @f.name
97
+ end
98
+
99
+ def test_sql_defaults_to_name
100
+ @f.name = :foo
101
+ assert_equal 'foo', @f.sql
102
+ end
103
+
104
+ def test_default_operator
105
+ assert_equal '= ?', @f.operator
106
+ end
107
+
108
+ def test_default_bind_pattern
109
+ assert_equal '?', @f.bind_pattern
110
+ end
111
+
112
+ def test_fragment_joins_sql_and_operator
113
+ @f.sql = 'foo'
114
+ @f.operator = 'bar'
115
+ assert_equal "foo bar", @f.fragment
116
+ end
117
+
118
+ def test_bind_returns_nil_if_operator_has_no_place
119
+ @f.operator = 'is null'
120
+ assert_equal nil, @f.bind('foo')
121
+ end
122
+
123
+ def test_bind_returns_term_applied_to_bind_pattern
124
+ @f.bind_pattern = '%?%'
125
+ assert_equal '%foo%', @f.bind('foo')
126
+ end
127
+
128
+ def test_bind_with_typecast_to_date
129
+ @f.type = :date
130
+ assert_equal Time.zone.parse('Apr 20, 2009').to_date, @f.bind('Apr 20, 2009')
131
+ end
132
+
133
+ def test_bind_with_typecast_to_time
134
+ @f.type = :time
135
+ assert_equal Time.zone.parse('Apr 20, 2009 11:00am'), @f.bind('Apr 20, 2009 11:00am')
136
+ end
137
+ end
data/test/search_test.rb CHANGED
@@ -1,30 +1,30 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class SearchTest < Presenting::Test
4
- def setup
5
- @s = Presentation::Search.new
6
- end
7
-
8
- # there's no configuration yet
9
- end
10
-
11
- class SearchRenderTest < Presentation::RenderTest
12
- def setup
13
- @presentation = Presentation::Search.new
14
- @presentation.controller = ActionView::TestCase::TestController.new
15
- @presentation.controller.request.path = '/users'
16
- end
17
-
18
- def test_rendering_a_form_reuses_current_path
19
- assert_select 'form[action=/users?][method=get]'
20
- end
21
-
22
- def test_rendering_a_search_box
23
- assert_select 'form input[type=text][name=search]'
24
- end
25
-
26
- def test_rendering_a_search_box_with_a_existing_search
27
- @presentation.controller.params[:search] = 'foo'
28
- assert_select 'form input[type=text][name=search][value=foo]'
29
- end
30
- end
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SearchTest < Presenting::Test
4
+ def setup
5
+ @s = Presentation::Search.new
6
+ end
7
+
8
+ # there's no configuration yet
9
+ end
10
+
11
+ class SearchRenderTest < Presentation::RenderTest
12
+ def setup
13
+ @presentation = Presentation::Search.new
14
+ @presentation.controller = ActionView::TestCase::TestController.new
15
+ @presentation.controller.request.path = '/users'
16
+ end
17
+
18
+ def test_rendering_a_form_reuses_current_path
19
+ assert_select 'form[action=/users?][method=get]'
20
+ end
21
+
22
+ def test_rendering_a_search_box
23
+ assert_select 'form input[type=text][name=search]'
24
+ end
25
+
26
+ def test_rendering_a_search_box_with_a_existing_search
27
+ @presentation.controller.params[:search] = 'foo'
28
+ assert_select 'form input[type=text][name=search][value=foo]'
29
+ end
30
+ end