tableasy 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -30,6 +30,10 @@ formatter(:destroy_link, :no_initial => true, :no_header => true) do |cell, text
30
30
  tail_link(text, options).execute(cell)
31
31
  end
32
32
 
33
+ formatter(:joined_array) do |cell|
34
+ cell.value = cell.value.join("<br />")
35
+ end
36
+
33
37
  formatter(:with_percent) do |cell, total_column|
34
38
  number, total = cell.value.to_i, cell.subject.send(total_column).to_i
35
39
  percent = total == 0 ? 0 : number.to_f / total * 100
@@ -15,8 +15,8 @@ module Tableasy
15
15
  end
16
16
  end
17
17
 
18
- def execute(record)
19
- @context.instance_exec(record, *@args, &@formatter.block)
18
+ def execute(cell)
19
+ @context.instance_exec(cell, *@args, &@formatter.block)
20
20
  end
21
21
 
22
22
  def to_sym
@@ -28,7 +28,7 @@ module Tableasy
28
28
 
29
29
  def initialize(&block)
30
30
  @block = block
31
- @format_header = Proc.new {|header| header }
31
+ @format_header = Proc.new {|header| header.to_sym }
32
32
  end
33
33
 
34
34
  def format_header(header = nil, &block)
@@ -13,7 +13,7 @@ module Tableasy
13
13
 
14
14
  def value=(value)
15
15
  if value.is_a?(Tableasy::Formatter::Column)
16
- @value = @subject.send(value.column) if value.column
16
+ self.value = value.column if value.column
17
17
  value.execute(self)
18
18
  else
19
19
  value = @subject.send(value) if value.is_a?(Symbol)
@@ -44,6 +44,29 @@ describe 'Formatters' do
44
44
  Tableasy::Table::Cell.new(nil, formatter).value.should == 123
45
45
  end
46
46
 
47
+ it "should allow joining array" do
48
+ @andrius = mock(:ages => (20..23).to_a)
49
+ formatter = helper.joined_array(:ages, 100..130)
50
+ formatter.to_sym.should == :ages
51
+ Tableasy::Table::Cell.new(@andrius, formatter).value.should == "20<br />21<br />22<br />23"
52
+ end
53
+
54
+ it "should allow chaining formatters" do
55
+ build :andrius
56
+ helper.expects(:rand).with(30).returns(17)
57
+ formatter = helper.linked(helper.random(:name, 100..130))
58
+ formatter.to_sym.should == :name
59
+ Tableasy::Table::Cell.new(@andrius, formatter).value.should == '<a href="/people/Andrius">117</a>'
60
+ end
61
+
62
+ it "should allow chaining two formatters, that both require initial value" do
63
+ build :andrius
64
+ @andrius.expects(:ages => (20..23).to_a)
65
+ formatter = helper.linked(helper.joined_array(:ages))
66
+ formatter.to_sym.should == :ages
67
+ Tableasy::Table::Cell.new(@andrius, formatter).value.should == '<a href="/people/Andrius">20<br />21<br />22<br />23</a>'
68
+ end
69
+
47
70
  describe 'tail_link' do
48
71
  before do
49
72
  build :andrius
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tableasy}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrius Chamentauskas"]
12
- s.date = %q{2010-03-04}
12
+ s.date = %q{2010-03-20}
13
13
  s.description = %q{Rails tables builder gem that makes creating tables painless. Includes ability to write custom column formatters or even customize row completely.
14
14
  Includes library of predefined column formatters. Also has ability to generate "totals" row.}
15
15
  s.email = %q{sinsiliux@gmail.com}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tableasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrius Chamentauskas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-04 00:00:00 +02:00
12
+ date: 2010-03-20 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency