sorting_table_for 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.mdown CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### Version 0.2.0 _(November 14, 2010)_
4
+
5
+ * Add footers and footer
6
+ * Add caption
7
+ * Add option colspan
8
+ * Add option i18n
9
+ * Change name on licence
10
+
3
11
  ### Version 0.1.2 _(November 02, 2010)_
4
12
 
5
13
  * Problem with date
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 arkownz (tom)
1
+ Copyright (c) 2010 arkownz (Thomas Floch)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.mdown CHANGED
@@ -6,9 +6,8 @@ SortingTableFor is a Rails TableBuilder made to easily create table or sort a ta
6
6
 
7
7
  ## Infos
8
8
 
9
- - It's Rails 2.3 and 3 compatible
9
+ - It's Rails 2 and 3 compatible
10
10
  - I18n compatible
11
- - Almost fully configurable
12
11
 
13
12
  ## Installation
14
13
 
@@ -24,154 +23,183 @@ Alternatively, you can install it as a plugin.
24
23
 
25
24
  rails plugin install git://github.com/arkownz/sorting_table_for.git
26
25
 
27
-
28
26
  ## Usage
29
27
 
30
- To create a simple table
28
+ To create a quick table
31
29
 
32
- <%- sorting_table_for @users do |table| %>
30
+ <% sorting_table_for @users do |table| %>
33
31
  <%= table.headers %>
34
32
  <%= table.columns %>
35
- <%- end %>
33
+ <% end %>
36
34
 
37
35
  will render
38
36
 
39
37
  <table>
40
38
  <thead>
41
39
  <tr>
42
- <th><a href='/to_sort'>Username</a></th>
43
- <th><a href='/to_sort'>Firstname</a></th>
40
+ <th class='cur-sort-not'><a href='/my_link?table_sort[username]=asc'>...</a></th>
41
+ <th class='cur-sort-not'><a href='/my_link?table_sort[firstname]=asc'>...</a></th>
44
42
  <th>Edit</th>
45
43
  <th>Delete</th>
46
44
  </tr>
47
45
  </thead>
48
46
  <tbody>
49
47
  <tr>
50
- <td colspan='4'>Total rows : 1</td>
48
+ <td colspan='4' class='total-entries'>Total Entries: 2</td>
51
49
  </tr>
52
50
  <tr>
53
51
  <td>Test</td>
54
52
  <td>Myname</td>
55
- <td><a href='/to_edit'>Edit</a></td>
56
- <td><a href='/to_delete'>Delete</a></td>
53
+ <td><a href='/users/1/edit'>Edit</a></td>
54
+ <td><a href='/users/1'>Delete</a></td>
57
55
  <tr>
58
56
  </tbody>
59
57
  </table>
60
58
 
61
- You can specify columns and headers
59
+ column and header can be called with a list
62
60
 
63
- <%- sorting_table_for @users do |table| %>
61
+ <% sorting_table_for @users do |table| %>
64
62
  <%= table.headers :username, :firstname, :lastname %>
65
63
  <%= table.columns :username, :firstname, :lastname %>
66
- <%- end %>
64
+ <% end %>
67
65
 
68
- On columns you can get the object of your collection.
69
- Your can pass to column or header what ever your want: symbol, string, image, ...
66
+ On columns you can get the current object of your collection.
67
+ You can give to column or header whatever you want: symbol, string, image, ...
70
68
 
71
- <%- sorting_table_for @users do |table| %>
69
+ <% sorting_table_for @users do |table| %>
72
70
  <%= table.headers do %>
73
71
  <%= table.header :username %>
74
72
  <%= table.header :firstname %>
75
73
  <%= table.header image_tag('rails.png') %>
76
- <%- end %>
74
+ <% end %>
77
75
  <%= table.columns do |user| %>
78
76
  <%= table.column :username %>
79
77
  <%= table.column user.firstname %>
80
78
  <%= table.column 'exemple' %>
81
- <%- end %>
82
- <%- end %>
79
+ <% end %>
80
+ <% end %>
83
81
 
84
- For more control on headers or columns
82
+ column and header can be called with a block
85
83
 
86
- <%- sorting_table_for @users do |table| %>
84
+ <% sorting_table_for @users do |table| %>
87
85
  <%= table.headers do %>
88
86
  <%= table.header do %>
89
87
  <%= image_tag('rails.png') %>
90
- <%- end %>
91
- <%- end %>
92
- <%= table.columns do |val| %>
88
+ <% end %>
89
+ <% end %>
90
+ <%= table.columns do |user| %>
93
91
  <%= table.column do %>
94
- <%= val.username.downcase %>
95
- <%- end %>
96
- <%- end %>
97
- <%- end %>
92
+ <%= user.username.downcase %>
93
+ <% end %>
94
+ <% end %>
95
+ <% end %>
96
+
97
+ ### Footer
98
+
99
+ You can set a footer to the table, it can be called with a list or a block
100
+
101
+ <% sorting_table_for @users do |table| %>
102
+ <%= table.footers :footer %>
103
+ <% end %>
98
104
 
99
- By default SortingTableFor will customize your table
105
+ -- equivalent --
100
106
 
101
- Header:
107
+ <% sorting_table_for @users do |table| %>
108
+ <%= table.footers do %>
109
+ <%= table.footer :footer %>
110
+ <% end %>
111
+ <% end %>
102
112
 
103
- - On symbol it make by default a sorting
104
- - On symbol it will add the translation (I18n.t)
105
- - On sorting it will add a class with an image to show the sort order
113
+ ### Caption
106
114
 
107
- Column:
115
+ Create a tag caption to set a title to the table, it can be called
116
+ with or without a block
108
117
 
109
- - On Symbol it will find the value in collection
110
- - On Object Date or DateTime it will add the localization (I18n.l)
111
- - On Column name (price, total_price, ...) it will the currency
112
- - On Boolean it will add the translation (I18n.t) true or false
118
+ <% sorting_table_for @users do |table| %>
119
+ <%= table.caption 'my title' %>
120
+ <% end %>
113
121
 
114
- You can customize the table
122
+ ### Options
115
123
 
116
- <%- sorting_table_for @users do |table| %>
124
+ - :html => Hash options: class, id, ...
125
+ - :as => Force to render a type (:date, :time, :currency)
126
+ - :format => Set the I18n localization format for :date or :time (:default, :short, ...)
127
+ - :action => Set an action
128
+ - :caption => Set caption on td
129
+ - :actions => Set actions to render
130
+ - :only => Columns to render (on list)
131
+ - :except => Columns to not render (on list)
132
+ - :sort => Add or not sorting (true of false)
133
+
134
+ Options for sorting table for
135
+
136
+ - :builder => Set a table builder
137
+ - :html => Set html options (id, class, ...)
138
+ - :remote_link => To set actions link with ajax (true or false)
139
+ - :remote_sort => To set link for sorting with ajax (true of false)
140
+ - :i18n => To use or not i18n on values (true or false)
141
+
142
+ Exemple
143
+
144
+ <% sorting_table_for @users do |table| %>
117
145
  <%= table.headers do %>
118
146
  <%= table.header :username %>
119
147
  <%= table.header :price, :sort => false %>
120
148
  <%= table.header :created_at %>
121
149
  <%= table.header 'today' %>
122
- <%- end %>
150
+ <% end %>
123
151
  <%= table.columns do |user| %>
124
152
  <%= table.column user.username %>
125
153
  <%= table.column user.price, :as => :currency %>
126
154
  <%= table.column user.created, :as => :date %>
127
155
  <%= table.column DateTime.now, :as => :datetime, :format => :short %>
128
- <%- end %>
129
- <%- end %>
156
+ <% end %>
157
+ <% end %>
130
158
 
131
- You can customize the table with action
159
+ Exemple with action
132
160
 
133
- <%- sorting_table_for @users do |table| %>
161
+ <% sorting_table_for @users do |table| %>
134
162
  <%= table.headers do %>
135
163
  <%= table.header :username %>
136
164
  <%= table.header :action => :edit %>
137
- <%- end %>
165
+ <% end %>
138
166
  <%= table.columns do |user| %>
139
167
  <%= table.column user.username, :action => :show %>
140
168
  <%= table.column :action => :edit %>
141
- <%- end %>
142
- <%- end %>
169
+ <% end %>
170
+ <% end %>
143
171
 
144
- You can customize the html and add title
172
+ Exemple with html
145
173
 
146
- <%- sorting_table_for @users, :html => { :class => 'my_table' } do |table| %>
174
+ <% sorting_table_for @users, :html => { :class => 'my_table' } do |table| %>
147
175
  <%= table.headers :html => { :class => 'my_headers', :title => 'column !' } do %>
148
176
  <%= table.header :username :html => { :class => 'header_username' } %>
149
177
  <%= table.header :firstname :html => { :title => 'hello price' } %>
150
- <%- end %>
178
+ <% end %>
151
179
  <%= table.columns :html => { :class => 'my_columns' } do |user| %>
152
180
  <%= table.column :username :html => { :class => 'column_username' }%>
153
- <%= table.column :firstname :html => { :title => "it's #{val.firstname}" } %>
154
- <%- end %>
155
- <%- end %>
181
+ <%= table.column :firstname :html => { :title => "it's #{user.firstname}" } %>
182
+ <% end %>
183
+ <% end %>
156
184
 
157
185
  ## Namespace
158
186
 
159
187
  SortingTableFor can use your namespace
160
188
 
161
- <%- sorting_table_for [:admin, @users] do |table| %>
189
+ <% sorting_table_for [:admin, @users] do |table| %>
162
190
  <%= table.headers %>
163
191
  <%= table.columns %>
164
- <%- end %>
192
+ <% end %>
165
193
 
166
194
  ## Sorting
167
195
 
168
- To add sorting in your query, you just have to add sorting_table in your query
196
+ To add sort in your query, you just have to add sorting_table in your query
169
197
 
170
198
  def index
171
199
  @users = User.sorting_table(params).all
172
200
  end
173
201
 
174
- to add a default sorting
202
+ to add a default sorting
175
203
 
176
204
  def index
177
205
  @users = User.sorting_table(params, :username).all
@@ -187,34 +215,33 @@ to add a default sorting
187
215
 
188
216
  You can add ajax on sorting
189
217
 
190
- <%- sorting_table_for @users, :sort_remote => true do |table| %>
218
+ <% sorting_table_for @users, :sort_remote => true do |table| %>
191
219
  <%= table.headers %>
192
220
  <%= table.columns %>
193
- <%- end %>
221
+ <% end %>
194
222
 
195
223
  You can add ajax on links
196
224
 
197
- <%- sorting_table_for @users, :link_remote => true do |table| %>
198
- <%= table.headers %>
199
- <%= table.columns %>
200
- <%- end %>
201
-
202
- ## Stylesheet
225
+ <% sorting_table_for @users, :link_remote => true do |table| %>
226
+ <%= table.headers %>
227
+ <%= table.columns %>
228
+ <% end %>
203
229
 
204
- there are a default stylesheet in _stylesheet_
230
+ ## Configurations
205
231
 
206
- - A class 'odd' or 'even' on rows
207
- - A class 'cur-sort-not', 'cur-sort-asc' or 'cur-sort-desc' on headers that you want to sort
232
+ There are some options that you can modify in your initiatilizer
208
233
 
209
- [_Here an exemple of css file_][]
234
+ [_see the initializer file exemple for more explanation_][]
210
235
 
211
- ## Configurations
236
+ ## Stylesheet
212
237
 
213
- There are some options that you can customize in your initiatilizer
238
+ - Class 'odd' or 'even' on rows
239
+ - Class 'cur-sort-not', 'cur-sort-asc' or 'cur-sort-desc' on sorting headers
240
+ - Class 'total-entries' on total entries
214
241
 
215
- [_see the initializer file exemple for more explanation_][]
242
+ [_Here an exemple of css file_][]
216
243
 
217
- Copyright (c) 2010 arkownz (tom), released under the MIT license
244
+ Copyright (c) 2010 arkownz (Thomas Floch), released under the MIT license
218
245
 
219
246
  [_see the initializer file exemple for more explanation_]: http://github.com/arkownz/sorting_table_for/blob/master/assets/config/initializers/sorting_table_for.rb
220
247
  [_Here an exemple of css file_]: http://github.com/arkownz/sorting_table_for/blob/master/assets/public/stylesheets/sorting_table_for.css
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ ## All the values here are the defauls
4
+
5
+ ## This is the column you don't want to show by default
6
+ ## Array with columns name
7
+ ## SortingTableFor::TableBuilder.reserved_columns = [:id, :password, :salt]
8
+
9
+ ## Set the currency default columns
10
+ ## Array with columns name
11
+ ## SortingTableFor::TableBuilder.currency_columns = [:price, :total_price, :currency, :money]
12
+
13
+ ## Set default for the boolean values
14
+ ## Array with two states
15
+ ## SortingTableFor::TableBuilder.default_boolean = [I18n.t(:bool_true, :scope => [:sorting_table_for, :columns]), I18n.t(:bool_false, :scope => [:sorting_table_for, :columns])]
16
+
17
+ ## Show the total entries in table
18
+ ## true or false
19
+ ## SortingTableFor::TableBuilder.show_total_entries = true
20
+
21
+ ## The name of the url params for sorting
22
+ ## SortingTableFor::TableBuilder.params_sort_table = :table_sort
23
+
24
+ ## The html classes for sorting
25
+ ## Array with the tree states
26
+ ## SortingTableFor::TableBuilder.html_sorting_class = ['cur-sort-not', 'cur_sort_asc', 'cur-sort-desc']
27
+
28
+ ## Set default for actions
29
+ ## Array with actions
30
+ ## SortingTableFor::TableBuilder.default_actions = [:edit, :delete]
31
+
32
+ ## The default format for I18n localization
33
+ ## I18n.l
34
+ ## SortingTableFor::TableBuilder.i18n_default_format_date = :default
35
+
36
+ ## The default scope for localisation
37
+ ## I18n.t
38
+ ## Keywords are: namespace, controller, action, model
39
+ ## SortingTableFor::TableBuilder.i18n_default_scope = [:namespace, :controller, :action]
40
+
41
+ ## This value is add a value by default header's scope
42
+ ## SortingTableFor::TableBuilder.i18n_add_header_action_scope = :header
43
+
44
+ ## This value is add a value by default footer's scope
45
+ ## SortingTableFor::TableBuilder.i18n_add_footer_action_scope = :footer
@@ -0,0 +1,22 @@
1
+ Silk icon set 1.3
2
+
3
+ _________________________________________
4
+ Mark James
5
+ http://www.famfamfam.com/lab/icons/silk/
6
+ _________________________________________
7
+
8
+ This work is licensed under a
9
+ Creative Commons Attribution 2.5 License.
10
+ [ http://creativecommons.org/licenses/by/2.5/ ]
11
+
12
+ This means you may use it for any purpose,
13
+ and make any changes you like.
14
+ All I ask is that you include a link back
15
+ to this page in your credits.
16
+
17
+ Are you using this icon set? Send me an email
18
+ (including a link or picture if available) to
19
+ mjames@gmail.com
20
+
21
+ Any other questions about this icon set please
22
+ contact mjames@gmail.com
@@ -0,0 +1,13 @@
1
+ table.sorting_table_for { background-color: #BCBAB6; width: 100%; font-size: 12px; }
2
+ table.sorting_table_for thead tr th { background-color: #F0CFAD; text-align: left; color: black; padding: 4px; }
3
+ table.sorting_table_for thead tr th a { color: black; cursor: pointer; display: block; width: 100%; height: 100%; }
4
+ table.sorting_table_for thead tr th a:hover { text-decoration: underline; }
5
+ table.sorting_table_for thead tr th.cur-sort-not { background: #F0CFAD url('/images/sorting_table_for/bullet_black.png') no-repeat right; }
6
+ table.sorting_table_for thead tr th.cur-sort-asc { background: #F0CFAD url('/images/sorting_table_for/bullet_arrow_down.png') no-repeat right; }
7
+ table.sorting_table_for thead tr th.cur-sort-desc { background: #F0CFAD url('/images/sorting_table_for/bullet_arrow_up.png') no-repeat right; }
8
+ table.sorting_table_for tbody tr.odd { background-color: #8FF1F4; }
9
+ table.sorting_table_for tbody tr.even { background-color: white; }
10
+ table.sorting_table_for tbody tr.total-entries { background-color: white; }
11
+ table.sorting_table_for tbody tr td { padding: 4px; text-align: center; }
12
+ table.sorting_table_for tbody tr td a { color: black; cursor: pointer; display: block; width: 100%; height: 100%; }
13
+ table.sorting_table_for tfoot tr { background-color: white; text-align: center; }
@@ -13,16 +13,19 @@ module SortingTableFor
13
13
  # <% end %>
14
14
  #
15
15
  # <% sorting_table_for @users do |table| %>
16
+ # <%= table.caption %>
16
17
  # <%= table.headers %>
17
18
  # <%= table.columns %>
19
+ # <%= table.footers %>
18
20
  # <% end %>
19
21
  #
20
22
  # === Options
21
23
  #
22
- # * :builder - Set a table builder (default: SortingTableFor::TableBuilder)
23
- # * :html - Set html options (id, class, ...)
24
- # * :remote_link - To set actions link with ajax (true or false)
25
- # * :remote_sort - To set link for sorting with ajax (true of false)
24
+ # * :builder - Set a table builder, default: SortingTableFor::TableBuilder
25
+ # * :html - Set html options (id, class, ...), default: empty
26
+ # * :remote_link - To set actions link with ajax (true or false), default: false
27
+ # * :remote_sort - To set link for sorting with ajax (true of false), default: false
28
+ # * :i18n - To use or not i18n on values (true or false), default: true
26
29
  #
27
30
  def sorting_table_for(object_or_array, *args)
28
31
  raise ArgumentError, 'Missing block' unless block_given?
@@ -5,16 +5,21 @@ module SortingTableFor
5
5
  class << self
6
6
 
7
7
  # Set options to create a default scope
8
- def set_options(params, model_name, namespace)
9
- @params, @model_name, @namespace = params, model_name, namespace
8
+ def set_options(params, model_name, namespace, i18n_active = true)
9
+ @params, @model_name, @namespace, @i18n_active = params, model_name, namespace, i18n_active
10
10
  end
11
11
 
12
12
  # Translate
13
13
  # Add a default scope if option scope isn't defined
14
- def translate(attribute, options = {}, action_header = false)
14
+ def translate(attribute, options = {}, type = nil)
15
+ if !@i18n_active
16
+ return options[:value] if options.has_key? :value
17
+ return attribute
18
+ end
15
19
  if !options.has_key? :scope
16
20
  options[:scope] = create_scope
17
- options[:scope] << TableBuilder.i18n_add_header_action_scope if action_header
21
+ options[:scope] << TableBuilder.i18n_add_header_action_scope if type and type == :header
22
+ options[:scope] << TableBuilder.i18n_add_footer_action_scope if type and type == :footer
18
23
  end
19
24
  ::I18n.t(attribute, options)
20
25
  end