tabulatr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +106 -0
- data/LICENSE +23 -0
- data/README.textile +284 -0
- data/Rakefile +11 -0
- data/assets/simple_table.png +0 -0
- data/assets/tabulatr.css +107 -0
- data/lib/initializers/action_view.rb +31 -0
- data/lib/initializers/active_record.rb +32 -0
- data/lib/initializers/mark_as_localizable.rb +43 -0
- data/lib/initializers/mongoid.rb +34 -0
- data/lib/tabulatr/tabulatr/batch_actions.rb +52 -0
- data/lib/tabulatr/tabulatr/check_controls.rb +43 -0
- data/lib/tabulatr/tabulatr/data_cell.rb +118 -0
- data/lib/tabulatr/tabulatr/filter_cell.rb +130 -0
- data/lib/tabulatr/tabulatr/finder/find_for_active_record_table.rb +162 -0
- data/lib/tabulatr/tabulatr/finder/find_for_mongoid_table.rb +116 -0
- data/lib/tabulatr/tabulatr/finder.rb +82 -0
- data/lib/tabulatr/tabulatr/formattr.rb +51 -0
- data/lib/tabulatr/tabulatr/header_cell.rb +94 -0
- data/lib/tabulatr/tabulatr/paginator.rb +88 -0
- data/lib/tabulatr/tabulatr/row_builder.rb +115 -0
- data/lib/tabulatr/tabulatr/settings.rb +221 -0
- data/lib/tabulatr/tabulatr.rb +238 -0
- data/lib/tabulatr.rb +34 -0
- data/tabulatr.gemspec +26 -0
- metadata +143 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tabulatr (0.0.1)
|
5
|
+
id_stuffer (>= 0.0.1)
|
6
|
+
rails (~> 3.0.3)
|
7
|
+
whiny_hash (>= 0.0.2)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
abstract (1.0.0)
|
13
|
+
actionmailer (3.0.3)
|
14
|
+
actionpack (= 3.0.3)
|
15
|
+
mail (~> 2.2.9)
|
16
|
+
actionpack (3.0.3)
|
17
|
+
activemodel (= 3.0.3)
|
18
|
+
activesupport (= 3.0.3)
|
19
|
+
builder (~> 2.1.2)
|
20
|
+
erubis (~> 2.6.6)
|
21
|
+
i18n (~> 0.4)
|
22
|
+
rack (~> 1.2.1)
|
23
|
+
rack-mount (~> 0.6.13)
|
24
|
+
rack-test (~> 0.5.6)
|
25
|
+
tzinfo (~> 0.3.23)
|
26
|
+
activemodel (3.0.3)
|
27
|
+
activesupport (= 3.0.3)
|
28
|
+
builder (~> 2.1.2)
|
29
|
+
i18n (~> 0.4)
|
30
|
+
activerecord (3.0.3)
|
31
|
+
activemodel (= 3.0.3)
|
32
|
+
activesupport (= 3.0.3)
|
33
|
+
arel (~> 2.0.2)
|
34
|
+
tzinfo (~> 0.3.23)
|
35
|
+
activeresource (3.0.3)
|
36
|
+
activemodel (= 3.0.3)
|
37
|
+
activesupport (= 3.0.3)
|
38
|
+
activesupport (3.0.3)
|
39
|
+
arel (2.0.7)
|
40
|
+
builder (2.1.2)
|
41
|
+
diff-lcs (1.1.2)
|
42
|
+
erubis (2.6.6)
|
43
|
+
abstract (>= 1.0.0)
|
44
|
+
i18n (0.5.0)
|
45
|
+
id_stuffer (0.0.1)
|
46
|
+
mail (2.2.15)
|
47
|
+
activesupport (>= 2.3.6)
|
48
|
+
i18n (>= 0.4.0)
|
49
|
+
mime-types (~> 1.16)
|
50
|
+
treetop (~> 1.4.8)
|
51
|
+
mime-types (1.16)
|
52
|
+
nokogiri (1.4.4)
|
53
|
+
polyglot (0.3.1)
|
54
|
+
rack (1.2.1)
|
55
|
+
rack-mount (0.6.13)
|
56
|
+
rack (>= 1.0.0)
|
57
|
+
rack-test (0.5.6)
|
58
|
+
rack (>= 1.0)
|
59
|
+
rails (3.0.3)
|
60
|
+
actionmailer (= 3.0.3)
|
61
|
+
actionpack (= 3.0.3)
|
62
|
+
activerecord (= 3.0.3)
|
63
|
+
activeresource (= 3.0.3)
|
64
|
+
activesupport (= 3.0.3)
|
65
|
+
bundler (~> 1.0)
|
66
|
+
railties (= 3.0.3)
|
67
|
+
railties (3.0.3)
|
68
|
+
actionpack (= 3.0.3)
|
69
|
+
activesupport (= 3.0.3)
|
70
|
+
rake (>= 0.8.7)
|
71
|
+
thor (~> 0.14.4)
|
72
|
+
rake (0.8.7)
|
73
|
+
rspec (2.3.0)
|
74
|
+
rspec-core (~> 2.3.0)
|
75
|
+
rspec-expectations (~> 2.3.0)
|
76
|
+
rspec-mocks (~> 2.3.0)
|
77
|
+
rspec-core (2.3.1)
|
78
|
+
rspec-expectations (2.3.0)
|
79
|
+
diff-lcs (~> 1.1.2)
|
80
|
+
rspec-mocks (2.3.0)
|
81
|
+
rspec-rails (2.3.1)
|
82
|
+
actionpack (~> 3.0)
|
83
|
+
activesupport (~> 3.0)
|
84
|
+
railties (~> 3.0)
|
85
|
+
rspec (~> 2.3.0)
|
86
|
+
thor (0.14.6)
|
87
|
+
treetop (1.4.9)
|
88
|
+
polyglot (>= 0.3.1)
|
89
|
+
tzinfo (0.3.23)
|
90
|
+
webrat (0.7.2)
|
91
|
+
nokogiri (>= 1.2.0)
|
92
|
+
rack (>= 1.0)
|
93
|
+
rack-test (>= 0.5.3)
|
94
|
+
whiny_hash (0.0.2)
|
95
|
+
|
96
|
+
PLATFORMS
|
97
|
+
ruby
|
98
|
+
|
99
|
+
DEPENDENCIES
|
100
|
+
id_stuffer
|
101
|
+
rails
|
102
|
+
rspec
|
103
|
+
rspec-rails
|
104
|
+
tabulatr!
|
105
|
+
webrat
|
106
|
+
whiny_hash
|
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010-2011 by Provideal GmbH, Peter Horn
|
4
|
+
http://www.provideal.net, peter.horn@provideal.net
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
23
|
+
|
data/README.textile
ADDED
@@ -0,0 +1,284 @@
|
|
1
|
+
h1. Tabulatr - Index Tables made easy, finally
|
2
|
+
|
3
|
+
h2. Mission Objective
|
4
|
+
|
5
|
+
Tabulatr aims at making the ever-recurring task of creating listings of ActiveRecord models simple and uniform.
|
6
|
+
|
7
|
+
We found ourselves reinventing the wheel in every project we made, by using
|
8
|
+
|
9
|
+
* different paging mechanisms,
|
10
|
+
* different ways of implementing filtering/searching,
|
11
|
+
* difterent ways of implementing selecting and batch actions,
|
12
|
+
* different layouts.
|
13
|
+
|
14
|
+
We finally thought that whilst gems like Formtastic or SimpleForm provide a really cool, uniform, and concise way to implement forms, it's time for a table builder. During a project with Magento (*shiver*) we decided that their general tables are quite reasonable, and enterprise-proven -- so that's our starting point.
|
15
|
+
|
16
|
+
h3. Visual Components
|
17
|
+
|
18
|
+
Every Tabulatr table consists of the following components:
|
19
|
+
|
20
|
+
* a wrapping form
|
21
|
+
* a 'Controls Container' containing the table-controls as
|
22
|
+
* the paginator,
|
23
|
+
* the batch_actions,
|
24
|
+
* the submit button,
|
25
|
+
* controls to manage selecting/checking/marking,
|
26
|
+
* an info_text
|
27
|
+
* The actual table consisting of
|
28
|
+
* A header row,
|
29
|
+
* A filter row,
|
30
|
+
* data rows,
|
31
|
+
* possibly a selecting/checking/marking column
|
32
|
+
* possibly action links/buttons
|
33
|
+
|
34
|
+
Whilst this is a strong decision, we made everything as-configurable-as-possible, there are roughly 150 options you can use to tweak almost every aspect of Tabulatr.
|
35
|
+
|
36
|
+
h3. Features
|
37
|
+
|
38
|
+
Tabulatr tries to make these common tasks as simple/transparent as possible:
|
39
|
+
* paging
|
40
|
+
* selecting/checking/marking
|
41
|
+
* filtering
|
42
|
+
* batch actions
|
43
|
+
|
44
|
+
h2. Example
|
45
|
+
|
46
|
+
h3. Models
|
47
|
+
|
48
|
+
We suppose we have a couple of models
|
49
|
+
* tags has and belong to many products
|
50
|
+
* vendors have many products
|
51
|
+
* products belong to vendors and have and belong to many tags
|
52
|
+
|
53
|
+
h3. Controller
|
54
|
+
|
55
|
+
In the products controllers index action we have:
|
56
|
+
|
57
|
+
<pre>
|
58
|
+
def index
|
59
|
+
@products = Product.find_for_table(params)
|
60
|
+
end
|
61
|
+
</pre>
|
62
|
+
|
63
|
+
the find_for_table method is injected into ActiveRecord by Tabulatr, it retrieves all relevant data from the params hash automagically.
|
64
|
+
|
65
|
+
h3.View
|
66
|
+
|
67
|
+
To get a simple Table, all we need to do is
|
68
|
+
|
69
|
+
<pre>
|
70
|
+
<%= table_for @products do |t|
|
71
|
+
t.column :id
|
72
|
+
t.column :title
|
73
|
+
t.column :price
|
74
|
+
t.column :active
|
75
|
+
t.association :vendor, :name
|
76
|
+
t.association :tags, :title
|
77
|
+
end %>
|
78
|
+
</pre>
|
79
|
+
|
80
|
+
but the result is pretty fancy, already:
|
81
|
+
|
82
|
+
<img src="assets/simple_table.png" />
|
83
|
+
|
84
|
+
To add a column with ckeckboxes (thus giving all the "Select ..." buttons a reasonable semantics), we simply add a
|
85
|
+
<pre>
|
86
|
+
t.checkbox
|
87
|
+
</pre>
|
88
|
+
row.
|
89
|
+
|
90
|
+
To add e.g. edit-buttons, we specify
|
91
|
+
<pre>
|
92
|
+
t.action do |record|
|
93
|
+
link_to "Edit", edit_product_path(record)
|
94
|
+
end
|
95
|
+
</pre>
|
96
|
+
|
97
|
+
To add a select-popup with batch-actions (i.e., actions that are to be perfored on all selected rows), we add an option to the table_for:
|
98
|
+
<pre>
|
99
|
+
<%= table_for @products, :batch_actions => {'foo' => 'Foo', 'delete' => "Delete"} do |t|
|
100
|
+
...
|
101
|
+
end %>
|
102
|
+
</pre>
|
103
|
+
|
104
|
+
to handle the actual batch action, we have to add a block to the <tt>find_for_table</tt> call in the controller:
|
105
|
+
<pre>
|
106
|
+
@products = Product.find_for_table(params) do |batch_actions|
|
107
|
+
batch_actions.delete do |ids|
|
108
|
+
ids.each do |id|
|
109
|
+
Product.find(id).destroy
|
110
|
+
end
|
111
|
+
redirect_to index_select_products_path()
|
112
|
+
return
|
113
|
+
end
|
114
|
+
batch_actions.foo do |ids|
|
115
|
+
# do whatever is foo-ish to the records
|
116
|
+
end
|
117
|
+
end
|
118
|
+
</pre>
|
119
|
+
where the <tt>ids</tt> parameter to the block is actually an Array containing the numeric ids of the currently selected rows.
|
120
|
+
|
121
|
+
h2. Options
|
122
|
+
|
123
|
+
Literally every aspect of Tabulatr can be tweaked to fit your needs. You may add or remove components, change the class or other html attributes of the generated html nodes. There are options of several types:
|
124
|
+
|
125
|
+
h3. Table Options
|
126
|
+
|
127
|
+
These options are to be specified at the form_for level and change the appearance and behaviour of the table. This is taken from <tt>lib/tabulatr/tabulatr/settings.rb</tt>
|
128
|
+
|
129
|
+
<pre>
|
130
|
+
remote: false, # add data-remote="true" to form
|
131
|
+
form_class: 'tabulatr_form', # class of the overall form
|
132
|
+
table_class: 'tabulatr_table', # class for the actual data table
|
133
|
+
sortable_class: 'sortable', # class for the header of a sortable column
|
134
|
+
sorting_asc_class: 'sorting-asc', # class for the currently asc sorting column
|
135
|
+
sorting_desc_class: 'sorting-desc', # class for the currently desc sorting column
|
136
|
+
page_left_class: 'page-left', # class for the page left button
|
137
|
+
page_right_class: 'page-right', # class for the page right button
|
138
|
+
page_no_class: 'page-no', # class for the page no <input>
|
139
|
+
control_div_class_before: 'table-controls', # class of the upper div containing the paging and batch action controls
|
140
|
+
control_div_class_after: 'table-controls', # class of the lower div containing the paging and batch action controls
|
141
|
+
paginator_div_class: 'paginator', # class of the div containing the paging controls
|
142
|
+
batch_actions_div_class: 'batch-actions', # class of the div containing the batch action controls
|
143
|
+
select_controls_div_class: 'check-controls', # class of the div containing the check controls
|
144
|
+
submit_class: 'submit-table', # class of submit button
|
145
|
+
pagesize_select_class: 'pagesize_select', # class of the pagesize select element
|
146
|
+
select_all_class: 'select-btn', # class of the select all button
|
147
|
+
select_none_class: 'select-btn', # class of the select none button
|
148
|
+
select_visible_class: 'select-btn', # class of the select visible button
|
149
|
+
unselect_visible_class: 'select-btn', # class of the unselect visible button
|
150
|
+
select_filtered_class: 'select-btn', # class of the select filtered button
|
151
|
+
unselect_filtered_class: 'select-btn', # class of the unselect filteredbutton
|
152
|
+
info_text_class: 'info-text', # class of the info text div
|
153
|
+
|
154
|
+
batch_actions_label: 'Batch Action: ', # Text to show in front of the batch action select
|
155
|
+
batch_actions_type: :select, # :select or :button depending on the kind of input you want
|
156
|
+
batch_actions_class: 'batch-action-inputs', # class to apply on the batch action input elements
|
157
|
+
submit_label: 'Apply', # Text on the submit button
|
158
|
+
select_all_label: 'Select All', # Text on the select all button
|
159
|
+
select_none_label: 'Select None', # Text on the select none button
|
160
|
+
select_visible_label: 'Select visible', # Text on the select visible button
|
161
|
+
unselect_visible_label: 'Unselect visible', # Text on the unselect visible button
|
162
|
+
select_filtered_label: 'Select filtered', # Text on the select filtered button
|
163
|
+
unselect_filtered_label: 'Unselect filtered',# Text on the unselect filtered button
|
164
|
+
info_text: "Showing %1$d, total %2$d, selected %3$d, matching %4$d",
|
165
|
+
|
166
|
+
# which controls to be rendered above and below the tabel and in which order
|
167
|
+
before_table_controls: [:submit, :paginator, :batch_actions, :select_controls, :info_text],
|
168
|
+
after_table_controls: [],
|
169
|
+
|
170
|
+
# whih selecting controls to render in which order
|
171
|
+
select_controls: [:select_all, :select_none, :select_visible, :unselect_visible,
|
172
|
+
:select_filtered, :unselect_filtered],
|
173
|
+
|
174
|
+
image_path_prefix: '/images/tabulatr/',
|
175
|
+
pager_left_button: 'left.gif',
|
176
|
+
pager_left_button_inactive: 'left_off.gif',
|
177
|
+
pager_right_button: 'right.gif',
|
178
|
+
pager_right_button_inactive: 'right_off.gif',
|
179
|
+
sort_up_button: 'up.gif',
|
180
|
+
sort_up_button_inactive: 'up_off.gif',
|
181
|
+
sort_down_button: 'down.gif',
|
182
|
+
sort_down_button_inactive: 'down_off.gif',
|
183
|
+
|
184
|
+
make_form: true, # whether or not to wrap the whole table (incl. controls) in a form
|
185
|
+
table_html: false, # a hash with html attributes for the table
|
186
|
+
row_html: false, # a hash with html attributes for the normal trs
|
187
|
+
header_html: false, # a hash with html attributes for the header trs
|
188
|
+
filter_html: false, # a hash with html attributes for the filter trs
|
189
|
+
filter: true, # false for no filter row at all
|
190
|
+
paginate: true, # true to show paginator
|
191
|
+
sortable: true, # true to allow sorting (can be specified for every sortable column)
|
192
|
+
selectable: true, # true to render "select all", "select none" and the like
|
193
|
+
action: nil, # target action of the wrapping form if applicable
|
194
|
+
batch_actions: false, # name: value hash of batch action stuff
|
195
|
+
translate: false, # call t() for all 'labels' and stuff, possible values are true/:translate or :localize
|
196
|
+
row_classes: ['odd', 'even'] # class for the trs
|
197
|
+
</pre>
|
198
|
+
|
199
|
+
h3. Column Options
|
200
|
+
|
201
|
+
<pre>
|
202
|
+
header: false, # a string to write into the header cell
|
203
|
+
width: false, # the width of the cell
|
204
|
+
align: false, # horizontal alignment
|
205
|
+
valign: false, # vertical alignment
|
206
|
+
wrap: true, # wraps
|
207
|
+
type: :string, # :integer, :date
|
208
|
+
td_html: false, # a hash with html attributes for the cells
|
209
|
+
th_html: false, # a hash with html attributes for the header cell
|
210
|
+
filter_html: false, # a hash with html attributes for the filter cell
|
211
|
+
filter_html: false, # a hash with html attributes for the filter cell
|
212
|
+
filter: true, # false for no filter field,
|
213
|
+
# container for options_for_select
|
214
|
+
# String from options_from_collection_for_select or the like
|
215
|
+
# :range for range spec
|
216
|
+
# :checkbox for a 0/1 valued checkbox
|
217
|
+
checkbox_value: '1', # value if checkbox is checked
|
218
|
+
checkbox_label: '', # text behind the checkbox
|
219
|
+
filter_width: '97%', # width of the filter <input>
|
220
|
+
range_filter_symbol: '–', # put between the <inputs> of the range filter
|
221
|
+
format: false, # a sprintf-string or a proc to do special formatting
|
222
|
+
method: false, # if you want to get the column by a different method than its name
|
223
|
+
link: false, # proc or symbol to make the content a link
|
224
|
+
join_symbol: ', ', # symbol used to join the elements of 'many' associations
|
225
|
+
sortable: true # if set, sorting-stuff is added to the header cell
|
226
|
+
</pre>
|
227
|
+
|
228
|
+
h3. Global settings
|
229
|
+
|
230
|
+
These settings are *not* supposed to be changed on a per-table basis. This is necessary, because the <tt>find_for_table</tt> method needs to rely on a priori information.
|
231
|
+
|
232
|
+
h4. Table Form Options
|
233
|
+
|
234
|
+
This hash contains all the information about the naming of the generated form elements. To override them, you should, in an initializer, call
|
235
|
+
<pre>
|
236
|
+
Tabulatr.table_form_options(my_options_hash)
|
237
|
+
</pre>
|
238
|
+
|
239
|
+
<pre>
|
240
|
+
batch_action_name: 'batch_action', # name of the batch action param
|
241
|
+
sort_by_key: 'sort_by_key', # name of key which to search, format is 'id asc'
|
242
|
+
pagination_postfix: '_pagination', # name of the param w/ the pagination infos
|
243
|
+
filter_postfix: '_filter', # postfix for name of the filter in the params hash: xxx_filter
|
244
|
+
sort_postfix: '_sort', # postfix for name of the filter in the params hash: xxx_filter
|
245
|
+
checked_postfix: '_checked', # postfix for name of the checked in the params hash: xxx_filter
|
246
|
+
associations_filter: '__association', # name of the associations in the filter hash
|
247
|
+
method: 'post', # http method for that form if applicable
|
248
|
+
batch_postfix: '_batch', # postfix for name of the batch action select
|
249
|
+
checked_separator: ',' # symbol to separate the checked ids
|
250
|
+
</pre>
|
251
|
+
|
252
|
+
h4. Paginate options
|
253
|
+
|
254
|
+
To override these, you should, in an initializer, call
|
255
|
+
<pre>
|
256
|
+
Tabulatr.paginate_options(my_options_hash)
|
257
|
+
</pre>
|
258
|
+
|
259
|
+
<pre>
|
260
|
+
page: 1,
|
261
|
+
pagesize: 10,
|
262
|
+
pagesizes: [10, 20, 50]
|
263
|
+
</pre>
|
264
|
+
|
265
|
+
h2.Dependencies
|
266
|
+
|
267
|
+
We use
|
268
|
+
* <a href="http://github.com/providel/whiny_hash">WhinyHash</a> to handle the options in a fail-early-manner,
|
269
|
+
* <a href="http://github.com/providel/id_stuffer">IdStuffer</a> to compress the _remembered_ ids.
|
270
|
+
* And... eh... It's an extension for rails, so it might be handy to have a version of rails 3 and ruby 1.9.
|
271
|
+
|
272
|
+
h2.Bugs
|
273
|
+
|
274
|
+
There are, definitely, roughly 1000 bugs in Tabulatr, although we do some testing (see <tt>spec/dummy_app/spec</tt>). So if you hunt them, please let me know.
|
275
|
+
|
276
|
+
h2. License
|
277
|
+
|
278
|
+
Copyright (c) 2010-2011 Peter Horn, <a href="http://www.provideal.net" target="_blank">Provideal GmbH</a>
|
279
|
+
|
280
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
281
|
+
|
282
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
283
|
+
|
284
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
require 'rspec/core'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
|
11
|
+
task :default => :spec
|
Binary file
|
data/assets/tabulatr.css
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
<style type="text/css" media="screen">
|
2
|
+
|
3
|
+
body {
|
4
|
+
font: 9pt Verdana;
|
5
|
+
}
|
6
|
+
|
7
|
+
table {
|
8
|
+
border-collapse: collapse;
|
9
|
+
width:100%;
|
10
|
+
}
|
11
|
+
|
12
|
+
td, th {
|
13
|
+
border: 1px solid gray;
|
14
|
+
padding:5px;
|
15
|
+
text-overflow: ellipsis;
|
16
|
+
white-space: nowrap;
|
17
|
+
overflow: ellipsis;
|
18
|
+
}
|
19
|
+
|
20
|
+
th {
|
21
|
+
background-color: #ccc;
|
22
|
+
text-shadow: 1px 1px 1px rgba(0,0,0,.2);
|
23
|
+
}
|
24
|
+
|
25
|
+
div.table-controls {
|
26
|
+
font: 9pt Verdana;
|
27
|
+
width: 100%-10px;
|
28
|
+
border: 1px solid gray;
|
29
|
+
padding:5px;
|
30
|
+
margin-bottom: 10px;
|
31
|
+
background-color: #eee;
|
32
|
+
border-radius: 5px;
|
33
|
+
position: relative;
|
34
|
+
}
|
35
|
+
|
36
|
+
div.table-controls input {
|
37
|
+
font: 9pt Verdana;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.table-controls input[type=submit] {
|
41
|
+
position: relative;
|
42
|
+
background-repeat: repeat-x;
|
43
|
+
color: #efefef;
|
44
|
+
font-weight: bold;
|
45
|
+
display: inline-block;
|
46
|
+
text-decoration: none;
|
47
|
+
border-width: 1px;
|
48
|
+
border-style: solid;
|
49
|
+
padding: 0 12px;
|
50
|
+
margin: 0;
|
51
|
+
text-shadow: 1px 1px 1px rgba(0,0,0,.2);
|
52
|
+
-moz-box-shadow: 1px 1px 1px rgba(0,0,0,.25);
|
53
|
+
-webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.25);
|
54
|
+
box-shadow: 1px 1px 1px rgba(0,0,0,.25);
|
55
|
+
-moz-border-radius: 5px;
|
56
|
+
-webkit-border-radius: 5px;
|
57
|
+
border-radius: 5px;
|
58
|
+
cursor: pointer;
|
59
|
+
background-position: 0 -80px;
|
60
|
+
font-size: 11px;
|
61
|
+
height: 24px;
|
62
|
+
line-height: 24px;
|
63
|
+
}
|
64
|
+
|
65
|
+
div.table-controls input[type=submit] {
|
66
|
+
background-image: url(../images/tabulatr/buttons_lite_background.png);
|
67
|
+
background-color: #263849;
|
68
|
+
border-color: #16222c;
|
69
|
+
color: #efefef;
|
70
|
+
}
|
71
|
+
|
72
|
+
div.table-controls input[type=submit]:hover {
|
73
|
+
background-color: #16222c;
|
74
|
+
color: #efefef;
|
75
|
+
text-decoration: none;
|
76
|
+
}
|
77
|
+
|
78
|
+
div.paginator {
|
79
|
+
display: inline-block;
|
80
|
+
margin-right: 40px;
|
81
|
+
}
|
82
|
+
|
83
|
+
div.batch-actions {
|
84
|
+
display: inline-block;
|
85
|
+
}
|
86
|
+
|
87
|
+
div.check-controls {
|
88
|
+
margin-top: 10px;
|
89
|
+
position: absolute;
|
90
|
+
bottom: 5px;
|
91
|
+
right: 5px;
|
92
|
+
}
|
93
|
+
|
94
|
+
div.check-controls input[type=submit] {
|
95
|
+
font-size: 9px;
|
96
|
+
height: 20px;
|
97
|
+
line-height: 20px;
|
98
|
+
margin:3px;
|
99
|
+
}
|
100
|
+
|
101
|
+
div.info-text {
|
102
|
+
margin-top:10px;
|
103
|
+
font-size: 9pt;
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
</style>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2011 Peter Horn, Provideal GmbH
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
class ActionView::Base
|
25
|
+
# render the table in a view
|
26
|
+
def table_for(records, opts={}, &block)
|
27
|
+
tabulatr = Tabulatr.new(records, self, opts)
|
28
|
+
tabulatr.build_table(&block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2011 Peter Horn, Provideal GmbH
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
# We monkey patch ActiveRecord::Base to add a function for finding using
|
25
|
+
# the information of the params hash as created by a Tabulatr table
|
26
|
+
if Object.const_defined? "ActiveRecord"
|
27
|
+
class ActiveRecord::Base
|
28
|
+
def self.find_for_table(params, opts={}, &block)
|
29
|
+
Tabulatr::Finder.find_for_active_record_table(self, params, opts, &block)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2011 Peter Horn, Provideal GmbH
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
# This is probably a REALLY bad idea...
|
25
|
+
module MarkAsLocalizable
|
26
|
+
def l
|
27
|
+
@should_localize = true
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def should_localize?
|
32
|
+
@should_localize == true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class String
|
37
|
+
include MarkAsLocalizable
|
38
|
+
end
|
39
|
+
|
40
|
+
class Symbol
|
41
|
+
include MarkAsLocalizable
|
42
|
+
end
|
43
|
+
|