tableasy 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -4,7 +4,7 @@ end
4
4
 
5
5
  formatter(:linked_to) do |subject, column|
6
6
  object = subject.send(column)
7
- link_to object, object
7
+ object ? link_to(object, object) : ''
8
8
  end
9
9
 
10
10
  formatter(:tail_link, :no_header => true) do |subject, text, *args|
@@ -19,19 +19,17 @@ formatter(:tail_link, :no_header => true) do |subject, text, *args|
19
19
  end
20
20
  end
21
21
 
22
- #def edit_link(*url)
23
- # options = url.extract_options!
24
- # options.merge!(:method => 'get') if options[:ajax]
25
- # url.unshift(:edit).push(options)
26
- # tail_link "Edit", *url
27
- #end
28
- #
29
- #def destroy_link(*url)
30
- # options = url.extract_options!
31
- # options.reverse_merge!(:confirm => 'Are you sure?', :method => 'delete')
32
- # url.push(options)
33
- # tail_link "Delete", *url
34
- #end
22
+ formatter(:edit_link) do |subject, text, options|
23
+ options ||= {}
24
+ options[:method] = 'get' if options[:ajax]
25
+ tail_link(text, :edit, options).execute(subject)
26
+ end
27
+
28
+ formatter(:destroy_link) do |subject, text, options|
29
+ options ||= {}
30
+ options.reverse_merge!(:confirm => 'Are you sure?', :method => 'delete')
31
+ tail_link(text, options).execute(subject)
32
+ end
35
33
 
36
34
  formatter(:with_percent) do |subject, column, total_column|
37
35
  number, total = subject.send(column).to_i, subject.send(total_column).to_i
@@ -3,7 +3,7 @@ module Tableasy
3
3
  def table_for(klass, list, *columns)
4
4
  options = columns.extract_options!
5
5
 
6
- content_tag('table') do
6
+ content_tag('table', options[:html]) do
7
7
  content = ''
8
8
  content << content_tag('tr') do
9
9
  columns.select {|column| column.to_sym }.collect do |column|
@@ -18,6 +18,14 @@ describe 'Formatters' do
18
18
  formatter.execute(@project).should == '<a href="/people/Andrius">Andrius</a>'
19
19
  end
20
20
 
21
+ it "should show nothing when linked object doesn't exist" do
22
+ build :project
23
+ @project.leader = nil
24
+ formatter = helper.linked_to(:leader)
25
+ formatter.to_sym.should == :leader
26
+ formatter.execute(@project).should == ''
27
+ end
28
+
21
29
  it "should show number with percent" do
22
30
  @andrius.stubs(:work_hours).returns(100, 100, 13, nil)
23
31
  @andrius.stubs(:remaining).returns(8, -8, 8, nil)
@@ -61,5 +69,20 @@ describe 'Formatters' do
61
69
  formatter = helper.tail_link('hello', :edit, :ajax => true)
62
70
  formatter.execute(@andrius).should == helper.link_to_remote('hello', :url => [:edit, @andrius])
63
71
  end
72
+
73
+ it "should allow creating edit url" do
74
+ formatter = helper.edit_link('Edit')
75
+ formatter.execute(@andrius).should == helper.link_to('Edit', [:edit, @andrius])
76
+ end
77
+
78
+ it "should allow creating ajax edit url" do
79
+ formatter = helper.edit_link('Edit', :ajax => true)
80
+ formatter.execute(@andrius).should == helper.link_to_remote('Edit', :url => [:edit, @andrius], :method => :get)
81
+ end
82
+
83
+ it "should allow creating delete link" do
84
+ formatter = helper.destroy_link('Delete')
85
+ formatter.execute(@andrius).should == helper.link_to('Delete', @andrius, :method => :delete, :confirm => 'Are you sure?')
86
+ end
64
87
  end
65
88
  end
@@ -84,4 +84,10 @@ describe Tableasy::TablesHelper do
84
84
 
85
85
  output.should == "<table><tr></tr><tr class=\"person odd\" id=\"row_person_1\"><td><a href=\"/people/Andrius\">show</a></td></tr></table>"
86
86
  end
87
+
88
+ it "should allow passing custom html options to table" do
89
+ build :project
90
+ output = helper.table_for(Project, [@project], :name, :html => {:id => 'my_table'})
91
+ output.should == "<table id=\"my_table\"><tr><th>Name</th></tr><tr class=\"project odd\" id=\"row_project_1\"><td>project</td></tr></table>"
92
+ end
87
93
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tableasy}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
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-02-23}
12
+ s.date = %q{2010-02-24}
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.1.1
4
+ version: 0.1.2
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-02-23 00:00:00 +02:00
12
+ date: 2010-02-24 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency