tabulatr 0.2.0 → 0.3.0

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/Changelog.textile CHANGED
@@ -1,5 +1,14 @@
1
1
  h1. Changelog for tabulatr
2
2
 
3
+ h2. 0.3.0
4
+
5
+ * Converted into a Rails 3.1 engine and moved css and images to use the new asset pipeline. Works with 3.0.x -- 'opefully. Thanks to all that reported the problem.
6
+ * Header cells are now auto translated. Thanks to <a href="https://github.com/niedhui">niedhui</a>!
7
+
8
+ h2. 0.2.1
9
+
10
+ * Fixed a ruby 1.8 syntax issue. Thanks to <a href="https://github.com/TBAA">TBAA</a> for reporting!
11
+
3
12
  h2. 0.2.0
4
13
 
5
14
  * Mongoid can also be used in place of ActiveRecord
data/README.textile CHANGED
@@ -1,6 +1,11 @@
1
1
  h1. Tabulatr - Index Tables made easy, finally
2
2
 
3
- (there is a <a href="https://github.com/provideal/tabulatr-demo">demo app repository</a>)
3
+ <b>Notes:</b>
4
+
5
+ <ul>
6
+ <li>there is a <a href="https://github.com/provideal/tabulatr-demo">demo app repository</a></li>
7
+ <li>note the spelling, it's tabulatr, not tabulat<b>o</b>r.
8
+ </ul>
4
9
 
5
10
  h2. Mission Objective
6
11
 
@@ -0,0 +1 @@
1
+ /*= require tabulatr/application */
@@ -0,0 +1,102 @@
1
+ body {
2
+ font: 9pt Verdana;
3
+ }
4
+
5
+ table {
6
+ border-collapse: collapse;
7
+ width:100%;
8
+ }
9
+
10
+ td, th {
11
+ border: 1px solid gray;
12
+ padding:5px;
13
+ text-overflow: ellipsis;
14
+ white-space: nowrap;
15
+ overflow: ellipsis;
16
+ }
17
+
18
+ th {
19
+ background-color: #ccc;
20
+ text-shadow: 1px 1px 1px rgba(0,0,0,.2);
21
+ }
22
+
23
+ div.table-controls {
24
+ font: 9pt Verdana;
25
+ width: 100%-10px;
26
+ border: 1px solid gray;
27
+ padding:5px;
28
+ margin-bottom: 10px;
29
+ background-color: #eee;
30
+ border-radius: 5px;
31
+ position: relative;
32
+ }
33
+
34
+ div.table-controls input {
35
+ font: 9pt Verdana;
36
+ }
37
+
38
+ div.table-controls input[type=submit] {
39
+ position: relative;
40
+ background-repeat: repeat-x;
41
+ color: #efefef;
42
+ font-weight: bold;
43
+ display: inline-block;
44
+ text-decoration: none;
45
+ border-width: 1px;
46
+ border-style: solid;
47
+ padding: 0 12px;
48
+ margin: 0;
49
+ text-shadow: 1px 1px 1px rgba(0,0,0,.2);
50
+ -moz-box-shadow: 1px 1px 1px rgba(0,0,0,.25);
51
+ -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.25);
52
+ box-shadow: 1px 1px 1px rgba(0,0,0,.25);
53
+ -moz-border-radius: 5px;
54
+ -webkit-border-radius: 5px;
55
+ border-radius: 5px;
56
+ cursor: pointer;
57
+ background-position: 0 -80px;
58
+ font-size: 11px;
59
+ height: 24px;
60
+ line-height: 24px;
61
+ }
62
+
63
+ div.table-controls input[type=submit] {
64
+ background-image: asset-url("buttons_lite_background.png", "image");
65
+ background-color: #263849;
66
+ border-color: #16222c;
67
+ color: #efefef;
68
+ }
69
+
70
+ div.table-controls input[type=submit]:hover {
71
+ background-color: #16222c;
72
+ color: #efefef;
73
+ text-decoration: none;
74
+ }
75
+
76
+ div.paginator {
77
+ display: inline-block;
78
+ margin-right: 40px;
79
+ }
80
+
81
+ div.batch-actions {
82
+ display: inline-block;
83
+ }
84
+
85
+ div.check-controls {
86
+ margin-top: 10px;
87
+ position: absolute;
88
+ bottom: 5px;
89
+ right: 5px;
90
+ }
91
+
92
+ div.check-controls input[type=submit] {
93
+ font-size: 9px;
94
+ height: 20px;
95
+ line-height: 20px;
96
+ margin:3px;
97
+ }
98
+
99
+ div.info-text {
100
+ margin-top:10px;
101
+ font-size: 9pt;
102
+ }
data/lib/tabulatr.rb CHANGED
@@ -22,6 +22,7 @@
22
22
  #++
23
23
 
24
24
  require 'tabulatr/tabulatr'
25
+ require 'tabulatr/engine'
25
26
  require 'whiny_hash'
26
27
  require 'id_stuffer'
27
28
 
@@ -0,0 +1,3 @@
1
+ class Tabulatr::Engine < Rails::Engine
2
+
3
+ end
@@ -42,6 +42,8 @@ class Tabulatr
42
42
  include ActionView::Helpers::FormOptionsHelper
43
43
  include ActionView::Helpers::TranslationHelper
44
44
  include ActionView::Helpers::RecordTagHelper
45
+ # include ActionView::Helpers::AssetTagHelper
46
+ # include Rails::Application::Configurable
45
47
 
46
48
  # Constructor of Tabulatr
47
49
  #
@@ -57,7 +59,7 @@ class Tabulatr
57
59
  @val = []
58
60
  @record = nil
59
61
  @row_mode = false
60
- @classname, @id, @id_type = @records.__classinfo
62
+ @klaz, @classname, @id, @id_type = @records.__classinfo
61
63
  @pagination = @records.__pagination
62
64
  @filters = @records.__filters
63
65
  @sorting = @records.__sorting
@@ -237,6 +239,21 @@ private
237
239
  end
238
240
  nil
239
241
  end
242
+
243
+ def make_image_button(iname, options)
244
+ inactive = options.delete(:inactive)
245
+ psrc = @view.image_path File.join(@table_options[:image_path_prefix], iname)
246
+ if !inactive
247
+ make_tag(:input,
248
+ options.merge(
249
+ :type => 'image',
250
+ :src => psrc
251
+ )
252
+ )
253
+ else
254
+ make_tag(:img, :src => psrc)
255
+ end
256
+ end
240
257
  end
241
258
 
242
259
  Dir[File.join(File.dirname(__FILE__), "tabulatr", "*.rb")].each do |file|
@@ -45,8 +45,8 @@ module Tabulatr::Finder
45
45
  if !str.present?
46
46
  []
47
47
  elsif str.starts_with?("GzB")
48
- Zlib::Inflate.inflate(Base64.decode64(str[3..-1]))
49
- .split(Tabulatr.table_form_options[:checked_separator])
48
+ Zlib::Inflate.inflate(Base64.decode64(str[3..-1])).split(
49
+ Tabulatr.table_form_options[:checked_separator])
50
50
  else
51
51
  IdStuffer.unstuff(str)
52
52
  end
@@ -99,7 +99,8 @@ module Tabulatr::Finder
99
99
  if opts[:stateful]
100
100
  session = opts[:stateful]
101
101
  sname = "#{cname}#{form_options[:state_session_postfix]}"
102
- raise "give the session as the :stateful parameter in find_for_table" unless session.is_a?(ActionDispatch::Session::AbstractStore::SessionHash)
102
+ raise "give the session as the :stateful parameter in find_for_table, not a '#{session.class}'" \
103
+ unless session.is_a?(Rails::version.to_f >= 3.1 ? ActiveSupport::HashWithIndifferentAccess : ActionDispatch::Session::AbstractStore::SessionHash)
103
104
  session[sname] ||= {}
104
105
 
105
106
  if params["#{cname}#{form_options[:reset_state_postfix]}"]
@@ -188,19 +189,23 @@ module Tabulatr::Finder
188
189
  page += 1 if paginate_options[:page_right]
189
190
  page -= 1 if paginate_options[:page_left]
190
191
  c = rel.count
192
+ # Group statments return a hash
193
+ c = c.count unless c.class == Fixnum
191
194
  pages = (c/pagesize).ceil
192
195
  page = [1, [page, pages].min].max
193
196
  total = klaz
194
197
  total = total.where(opts[:precondition]) if opts[:precondition]
198
+ # here too
195
199
  total = total.count
200
+ total = total.count unless total.class == Fixnum
196
201
 
197
202
  # Now, actually find the stuff
198
- found = rel.limit(pagesize.to_i).offset(((page-1)*pagesize).to_i)
199
- .order(order).to_a #, :include => includes
203
+ found = rel.limit(pagesize.to_i).offset(((page-1)*pagesize).to_i
204
+ ).order(order).to_a #, :include => includes
200
205
 
201
206
  # finally, inject methods to retrieve the current 'settings'
202
207
  found.define_singleton_method(:__filters) do filter_param end
203
- found.define_singleton_method(:__classinfo) do [cname, id, id_type] end
208
+ found.define_singleton_method(:__classinfo) do [klaz, cname, id, id_type] end
204
209
  found.define_singleton_method(:__pagination) do
205
210
  { :page => page, :pagesize => pagesize, :count => c, :pages => pages,
206
211
  :pagesizes => paginate_options[:pagesizes],
@@ -37,25 +37,22 @@ class Tabulatr
37
37
  bid = "#{@classname}#{@table_form_options[:sort_postfix]}"
38
38
  opts = normalize_column_options opts
39
39
  make_tag(:th, opts[:th_html]) do
40
- concat(t(opts[:header] || name.to_s.humanize.titlecase), :escape_html)
40
+ concat(t(opts[:header] || @klaz.human_attribute_name(name).titlecase), :escape_html)
41
41
  if opts[:sortable] and @table_options[:sortable]
42
42
  if @sorting and @sorting[:by].to_s == name.to_s
43
43
  pname = "#{sortparam}[_resort][#{name}][#{@sorting[:direction] == 'asc' ? 'desc' : 'asc'}]"
44
44
  bid = "#{bid}_#{name}_#{@sorting[:direction] == 'asc' ? 'desc' : 'asc'}"
45
- psrc = File.join(@table_options[:image_path_prefix], @table_options[@sorting[:direction] == 'desc' ?
46
- :sort_down_button : :sort_up_button])
45
+ psrc = @table_options[@sorting[:direction] == 'desc' ?
46
+ :sort_down_button : :sort_up_button]
47
47
  make_tag(:input, :type => :hidden,
48
48
  :name => "#{sortparam}[#{name}][#{@sorting[:direction]}]",
49
49
  :value => "#{@sorting[:direction]}")
50
50
  else
51
51
  pname = "#{sortparam}[_resort][#{name}][desc]"
52
52
  bid = "#{bid}_#{name}_desc"
53
- psrc = File.join(@table_options[:image_path_prefix], @table_options[:sort_down_button_inactive])
53
+ psrc = @table_options[:sort_down_button_inactive]
54
54
  end
55
- make_tag(:input, :type => 'image',
56
- :id => bid,
57
- :src => psrc,
58
- :name => pname)
55
+ make_image_button(psrc, :id => bid, :name => pname)
59
56
  end
60
57
  end # </th>
61
58
  end
@@ -35,17 +35,11 @@ class Tabulatr
35
35
  # render the 'wrapping' div
36
36
  make_tag(:div, :class => @table_options[:paginator_div_class]) do
37
37
  # << Page Left
38
- if page > 1
39
- make_tag(:input, :type => 'image',
40
- :src => File.join(@table_options[:image_path_prefix], @table_options[:pager_left_button]),
41
- :class => @table_options[:page_left_class],
42
- :id => "#{pagination_name}_page_left",
43
- :name => "#{pagination_name}[page_left]")
44
- else
45
- make_tag(:img,
46
- :src => File.join(@table_options[:image_path_prefix], @table_options[:pager_left_button_inactive]),
47
- :class => @table_options[:page_left_class])
48
- end # page > 1
38
+ make_image_button(@table_options[page > 1 ? :pager_left_button : :pager_left_button_inactive],
39
+ :class => @table_options[:page_left_class],
40
+ :id => "#{pagination_name}_page_left",
41
+ :name => "#{pagination_name}[page_left]",
42
+ :inactive => (page <= 1))
49
43
  # current page number
50
44
  concat(make_tag(:input,
51
45
  :type => :hidden,
@@ -58,16 +52,11 @@ class Tabulatr
58
52
  :value => page))
59
53
  concat("/#{pages}")
60
54
  # >> Page Right
61
- if page < pages
62
- make_tag(:input, :type => 'image',
63
- :src => File.join(@table_options[:image_path_prefix], @table_options[:pager_right_button]),
64
- :class => @table_options[:page_right_class],
65
- :id => "#{pagination_name}_page_right",
66
- :name => "#{pagination_name}[page_right]")
67
- else
68
- make_tag(:img, :src => File.join(@table_options[:image_path_prefix], @table_options[:pager_right_button_inactive]),
69
- :class => @table_options[:page_right_class])
70
- end # page < pages
55
+ make_image_button(@table_options[page < pages ? :pager_right_button : :pager_right_button_inactive],
56
+ :class => @table_options[:page_right_class],
57
+ :id => "#{pagination_name}_page_right",
58
+ :name => "#{pagination_name}[page_right]",
59
+ :inactive => (page >= pages))
71
60
  if pagesizes.length > 1
72
61
  make_tag(:select, :name => "#{pagination_name}[pagesize]", :class => @table_options[:pagesize_select_class]) do
73
62
  pagesizes.each do |n|
@@ -75,7 +75,7 @@ class Tabulatr
75
75
  :select_controls => [:select_all, :select_none, :select_visible, :unselect_visible,
76
76
  :select_filtered, :unselect_filtered],
77
77
 
78
- :image_path_prefix => '/images/tabulatr/',
78
+ :image_path_prefix => (Rails::version.to_f >= 3.1 ? 'tabulatr/' : '/images/tabulatr/'),
79
79
  :pager_left_button => 'pager_arrow_left.gif',
80
80
  :pager_left_button_inactive => 'pager_arrow_left_off.gif',
81
81
  :pager_right_button => 'pager_arrow_right.gif',
@@ -1,3 +1,3 @@
1
1
  class Tabulatr
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/tabulatr.gemspec CHANGED
@@ -15,14 +15,10 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = []
19
- s.require_paths = ["lib"]
20
18
  s.rdoc_options = ['--charset=UTF-8']
21
19
 
22
20
 
23
- s.add_runtime_dependency('rails', '~> 3.0')
21
+ s.add_runtime_dependency('rails', '>= 3.0.0')
24
22
  s.add_dependency('whiny_hash', '>= 0.0.2')
25
23
  s.add_dependency('id_stuffer', '>= 0.0.1')
26
-
27
- s.rubyforge_project = "tabulatr"
28
24
  end
metadata CHANGED
@@ -1,76 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: tabulatr
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 0
9
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Peter Horn
13
- - "Ren\xC3\xA9 Sprotte"
9
+ - René Sprotte
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2011-05-26 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2011-08-20 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70348423259000 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 3
31
- - 0
32
- version: "3.0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
33
23
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: whiny_hash
37
24
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70348423259000
26
+ - !ruby/object:Gem::Dependency
27
+ name: whiny_hash
28
+ requirement: &70348423258260 !ruby/object:Gem::Requirement
39
29
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 0
46
- - 2
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
47
33
  version: 0.0.2
48
34
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: id_stuffer
52
35
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *70348423258260
37
+ - !ruby/object:Gem::Dependency
38
+ name: id_stuffer
39
+ requirement: &70348423257540 !ruby/object:Gem::Requirement
54
40
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- - 0
61
- - 1
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
62
44
  version: 0.0.1
63
45
  type: :runtime
64
- version_requirements: *id003
65
- description: A tight DSL to build tables of ActiveRecord or Mongoid models with sorting, pagination, finding/filtering, selecting and batch actions. Tries to do for tables what formtastic and simple_form did for forms.
46
+ prerelease: false
47
+ version_requirements: *70348423257540
48
+ description: A tight DSL to build tables of ActiveRecord or Mongoid models with sorting,
49
+ pagination, finding/filtering, selecting and batch actions. Tries to do for tables
50
+ what formtastic and simple_form did for forms.
66
51
  email: info@provideal.net
67
52
  executables: []
68
-
69
53
  extensions: []
70
-
71
54
  extra_rdoc_files: []
72
-
73
- files:
55
+ files:
74
56
  - .gitignore
75
57
  - .rspec
76
58
  - Changelog.textile
@@ -78,6 +60,17 @@ files:
78
60
  - LICENSE
79
61
  - README.textile
80
62
  - Rakefile
63
+ - app/assets/images/tabulatr/buttons_lite_background.png
64
+ - app/assets/images/tabulatr/pager_arrow_left.gif
65
+ - app/assets/images/tabulatr/pager_arrow_left_off.gif
66
+ - app/assets/images/tabulatr/pager_arrow_right.gif
67
+ - app/assets/images/tabulatr/pager_arrow_right_off.gif
68
+ - app/assets/images/tabulatr/sort_arrow_down.gif
69
+ - app/assets/images/tabulatr/sort_arrow_down_off.gif
70
+ - app/assets/images/tabulatr/sort_arrow_up.gif
71
+ - app/assets/images/tabulatr/sort_arrow_up_off.gif
72
+ - app/assets/stylesheets/tabulatr.css
73
+ - app/assets/stylesheets/tabulatr/application.scss
81
74
  - assets/images/buttons_lite_background.png
82
75
  - assets/images/pager_arrow_left.gif
83
76
  - assets/images/pager_arrow_left_off.gif
@@ -97,6 +90,7 @@ files:
97
90
  - lib/initializers/mark_as_localizable.rb
98
91
  - lib/initializers/mongoid.rb
99
92
  - lib/tabulatr.rb
93
+ - lib/tabulatr/engine.rb
100
94
  - lib/tabulatr/tabulatr.rb
101
95
  - lib/tabulatr/tabulatr/batch_actions.rb
102
96
  - lib/tabulatr/tabulatr/check_controls.rb
@@ -185,39 +179,33 @@ files:
185
179
  - spec/requests/tabulatrs_spec.rb
186
180
  - spec/spec_helper.rb
187
181
  - tabulatr.gemspec
188
- has_rdoc: true
189
182
  homepage: http://github.com/provideal/tabulatr
190
183
  licenses: []
191
-
192
184
  post_install_message:
193
- rdoc_options:
185
+ rdoc_options:
194
186
  - --charset=UTF-8
195
- require_paths:
187
+ require_paths:
196
188
  - lib
197
- required_ruby_version: !ruby/object:Gem::Requirement
189
+ required_ruby_version: !ruby/object:Gem::Requirement
198
190
  none: false
199
- requirements:
200
- - - ">="
201
- - !ruby/object:Gem::Version
202
- segments:
203
- - 0
204
- version: "0"
205
- required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ! '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
196
  none: false
207
- requirements:
208
- - - ">="
209
- - !ruby/object:Gem::Version
210
- segments:
211
- - 0
212
- version: "0"
197
+ requirements:
198
+ - - ! '>='
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
213
201
  requirements: []
214
-
215
- rubyforge_project: tabulatr
216
- rubygems_version: 1.3.7
202
+ rubyforge_project:
203
+ rubygems_version: 1.8.6
217
204
  signing_key:
218
205
  specification_version: 3
219
- summary: A tight DSL to build tables of ActiveRecord or Mongoid models with sorting, pagination, finding/filtering, selecting and batch actions.
220
- test_files:
206
+ summary: A tight DSL to build tables of ActiveRecord or Mongoid models with sorting,
207
+ pagination, finding/filtering, selecting and batch actions.
208
+ test_files:
221
209
  - spec/dummy_app/.gitignore
222
210
  - spec/dummy_app/app/controllers/application_controller.rb
223
211
  - spec/dummy_app/app/controllers/products_controller.rb