tabulatr2 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +71 -27
  4. data/app/assets/javascripts/tabulatr/application.js +130 -133
  5. data/app/assets/stylesheets/tabulatr/application.css.scss +153 -0
  6. data/app/assets/stylesheets/tabulatr/bootstrap2_fixes.css.scss +24 -0
  7. data/app/views/tabulatr/_tabulatr_actual_table.html.slim +35 -0
  8. data/app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim +34 -0
  9. data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +84 -0
  10. data/app/views/tabulatr/_tabulatr_filter_menu.html.slim +30 -0
  11. data/app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim +24 -0
  12. data/app/views/tabulatr/_tabulatr_info_string.html.slim +23 -0
  13. data/app/views/tabulatr/_tabulatr_paginator.html.slim +24 -0
  14. data/app/views/tabulatr/_tabulatr_static_table.html.slim +33 -0
  15. data/app/views/tabulatr/_tabulatr_table.html.slim +45 -0
  16. data/lib/tabulatr/data/column_name_builder.rb +86 -0
  17. data/lib/tabulatr/data/data.rb +135 -0
  18. data/lib/tabulatr/data/dsl.rb +61 -0
  19. data/lib/tabulatr/data/filtering.rb +101 -0
  20. data/lib/tabulatr/data/formatting.rb +65 -0
  21. data/lib/tabulatr/data/invoker.rb +37 -0
  22. data/lib/tabulatr/data/pagination.rb +48 -0
  23. data/lib/tabulatr/data/proxy.rb +41 -0
  24. data/lib/tabulatr/{tabulatr/batch_actions.rb → data/sorting.rb} +20 -23
  25. data/lib/tabulatr/engine.rb +24 -1
  26. data/lib/tabulatr/generators/railtie.rb +33 -0
  27. data/lib/tabulatr/generators/resource_override.rb +35 -0
  28. data/lib/{generators → tabulatr/generators}/tabulatr/install_generator.rb +21 -3
  29. data/lib/{generators → tabulatr/generators}/tabulatr/templates/tabulatr.yml +3 -1
  30. data/lib/tabulatr/generators/tabulatr/templates/tabulatr_data.rb +18 -0
  31. data/lib/tabulatr/json_builder.rb +94 -0
  32. data/lib/tabulatr/rails/action_controller.rb +36 -0
  33. data/lib/{initializers → tabulatr/rails}/action_view.rb +6 -3
  34. data/lib/{initializers → tabulatr/rails}/active_record.rb +11 -19
  35. data/lib/tabulatr/renderer/action.rb +32 -0
  36. data/lib/tabulatr/{tabulatr/formattr.rb → renderer/association.rb} +19 -30
  37. data/lib/tabulatr/renderer/checkbox.rb +36 -0
  38. data/lib/tabulatr/renderer/column.rb +113 -0
  39. data/lib/{initializers/mark_as_localizable.rb → tabulatr/renderer/columns.rb} +13 -15
  40. data/lib/tabulatr/renderer/columns_from_block.rb +56 -0
  41. data/lib/tabulatr/renderer/renderer.rb +96 -0
  42. data/lib/tabulatr/utility/utility.rb +46 -0
  43. data/lib/tabulatr/version.rb +25 -2
  44. data/lib/tabulatr.rb +45 -4
  45. data/lib/tabulatr2.rb +1 -0
  46. data/spec/dummy/app/assets/stylesheets/application.css.scss +2 -2
  47. data/spec/dummy/app/controllers/products_controller.rb +27 -3
  48. data/spec/dummy/app/models/vendor.rb +1 -0
  49. data/spec/dummy/app/tabulatr_data/product_tabulatr_data.rb +29 -0
  50. data/spec/dummy/app/views/products/implicit_columns.html.erb +1 -0
  51. data/spec/dummy/app/views/products/one_item_per_page.html.erb +1 -1
  52. data/spec/dummy/app/views/products/simple_index.html.erb +6 -4
  53. data/spec/dummy/app/views/products/stupid_array.html.erb +1 -1
  54. data/spec/dummy/app/views/products/with_batch_actions.html.erb +10 -0
  55. data/spec/dummy/config/locales/tabulatr.yml +22 -1
  56. data/spec/dummy/config/routes.rb +3 -1
  57. data/spec/features/tabulatrs_spec.rb +53 -11
  58. data/tabulatr.gemspec +1 -1
  59. metadata +50 -42
  60. data/app/assets/images/tabulatr/buttons_lite_background.png +0 -0
  61. data/app/assets/images/tabulatr/pager_arrow_left.gif +0 -0
  62. data/app/assets/images/tabulatr/pager_arrow_left_off.gif +0 -0
  63. data/app/assets/images/tabulatr/pager_arrow_right.gif +0 -0
  64. data/app/assets/images/tabulatr/pager_arrow_right_off.gif +0 -0
  65. data/app/assets/images/tabulatr/sort_arrow_down.gif +0 -0
  66. data/app/assets/images/tabulatr/sort_arrow_down_off.gif +0 -0
  67. data/app/assets/images/tabulatr/sort_arrow_up.gif +0 -0
  68. data/app/assets/images/tabulatr/sort_arrow_up_off.gif +0 -0
  69. data/app/assets/stylesheets/tabulatr/application.css +0 -40
  70. data/lib/initializers/action_controller.rb +0 -13
  71. data/lib/tabulatr/tabulatr/adapter/active_record.rb +0 -84
  72. data/lib/tabulatr/tabulatr/adapter.rb +0 -55
  73. data/lib/tabulatr/tabulatr/data_cell.rb +0 -132
  74. data/lib/tabulatr/tabulatr/dummy_record.rb +0 -40
  75. data/lib/tabulatr/tabulatr/empty_cell.rb +0 -44
  76. data/lib/tabulatr/tabulatr/filter_cell.rb +0 -145
  77. data/lib/tabulatr/tabulatr/filter_icon.rb +0 -6
  78. data/lib/tabulatr/tabulatr/finder/find_for_table.rb +0 -187
  79. data/lib/tabulatr/tabulatr/finder.rb +0 -64
  80. data/lib/tabulatr/tabulatr/header_cell.rb +0 -146
  81. data/lib/tabulatr/tabulatr/json_builder.rb +0 -57
  82. data/lib/tabulatr/tabulatr/paginator.rb +0 -76
  83. data/lib/tabulatr/tabulatr/row_builder.rb +0 -128
  84. data/lib/tabulatr/tabulatr/security.rb +0 -21
  85. data/lib/tabulatr/tabulatr/settings.rb +0 -158
  86. data/lib/tabulatr/tabulatr.rb +0 -343
  87. data/spec/lib/tabulatr/tabulatr/finder/find_for_table_spec.rb +0 -187
  88. /data/lib/{generators → tabulatr/generators}/tabulatr/templates/tabulatr.rb +0 -0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulatr2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Horn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-23 00:00:00.000000000 Z
13
+ date: 2013-10-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -27,19 +27,19 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: 4.0.0
29
29
  - !ruby/object:Gem::Dependency
30
- name: whiny_hash
30
+ name: slim
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - '>='
34
34
  - !ruby/object:Gem::Version
35
- version: 0.0.2
35
+ version: 2.0.1
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - '>='
41
41
  - !ruby/object:Gem::Version
42
- version: 0.0.2
42
+ version: 2.0.1
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: activerecord_outer_joins
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -70,49 +70,53 @@ files:
70
70
  - LICENSE
71
71
  - README.md
72
72
  - Rakefile
73
- - app/assets/images/tabulatr/buttons_lite_background.png
74
- - app/assets/images/tabulatr/pager_arrow_left.gif
75
- - app/assets/images/tabulatr/pager_arrow_left_off.gif
76
- - app/assets/images/tabulatr/pager_arrow_right.gif
77
- - app/assets/images/tabulatr/pager_arrow_right_off.gif
78
- - app/assets/images/tabulatr/sort_arrow_down.gif
79
- - app/assets/images/tabulatr/sort_arrow_down_off.gif
80
- - app/assets/images/tabulatr/sort_arrow_up.gif
81
- - app/assets/images/tabulatr/sort_arrow_up_off.gif
82
73
  - app/assets/javascripts/tabulatr.js
83
74
  - app/assets/javascripts/tabulatr/application.js
84
75
  - app/assets/javascripts/tabulatr/jquery.inview.min.js
85
76
  - app/assets/stylesheets/tabulatr.css
86
- - app/assets/stylesheets/tabulatr/application.css
77
+ - app/assets/stylesheets/tabulatr/application.css.scss
78
+ - app/assets/stylesheets/tabulatr/bootstrap2_fixes.css.scss
79
+ - app/views/tabulatr/_tabulatr_actual_table.html.slim
80
+ - app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim
81
+ - app/views/tabulatr/_tabulatr_filter_dialog.html.slim
82
+ - app/views/tabulatr/_tabulatr_filter_menu.html.slim
83
+ - app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim
84
+ - app/views/tabulatr/_tabulatr_info_string.html.slim
85
+ - app/views/tabulatr/_tabulatr_paginator.html.slim
86
+ - app/views/tabulatr/_tabulatr_static_table.html.slim
87
+ - app/views/tabulatr/_tabulatr_table.html.slim
87
88
  - init.rb
88
- - lib/generators/tabulatr/install_generator.rb
89
- - lib/generators/tabulatr/templates/tabulatr.rb
90
- - lib/generators/tabulatr/templates/tabulatr.yml
91
- - lib/initializers/action_controller.rb
92
- - lib/initializers/action_view.rb
93
- - lib/initializers/active_record.rb
94
- - lib/initializers/mark_as_localizable.rb
95
89
  - lib/tabulatr.rb
90
+ - lib/tabulatr/data/column_name_builder.rb
91
+ - lib/tabulatr/data/data.rb
92
+ - lib/tabulatr/data/dsl.rb
93
+ - lib/tabulatr/data/filtering.rb
94
+ - lib/tabulatr/data/formatting.rb
95
+ - lib/tabulatr/data/invoker.rb
96
+ - lib/tabulatr/data/pagination.rb
97
+ - lib/tabulatr/data/proxy.rb
98
+ - lib/tabulatr/data/sorting.rb
96
99
  - lib/tabulatr/engine.rb
97
- - lib/tabulatr/tabulatr.rb
98
- - lib/tabulatr/tabulatr/adapter.rb
99
- - lib/tabulatr/tabulatr/adapter/active_record.rb
100
- - lib/tabulatr/tabulatr/batch_actions.rb
101
- - lib/tabulatr/tabulatr/data_cell.rb
102
- - lib/tabulatr/tabulatr/dummy_record.rb
103
- - lib/tabulatr/tabulatr/empty_cell.rb
104
- - lib/tabulatr/tabulatr/filter_cell.rb
105
- - lib/tabulatr/tabulatr/filter_icon.rb
106
- - lib/tabulatr/tabulatr/finder.rb
107
- - lib/tabulatr/tabulatr/finder/find_for_table.rb
108
- - lib/tabulatr/tabulatr/formattr.rb
109
- - lib/tabulatr/tabulatr/header_cell.rb
110
- - lib/tabulatr/tabulatr/json_builder.rb
111
- - lib/tabulatr/tabulatr/paginator.rb
112
- - lib/tabulatr/tabulatr/row_builder.rb
113
- - lib/tabulatr/tabulatr/security.rb
114
- - lib/tabulatr/tabulatr/settings.rb
100
+ - lib/tabulatr/generators/railtie.rb
101
+ - lib/tabulatr/generators/resource_override.rb
102
+ - lib/tabulatr/generators/tabulatr/install_generator.rb
103
+ - lib/tabulatr/generators/tabulatr/templates/tabulatr.rb
104
+ - lib/tabulatr/generators/tabulatr/templates/tabulatr.yml
105
+ - lib/tabulatr/generators/tabulatr/templates/tabulatr_data.rb
106
+ - lib/tabulatr/json_builder.rb
107
+ - lib/tabulatr/rails/action_controller.rb
108
+ - lib/tabulatr/rails/action_view.rb
109
+ - lib/tabulatr/rails/active_record.rb
110
+ - lib/tabulatr/renderer/action.rb
111
+ - lib/tabulatr/renderer/association.rb
112
+ - lib/tabulatr/renderer/checkbox.rb
113
+ - lib/tabulatr/renderer/column.rb
114
+ - lib/tabulatr/renderer/columns.rb
115
+ - lib/tabulatr/renderer/columns_from_block.rb
116
+ - lib/tabulatr/renderer/renderer.rb
117
+ - lib/tabulatr/utility/utility.rb
115
118
  - lib/tabulatr/version.rb
119
+ - lib/tabulatr2.rb
116
120
  - spec/dummy/.gitignore
117
121
  - spec/dummy/README.rdoc
118
122
  - spec/dummy/Rakefile
@@ -131,11 +135,14 @@ files:
131
135
  - spec/dummy/app/models/product.rb
132
136
  - spec/dummy/app/models/tag.rb
133
137
  - spec/dummy/app/models/vendor.rb
138
+ - spec/dummy/app/tabulatr_data/product_tabulatr_data.rb
134
139
  - spec/dummy/app/views/layouts/application.html.erb
135
140
  - spec/dummy/app/views/products/count_tags.html.erb
141
+ - spec/dummy/app/views/products/implicit_columns.html.erb
136
142
  - spec/dummy/app/views/products/one_item_per_page.html.erb
137
143
  - spec/dummy/app/views/products/simple_index.html.erb
138
144
  - spec/dummy/app/views/products/stupid_array.html.erb
145
+ - spec/dummy/app/views/products/with_batch_actions.html.erb
139
146
  - spec/dummy/bin/bundle
140
147
  - spec/dummy/bin/rails
141
148
  - spec/dummy/bin/rake
@@ -169,7 +176,6 @@ files:
169
176
  - spec/dummy/public/500.html
170
177
  - spec/dummy/public/favicon.ico
171
178
  - spec/features/tabulatrs_spec.rb
172
- - spec/lib/tabulatr/tabulatr/finder/find_for_table_spec.rb
173
179
  - spec/spec_helper.rb
174
180
  - tabulatr.gemspec
175
181
  homepage: http://github.com/provideal/tabulatr2
@@ -216,11 +222,14 @@ test_files:
216
222
  - spec/dummy/app/models/product.rb
217
223
  - spec/dummy/app/models/tag.rb
218
224
  - spec/dummy/app/models/vendor.rb
225
+ - spec/dummy/app/tabulatr_data/product_tabulatr_data.rb
219
226
  - spec/dummy/app/views/layouts/application.html.erb
220
227
  - spec/dummy/app/views/products/count_tags.html.erb
228
+ - spec/dummy/app/views/products/implicit_columns.html.erb
221
229
  - spec/dummy/app/views/products/one_item_per_page.html.erb
222
230
  - spec/dummy/app/views/products/simple_index.html.erb
223
231
  - spec/dummy/app/views/products/stupid_array.html.erb
232
+ - spec/dummy/app/views/products/with_batch_actions.html.erb
224
233
  - spec/dummy/bin/bundle
225
234
  - spec/dummy/bin/rails
226
235
  - spec/dummy/bin/rake
@@ -254,5 +263,4 @@ test_files:
254
263
  - spec/dummy/public/500.html
255
264
  - spec/dummy/public/favicon.ico
256
265
  - spec/features/tabulatrs_spec.rb
257
- - spec/lib/tabulatr/tabulatr/finder/find_for_table_spec.rb
258
266
  - spec/spec_helper.rb
@@ -1,40 +0,0 @@
1
- .tabulatr-sort{
2
- opacity: 0.3;
3
- }
4
-
5
- .tabulatr-sort:hover{
6
- cursor: pointer;
7
- }
8
-
9
- i.sorted{
10
- opacity: 1;
11
- }
12
-
13
- i.tabulatr_remove_filter:hover{
14
- cursor: pointer;
15
- }
16
-
17
- .tabulatr_filtered_column{
18
- text-decoration: underline;
19
- }
20
-
21
- .tabulatr-per-page {
22
- margin: 20px 10px;
23
- a.active{
24
- background-color: red;
25
- }
26
- }
27
-
28
- .table-controls div{
29
- margin: 20px 10px;
30
- display: inline-block;
31
- vertical-align: middle;
32
- }
33
-
34
- .table-controls i, .tabulatr_table i{
35
- margin-right: 5px;
36
- }
37
-
38
- #tabulatr-wrench{
39
- margin-left: 10px;
40
- }
@@ -1,13 +0,0 @@
1
- class ActionController::Base
2
- def tabulatr_for(klaz, serializer: nil, **options, &block)
3
- respond_to do |format|
4
- format.json {
5
- records = klaz.find_for_table(params, options, &block)
6
- render json: records.to_tabulatr_json(serializer)
7
- }
8
- format.html {
9
- render action: options[:action] || action_name
10
- }
11
- end
12
- end
13
- end
@@ -1,84 +0,0 @@
1
- class Tabulatr::Adapter::ActiveRecordAdapter < Tabulatr::Adapter
2
-
3
- def initialize(klaz)
4
- set_like_statement unless Tabulatr::SQL_OPTIONS[:like]
5
-
6
- super klaz
7
- end
8
-
9
- def primary_key
10
- @relation.primary_key.to_sym
11
- end
12
-
13
- def key_type
14
- @relation.columns_hash[primary_key.to_s].type
15
- end
16
-
17
- def selected_ids(opts)
18
- preconditions_scope(opts).select(:id)
19
- end
20
-
21
- def table_name
22
- @relation.table_name
23
- end
24
-
25
- def table_name_for_association(assoc)
26
- @base.reflect_on_association(assoc).table_name
27
- end
28
-
29
- def order_for_query(sortparam, default)
30
- context = order(sortparam, default)
31
- "#{context[:by]} #{context[:direction]}" if context
32
- end
33
-
34
- def order_for_query_new(sort_by, orientation)
35
- "#{sort_by} #{orientation}"
36
- end
37
-
38
- def includes(inc)
39
- @relation.includes(inc)
40
- end
41
-
42
- def outer_joins(*args)
43
- @relation.outer_joins(*args)
44
- end
45
-
46
- def select(s)
47
- @relation.select(s)
48
- end
49
-
50
- def includes!(inc)
51
- @relation = includes(includes)
52
- end
53
-
54
- def add_conditions_from(n,v)
55
- like ||= Tabulatr.sql_options[:like]
56
- if v.is_a?(String)
57
- @relation = @relation.where("#{n} = ?", v) unless v.blank?
58
- elsif v.is_a?(Hash)
59
- if v[:like].present?
60
- @relation = @relation.where("#{n} #{like} ?", "%#{v[:like]}%")
61
- else
62
- @relation = @relation.where("#{n} >= ?", "#{v[:from]}") if v[:from].present?
63
- @relation = @relation.where("#{n} <= ?", "#{v[:to]}") if v[:to].present?
64
- end
65
- else
66
- raise "Wrong filter type: #{v.class}"
67
- end
68
- end
69
-
70
- private
71
- def set_like_statement
72
- case ActiveRecord::Base.connection.class.to_s
73
- when "ActiveRecord::ConnectionAdapters::MysqlAdapter" then Tabulatr.sql_options(:like => 'LIKE')
74
- when "ActiveRecord::ConnectionAdapters::Mysql2Adapter" then Tabulatr.sql_options(:like => 'LIKE')
75
- when "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter" then Tabulatr.sql_options(:like => 'ILIKE')
76
- when "ActiveRecord::ConnectionAdapters::SQLiteAdapter" then Tabulatr.sql_options(:like => 'LIKE')
77
- when "ActiveRecord::ConnectionAdapters::SQLite3Adapter" then Tabulatr.sql_options(:like => 'LIKE')
78
- else
79
- warn("Tabulatr Warning: Don't know which LIKE operator to use for the ConnectionAdapter '#{ActiveRecord::Base.connection.class}'.\n" +
80
- "Please specify by `Tabulatr.sql_options(:like => '<likeoperator>')`")
81
- Tabulatr.sql_options(:like => 'LIKE')
82
- end
83
- end
84
- end
@@ -1,55 +0,0 @@
1
- class Tabulatr::Adapter
2
- def initialize(klaz)
3
- @base = klaz
4
- @relation = klaz
5
- end
6
-
7
- delegate :all, :dup, :count, :limit, :to => :@relation
8
-
9
- def to_sql
10
- @relation.to_sql if @relation.respond_to? :to_sql
11
- end
12
-
13
- def class_to_param
14
- @relation.to_s.downcase.gsub("/","_")
15
- end
16
-
17
- def preconditions_scope(opts)
18
- opts[:precondition].present? ? @base.where(opts[:precondition]) : @base
19
- end
20
-
21
- def order(sortparam, default)
22
- order_by, order_direction = sort_params(sortparam, default)
23
- order_by ? { :by => order_by, :direction => order_direction } : nil
24
- end
25
-
26
- def sort_params(sortparam, default)
27
- if sortparam
28
- if sortparam[:_resort]
29
- order_by = sortparam[:_resort].first.first
30
- order_direction = sortparam[:_resort].first.last.first.first
31
- else
32
- order_by = sortparam.first.first
33
- order_direction = sortparam.first.last.first.first
34
- end
35
- raise "SECURITY violation, sort field name is '#{n}'" unless /^[\w]+$/.match order_direction
36
- raise "SECURITY violation, sort field name is '#{n}'" unless /^[\d\w]+$/.match order_by
37
- else
38
- if default
39
- l = default.split(" ")
40
- raise(":default_order parameter should be of the form 'id asc' or 'name desc'.") if l.length == 0 or l.length > 2
41
-
42
- order_by = l[0]
43
- order_direction = l[1] || 'asc'
44
- else
45
- order_by = order_direction = nil
46
- end
47
- end
48
-
49
- return order_by, order_direction
50
- end
51
- end
52
-
53
- Dir[File.join(File.dirname(__FILE__), "adapter", "*.rb")].each do |file|
54
- require file
55
- end
@@ -1,132 +0,0 @@
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 Tabulatr
25
-
26
- # the method used to actually define the data cells of the columns,
27
- # taking the name of the attribute and a hash of options.
28
- #
29
- # The following options are evaluated here:
30
- # <tt>:td_html</tt>:: a hash with html-attributes added to the <ts>s created
31
- # <tt>:method</tt>:: the actual method invoked on the record to retrieve the
32
- # value for the column, or false if name is to be used.
33
- # <tt>:fromat</tt>:: either a String by which the value is <tt>sprinf</tt>ed,
34
- # a proc/lambda to which the value is passed or false if
35
- # no specific formatting is desired.
36
- def data_column(name, opts={}, &block)
37
- raise "Not in data mode!" if @row_mode != :data
38
- opts = normalize_column_options(name, opts)
39
- make_tag(:td, opts[:td_html]) do
40
- href = if opts[:link].class == Symbol || opts[:link].class == String
41
- @view.send(opts[:link], @record)
42
- elsif opts[:link].respond_to?(:call)
43
- opts[:link].call(@record)
44
- else
45
- nil
46
- end
47
- make_tag((href ? :a : nil), :href => href) do
48
- if block_given?
49
- concat(@view.instance_exec(@record, &block))
50
- else
51
- val = @record.send(opts[:method] || name)
52
- format = opts[:format]
53
- concat(
54
- if format.is_a?(Proc) then @view.instance_exec(val, &format)
55
- elsif format.is_a?(String) then h(format % val)
56
- elsif format.is_a?(Symbol) then @view.send(format, val)
57
- else h(val.to_s)
58
- end)
59
- end # block_given?
60
- end # </a>
61
- end # </td>
62
- end
63
-
64
- # the method used to actually define the data cells of the columns,
65
- # taking the name of the attribute and a hash of options.
66
- #
67
- # The following options are evaluated here:
68
- # <tt>:td_html</tt>:: a hash with html-attributes added to the <ts>s created
69
- # <tt>:method</tt>:: the actual method invoked on the record to retrieve the
70
- # value for the column, or false if name is to be used.
71
- # <tt>:format</tt>:: either a String by which the value is <tt>sprinf</tt>ed,
72
- # a proc/lambda to which the value is passed or false if
73
- # no specific formatting is desired.
74
- def data_association(relation, name, opts={}, &block)
75
- raise "Not in data mode!" if @row_mode != :data
76
- opts = normalize_column_options(name, opts)
77
- if block_given?
78
- return @view.instance_exec(@record, &block)
79
- end
80
- assoc = @record.class.reflect_on_association(relation)
81
- make_tag(:td, opts[:td_html]) do
82
- format = opts[:format]
83
- ass = @record.send(relation.to_sym)
84
- if opts[:sort_by]
85
- # TODO: SORTING specified by opts[:sort_by]
86
- end
87
- concat(if (ass.is_a?(Array) || ass.respond_to?(:to_ary)) && (opts[:map] != false)
88
- ass.map do |r|
89
- val = h(r.send(opts[:method] || name))
90
- if format.is_a?(Proc) then format.call(val)
91
- elsif format.is_a?(String) then h(format % val)
92
- elsif format.is_a?(Symbol) then @view.send(format, val)
93
- else h(val.to_s)
94
- end
95
- end.join(opts[:join_symbol] || ', ')
96
- else
97
- return '' unless ass
98
- #puts ass.to_s
99
- val = h(ass.send(opts[:method] || name))
100
- val = if format.is_a?(Proc) then @view.instance_exec(val, &format)
101
- elsif format.is_a?(String) then h(format % val)
102
- elsif format.is_a?(Symbol) then @view.send(format, val)
103
- else h(val.to_s)
104
- end
105
- end)
106
- end # </td>
107
- end
108
-
109
- def data_checkbox(opts={}, &block)
110
- raise "Whatever that's for!" if block_given?
111
- iname = "#{@classname}#{@table_form_options[:checked_postfix]}[current_page][]"
112
- make_tag(:td, opts[:td_html]) do
113
- checked = @checked[:selected].member?(@record.send(@id)) ? :checked : nil
114
- make_tag(:input, :type => 'checkbox', :name => iname,
115
- :id => "#{@classname}#{@table_form_options[:checked_postfix]}_#{@record.send(@id).to_s}",
116
- :value => @record.send(@id), :checked => checked)
117
- end
118
- end
119
-
120
- def data_action(opts={}, &block)
121
- raise "Not in data mode!" if @row_mode != :data
122
- opts = normalize_column_options(:action_column, opts)
123
- make_tag(:td, opts[:td_html]) do
124
- if block_given?
125
- concat(yield(@record))
126
- else
127
- raise "Always give a block ino action columns"
128
- end # block_given?
129
- end # </td>
130
- end
131
-
132
- end
@@ -1,40 +0,0 @@
1
- class Tabulatr::DummyRecord
2
-
3
- def self.for(klaz)
4
- c = Class.new(self)
5
- c.instance_variable_set("@model_name", klaz.model_name)
6
- c.new
7
- end
8
-
9
- def to_s
10
- @methods ||= []
11
- if @methods.any?
12
- m = @methods.join(':')
13
- @method_names ||= []
14
- @method_names << m
15
- @methods.clear
16
- "{{#{m}}}"
17
- else
18
- "{{id}}"
19
- end
20
- end
21
-
22
- def method_missing(sym, *args)
23
- @methods ||= []
24
- @methods << sym.to_s
25
- self
26
- end
27
-
28
- def to_key
29
- ["{{id}}"]
30
- end
31
-
32
- def requested_methods
33
- Array(@method_names).try(:uniq)
34
- end
35
-
36
- def self.model_name
37
- @model_name
38
- end
39
-
40
- end
@@ -1,44 +0,0 @@
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 Tabulatr
25
-
26
- # the method used to actually define the filters of the columns,
27
- # taking the name of the attribute and a hash of options.
28
- #
29
- # The following options are evaluated here:
30
- # <tt>:filter_html</tt>:: a hash with html-attributes added to the <ts>s created
31
- # <tt>:filter</tt>:: may take different values:
32
- # <tt>false</tt>:: no filter is output for this column
33
- # a container:: the keys of the hash are used to define a <tt>select</tt>
34
- # where the values are the <tt>value</tt> of the <tt>options</tt>.
35
- # an Array:: the elements of that array are used to define a
36
- # <tt>select</tt>
37
- # a String:: a <tt>select</tt> is created with that String as options
38
- # you can use ActionView#collection_select and the like
39
- def empty_column(name, opts={}, &block)
40
- raise "Not in empty mode!" if @row_mode != :empty
41
- opts = normalize_column_options(name, opts)
42
- make_tag(:td, opts[:filter_html])
43
- end
44
- end