tabulatr 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tabulatr (0.0.3)
4
+ tabulatr (0.0.4)
5
5
  id_stuffer (>= 0.0.1)
6
6
  rails (~> 3.0)
7
7
  whiny_hash (>= 0.0.2)
data/README.textile CHANGED
@@ -149,9 +149,9 @@ If you want to use a predefined stylesheet and the images for sorting and paging
149
149
  create public/images/tabulatr/sort_arrow_up.gif
150
150
  create public/images/tabulatr/sort_arrow_up_off.gif
151
151
  -------------------------------------------------------
152
- Please note: We have copied a sample stylesheet to
152
+ Please note: We have copied a sample stylesheet to
153
153
  public/stylesheets/tabulatr.css
154
- to actually use it in your application, please include
154
+ to actually use it in your application, please include
155
155
  it in your layout file. You may use s/th like
156
156
  <%= stylesheet_link_tag :tabulatr %>
157
157
  for that.
@@ -260,6 +260,7 @@ h3. Column Options
260
260
  format: false, # a sprintf-string or a proc to do special formatting
261
261
  method: false, # if you want to get the column by a different method than its name
262
262
  link: false, # proc or symbol to make the content a link
263
+ map: true, # whether to map the call on individual records (true) of an association or call on the list (false)
263
264
  join_symbol: ', ', # symbol used to join the elements of 'many' associations
264
265
  sortable: true # if set, sorting-stuff is added to the header cell
265
266
  </pre>
@@ -79,16 +79,24 @@ class Tabulatr
79
79
  end
80
80
  assoc = @record.class.reflect_on_association(relation)
81
81
  make_tag(:td, opts[:td_html]) do
82
- concat(if assoc.collection?
83
- @record.send relation
82
+ format = opts[:format]
83
+ concat(if assoc.collection? and opts[:map]
84
+ @record.send(relation.to_sym).map do |r|
85
+ val = h(r.send(opts[:method] || name))
86
+ if format.is_a?(Proc) then format.call(val)
87
+ elsif format.is_a?(String) then h(format % val)
88
+ elsif format.is_a?(Symbol) then Tabulatr::Formattr.format(format, val)
89
+ else h(val.to_s)
90
+ end
91
+ end.join(opts[:join_symbol])
84
92
  else
85
- [ @record.send(relation.to_sym) ]
86
- end.map do |r|
87
- val = h(r.send(opts[:method] || name))
88
- val = opts[:format].call(val) if opts[:format].class == Proc
89
- val = (opts[:format] % val) if opts[:format].class == String
90
- val
91
- end.join(opts[:join_symbol]))
93
+ val = h(@record.send(relation.to_sym).send(opts[:method] || name))
94
+ val = if format.is_a?(Proc) then format.call(val)
95
+ elsif format.is_a?(String) then h(format % val)
96
+ elsif format.is_a?(Symbol) then Tabulatr::Formattr.format(format, val)
97
+ else h(val.to_s)
98
+ end
99
+ end)
92
100
  end # </td>
93
101
  end
94
102
 
@@ -73,7 +73,7 @@ class Tabulatr
73
73
  :select_controls => [:select_all, :select_none, :select_visible, :unselect_visible,
74
74
  :select_filtered, :unselect_filtered],
75
75
 
76
- :image_path_prefix => '/images/tabulatr/',
76
+ :image_path_prefix => '/images/tabulatr/',
77
77
  :pager_left_button => 'pager_arrow_left.gif',
78
78
  :pager_left_button_inactive => 'pager_arrow_left_off.gif',
79
79
  :pager_right_button => 'pager_arrow_right.gif',
@@ -147,6 +147,7 @@ class Tabulatr
147
147
  :method => false, # if you want to get the column by a different method than its name
148
148
  :link => false, # proc or symbol to make the content a link
149
149
  :join_symbol => ', ', # symbol used to join the elements of 'many' associations
150
+ :map => true, # whether to map the call on individual records (true) or call on the list (false)
150
151
  :sortable => true # if set, sorting-stuff is added to the header cell
151
152
  })
152
153
 
@@ -1,3 +1,3 @@
1
1
  class Tabulatr
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -5,6 +5,7 @@
5
5
  t.column :active
6
6
  t.association :vendor, :name
7
7
  t.association :tags, :title
8
+ t.association :tags, :count, :map => false, :format => '--%d--'
8
9
  end %>
9
10
 
10
11
 
@@ -16,7 +16,7 @@ describe "Tabulatrs" do
16
16
  # General stuf
17
17
  WORKS_IN_GENERAL = CONTAINS_BUTTONS = CONTAINS_COLUMN_HEADERS = CONTAINS_OTHER_CONTROLS = tralse
18
18
  # This fills in the data, so rather not cmment this out
19
- CONTAINS_ACTUAL_DATA = CONTAINS_ACTUAL_DATA_MULTIPLE = CONTAINS_DATA_ON_FURTHER_PAGES = true
19
+ CONTAINS_ACTUAL_DATA = CONTAINS_ASSOC_DATA = CONTAINS_ACTUAL_DATA_MULTIPLE = CONTAINS_DATA_ON_FURTHER_PAGES = true
20
20
  # Paginatione
21
21
  PAGES_UP_AND_DOWN = JUMPS_TO_CORRECT_PAGE = CHANGES_PAGE_SIZE = tralse
22
22
  # Filters
@@ -49,7 +49,7 @@ describe "Tabulatrs" do
49
49
 
50
50
  it "contains column headers" do
51
51
  visit index_simple_products_path
52
- ['Id','Title','Price','Active','Vendor Name','Tags Title'].each do |n|
52
+ ['Id','Title','Price','Active','Vendor Name','Tags Title','Tags Count'].each do |n|
53
53
  page.should have_content(n)
54
54
  end
55
55
  end if CONTAINS_COLUMN_HEADERS
@@ -66,9 +66,20 @@ describe "Tabulatrs" do
66
66
  page.should have_content("true")
67
67
  page.should have_content("10.0")
68
68
  page.should have_content("ven d'or")
69
+ page.should have_content("--0--")
69
70
  page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 1, 1, 0, 1))
70
71
  end if CONTAINS_ACTUAL_DATA
71
72
 
73
+ it "correctly contains the association data" do
74
+ product = Product.first
75
+ [tag1, tag2, tag3].each_with_index do |tag, i|
76
+ product.tags << tag
77
+ visit index_simple_products_path
78
+ page.should have_content tag.title
79
+ page.should have_content(sprintf("--%d--", i+1))
80
+ end
81
+ end if CONTAINS_ASSOC_DATA
82
+
72
83
  it "contains the actual data multiple" do
73
84
  9.times do |i|
74
85
  product = Product.create!(:title => names[i+1], :active => i.even?, :price => 11.0+i,
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulatr
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 4
9
- version: 0.0.4
4
+ prerelease:
5
+ version: 0.0.5
10
6
  platform: ruby
11
7
  authors:
12
8
  - Peter Horn
@@ -15,7 +11,7 @@ autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
13
 
18
- date: 2011-03-26 23:00:00 +01:00
14
+ date: 2011-03-28 00:00:00 +02:00
19
15
  default_executable:
20
16
  dependencies:
21
17
  - !ruby/object:Gem::Dependency
@@ -26,9 +22,6 @@ dependencies:
26
22
  requirements:
27
23
  - - ~>
28
24
  - !ruby/object:Gem::Version
29
- segments:
30
- - 3
31
- - 0
32
25
  version: "3.0"
33
26
  type: :runtime
34
27
  version_requirements: *id001
@@ -40,10 +33,6 @@ dependencies:
40
33
  requirements:
41
34
  - - ">="
42
35
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 0
46
- - 2
47
36
  version: 0.0.2
48
37
  type: :runtime
49
38
  version_requirements: *id002
@@ -55,10 +44,6 @@ dependencies:
55
44
  requirements:
56
45
  - - ">="
57
46
  - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- - 0
61
- - 1
62
47
  version: 0.0.1
63
48
  type: :runtime
64
49
  version_requirements: *id003
@@ -198,21 +183,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
183
  requirements:
199
184
  - - ">="
200
185
  - !ruby/object:Gem::Version
201
- segments:
202
- - 0
203
186
  version: "0"
204
187
  required_rubygems_version: !ruby/object:Gem::Requirement
205
188
  none: false
206
189
  requirements:
207
190
  - - ">="
208
191
  - !ruby/object:Gem::Version
209
- segments:
210
- - 0
211
192
  version: "0"
212
193
  requirements: []
213
194
 
214
195
  rubyforge_project: tabulatr
215
- rubygems_version: 1.3.7
196
+ rubygems_version: 1.5.0
216
197
  signing_key:
217
198
  specification_version: 3
218
199
  summary: Tabulatr is a DSL to easily create tables for e.g. admin backends.