easy-table 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ require 'sugar-high/includes'
4
+ require 'easy-table/namespaces'
5
+
6
+ require 'easy-table/table'
7
+
8
+ describe EasyTable::ViewExt::Table::Base do
9
+ extend_view_with EasyTable::ViewExt, :table, :row, :cell, :tag
10
+
11
+ before :each do
12
+ @post = stub(:title => 'my post', :id => 1, :author => 'kristian' )
13
+ @post2 = stub(:title => 'my other post', :id => 2, :author => 'mike' )
14
+
15
+ @posts = [@post, @post2]
16
+ end
17
+
18
+ describe '#render_caption' do
19
+ it 'should display a table caption' do
20
+ with_engine(:erb) do |e|
21
+ res = e.run_template do %{
22
+ <%= render_caption 'my caption' %>
23
+ }
24
+ end
25
+ res.should match /<caption>my caption<\/caption>/
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#table_body' do
31
+ it 'should display a table body with rows' do
32
+ with_engine(:erb) do |e|
33
+ res = e.run_template_locals :posts => @posts do %{
34
+ <%= table_body posts do |post| %>
35
+ <%= data_row post, %w{id title} %>
36
+ <% end %>
37
+ }
38
+ end
39
+ res.should match /<tr>/
40
+ res.should match /<td>1<\/td>/
41
+ res.should match /<td>my post<\/td>/
42
+ # puts res
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#render_tbody' do
48
+ it 'should display a table body' do
49
+ with_engine(:erb) do |e|
50
+ res = e.run_template_locals :posts => @posts do %{
51
+ <%= render_tbody posts do |post| %>
52
+ <%= data_row post, %w{id title} %>
53
+ <% end %>
54
+ }
55
+ end
56
+ res.should match /<tbody>/
57
+ res.should match /<tr>/
58
+ res.should match /<td>1<\/td>/
59
+ res.should match /<td>my post<\/td>/
60
+ # puts res
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#render_table' do
66
+ it 'should display a table' do
67
+ with_engine(:erb) do |e|
68
+ res = e.run_template_locals :posts => @posts do %{
69
+ <%= render_table do %>
70
+ <%= render_tbody posts do |post| %>
71
+ <%= data_row post, %w{id title} %>
72
+ <% end %>
73
+ <% end %>
74
+ }
75
+ end
76
+ res.should match /<table>/
77
+ res.should match /<tbody>/
78
+ res.should match /<tr>/
79
+ res.should match /<td>1<\/td>/
80
+ res.should match /<td>my post<\/td>/
81
+ end
82
+ end
83
+
84
+ it 'should display a blank table' do
85
+ with_engine(:erb) do |e|
86
+ res = e.run_template_locals :posts => @posts do %{
87
+ <%= render_table do %>
88
+ hello
89
+ <% end %>
90
+ }
91
+ end
92
+ res.should match /<table>/
93
+ res.should match /hello/
94
+ puts res
95
+ end
96
+ end
97
+
98
+ it 'should display a table with attributes' do
99
+ with_engine(:erb) do |e|
100
+ res = e.run_template_locals :posts => @posts do %{
101
+ <%= render_table :class => 'tables#posts', :id => 'posts_table' do %>
102
+ <%= render_tbody posts do |post| %>
103
+ <%= data_row post, %w{id title} %>
104
+ <% end %>
105
+ <% end %>
106
+ }
107
+ end
108
+ res.should match /<table class="tables#posts" id="posts_table">/
109
+ res.should match /<tbody>/
110
+ res.should match /<tr>/
111
+ res.should match /<td>1<\/td>/
112
+ res.should match /<td>my post<\/td>/
113
+ # puts res
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ require 'sugar-high/includes'
4
+ require 'sugar-high/blank'
5
+
6
+ require 'easy-table/namespaces'
7
+
8
+ require 'easy-table/table'
9
+ require 'easy-table/row'
10
+
11
+ describe EasyTable::ViewExt::Table::Base do
12
+ extend_view_with EasyTable::ViewExt, :table, :row, :cell, :tag
13
+
14
+ before :each do
15
+ @post = stub(:title => 'my post', :id => 1, :author => 'kristian' )
16
+ @post2 = stub(:title => 'my other post', :id => 2, :author => 'mike' )
17
+
18
+ @posts = [@post, @post2]
19
+ end
20
+
21
+ describe '#data_table' do
22
+ it 'should display a data table' do
23
+ with_engine(:erb) do |e|
24
+ res = e.run_template_locals :posts => @posts do %{
25
+ <%= data_table posts, %w{Id Title}, :summary => 'many posts', :caption => 'posts table' %>
26
+ }
27
+ end
28
+ res.should match /<table summary="many posts">/
29
+ res.should match /<tr>/
30
+ res.should match /<td>1<\/td>/
31
+ res.should match /<td>my post<\/td>/
32
+ puts res
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ require 'sugar-high/includes'
4
+ require 'easy-table/namespaces'
5
+
6
+ require 'easy-table/table'
7
+ require 'easy-table/row'
8
+
9
+ describe EasyTable::ViewExt::Table::Base do
10
+ extend_view_with EasyTable::ViewExt, :table, :row, :cell, :tag
11
+
12
+ before :each do
13
+ @post = stub(:title => 'my post', :id => 1, :author => 'kristian' )
14
+ @post2 = stub(:title => 'my other post', :id => 2, :author => 'mike' )
15
+
16
+ @posts = [@post, @post2]
17
+ end
18
+
19
+ describe '#table' do
20
+ it 'should display a table' do
21
+ with_engine(:erb) do |e|
22
+ res = e.run_template_locals :posts => @posts do %{
23
+ <%= table posts, %w{id title} do |post| %>
24
+ <%= data_row post, %w{id title} %>
25
+ <% end %>
26
+ }
27
+ end
28
+ res.should match /<table>/
29
+ res.should match /<tr>/
30
+ res.should match /<td>1<\/td>/
31
+ res.should match /<td>my post<\/td>/
32
+ # puts res
33
+ end
34
+ end
35
+
36
+ it 'should display a blank table' do
37
+ with_engine(:erb) do |e|
38
+ res = e.run_template_locals :posts => @posts do %{
39
+ <%= table posts, %w{id title} do %>
40
+ hello
41
+ <% end %>
42
+ }
43
+ end
44
+ res.should match /<table>/
45
+ res.should match /hello/
46
+ # puts res
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'easy-table/namespaces'
3
+ require 'easy-table/tag'
4
+
5
+ describe EasyTable::ViewExt::Tag do
6
+ extend_view_with EasyTable::ViewExt::Tag
7
+
8
+ describe '#do_tag' do
9
+ it 'should display an tag with NO indent' do
10
+ with_engine(:erb) do |e|
11
+ res = e.run_template do %{
12
+ <%= do_tag :li, :class => 'mine' do %>
13
+ hello
14
+ <% end %>
15
+ }
16
+ end
17
+ res.should match(/mine/)
18
+ res.should match(/hello/)
19
+ end
20
+ end
21
+ end
22
+
23
+ describe '#indent_tag' do
24
+ it 'should display a 2*2 space indented tag' do
25
+ with_engine(:erb) do |e|
26
+ res = e.run_template do %{
27
+ <%= indent_tag 2,:li, :class => 'mine' do %>
28
+ hello
29
+ <% end %>
30
+ }
31
+ end
32
+ # should make 4 spaces after new line!
33
+ res.should match(/\n\s{4}<li/)
34
+ puts res
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+ require 'easy-table/namespaces'
3
+ require 'easy-table/util'
4
+
5
+ describe EasyTable::ViewExt::Util do
6
+ extend_view_with EasyTable::ViewExt::Util
7
+
8
+ describe '#cycle' do
9
+ it 'should cycle classes' do
10
+ with_engine(:erb) do |e|
11
+ res = e.run_template_locals :options => {:row_classes => %w{class1 class2}} do %{
12
+ <%= class_option :row_classes, options %>
13
+ <%= class_option :row_classes, options %>
14
+ }
15
+ end
16
+ res.should match(/class1/)
17
+ res.should match(/class2/)
18
+ end
19
+
20
+ end
21
+ end
22
+
23
+
24
+
25
+ describe '#cycle' do
26
+ it 'should cycle classes' do
27
+ with_engine(:erb) do |e|
28
+ res = e.run_template_locals :classes => ["abc", "def"] do %{
29
+ <%= cycle("abc", "def") %>
30
+ <%= cycle("abc", "def") %>
31
+ <%= cycle(*classes) %>
32
+ <%= cycle(*classes) %>
33
+ }
34
+ end
35
+ res.should match(/abc/)
36
+ res.should match(/def/)
37
+ # puts res
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#get_class' do
43
+ it 'should cycle classes' do
44
+ with_engine(:erb) do |e|
45
+ res = e.run_template do %{
46
+ <%= get_class("abc", "def") %>
47
+ <%= get_class("abc", "def") %>
48
+ }
49
+ end
50
+ res.should match(/abc/)
51
+ res.should match(/def/)
52
+ end
53
+ end
54
+
55
+ it 'should default to odd/even classes when no args' do
56
+ with_engine(:erb) do |e|
57
+ res = e.run_template do %{
58
+ <%= get_class %>
59
+ <%= get_class %>
60
+ }
61
+ end
62
+ res.should match(/odd/)
63
+ res.should match(/even/)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,8 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+ require 'rspec-action_view'
4
+ require 'easy-table'
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :mocha
8
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-table
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
+ platform: ruby
11
+ authors:
12
+ - Kristian Mandrup
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-26 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ - beta
33
+ - 19
34
+ version: 2.0.0.beta.19
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec-action_view
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ - 3
48
+ - 0
49
+ version: 0.3.0
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rails3_plugin_toolbox
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ - 3
63
+ - 4
64
+ version: 0.3.4
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: activesupport
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 3
77
+ - 0
78
+ - 0
79
+ - rc
80
+ version: 3.0.0.rc
81
+ type: :runtime
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: sugar-high
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ - 1
94
+ - 4
95
+ version: 0.1.4
96
+ type: :runtime
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ name: sugar-high
100
+ prerelease: false
101
+ requirement: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ - 1
109
+ - 4
110
+ version: 0.1.4
111
+ type: :runtime
112
+ version_requirements: *id006
113
+ description: Makes it easy to add tables to your views using a nice DSL similar to the form helpers
114
+ email: kmandrup@gmail.com
115
+ executables: []
116
+
117
+ extensions: []
118
+
119
+ extra_rdoc_files:
120
+ - LICENSE
121
+ - README.markdown
122
+ files:
123
+ - .document
124
+ - .gitignore
125
+ - .rspec
126
+ - LICENSE
127
+ - README.markdown
128
+ - Rakefile
129
+ - VERSION
130
+ - easy-table.gemspec
131
+ - lib/easy-table.rb
132
+ - lib/easy-table/cell.rb
133
+ - lib/easy-table/namespaces.rb
134
+ - lib/easy-table/rails_config.rb
135
+ - lib/easy-table/row.rb
136
+ - lib/easy-table/row/data.rb
137
+ - lib/easy-table/table.rb
138
+ - lib/easy-table/table/base.rb
139
+ - lib/easy-table/table/data_table.rb
140
+ - lib/easy-table/tag.rb
141
+ - lib/easy-table/util.rb
142
+ - lib/easy-table/view_extension.rb
143
+ - spec/easy-table/cell_spec.rb
144
+ - spec/easy-table/row/data_row_spec.rb
145
+ - spec/easy-table/row/row_spec.rb
146
+ - spec/easy-table/table/base_spec.rb
147
+ - spec/easy-table/table/data_table_spec.rb
148
+ - spec/easy-table/table/table_spec.rb
149
+ - spec/easy-table/tag_spec.rb
150
+ - spec/easy-table/util_spec.rb
151
+ - spec/spec_helper.rb
152
+ has_rdoc: true
153
+ homepage: http://github.com/kristianmandrup/easy-table
154
+ licenses: []
155
+
156
+ post_install_message:
157
+ rdoc_options:
158
+ - --charset=UTF-8
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ segments:
167
+ - 0
168
+ version: "0"
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ requirements: []
178
+
179
+ rubyforge_project:
180
+ rubygems_version: 1.3.7
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: Simple table helper DSL similar to the well known form helpers
184
+ test_files:
185
+ - spec/easy-table/cell_spec.rb
186
+ - spec/easy-table/row/data_row_spec.rb
187
+ - spec/easy-table/row/row_spec.rb
188
+ - spec/easy-table/table/base_spec.rb
189
+ - spec/easy-table/table/data_table_spec.rb
190
+ - spec/easy-table/table/table_spec.rb
191
+ - spec/easy-table/tag_spec.rb
192
+ - spec/easy-table/util_spec.rb
193
+ - spec/spec_helper.rb