table_cloth 0.2.3 → 0.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/generators/templates/table.rb +7 -0
- data/lib/table_cloth.rb +14 -15
- data/lib/table_cloth/base.rb +3 -26
- data/lib/table_cloth/column.rb +0 -12
- data/lib/table_cloth/{action.rb → column_jury.rb} +10 -6
- data/lib/table_cloth/configurable_elements.rb +6 -13
- data/lib/table_cloth/extensions/actions.rb +25 -0
- data/lib/table_cloth/extensions/actions/action.rb +21 -0
- data/lib/table_cloth/extensions/actions/action_collection.rb +11 -0
- data/lib/table_cloth/extensions/actions/column.rb +21 -0
- data/lib/table_cloth/extensions/actions/jury.rb +37 -0
- data/lib/table_cloth/presenter.rb +16 -5
- data/lib/table_cloth/presenters/default.rb +1 -1
- data/lib/table_cloth/version.rb +1 -1
- data/spec/factories/actions.rb +6 -0
- data/spec/factories/columns.rb +18 -0
- data/spec/factories/dummy_tables.rb +11 -0
- data/spec/lib/base_spec.rb +6 -22
- data/spec/lib/column_jury_spec.rb +35 -0
- data/spec/lib/column_spec.rb +9 -14
- data/spec/lib/extensions/actions/action_collection_spec.rb +29 -0
- data/spec/lib/extensions/actions/action_spec.rb +57 -0
- data/spec/lib/extensions/actions/column_spec.rb +23 -0
- data/spec/lib/extensions/actions/jury_spec.rb +67 -0
- data/spec/lib/extensions/actions_spec.rb +42 -0
- data/spec/lib/presenter_spec.rb +29 -31
- data/spec/lib/presenters/default_spec.rb +61 -124
- data/spec/spec_helper.rb +7 -0
- data/spec/support/dummy_table.rb +0 -4
- data/spec/support/dummy_table_with_value_options.rb +1 -1
- data/spec/support/matchers/element_matchers.rb +6 -0
- data/table_cloth.gemspec +2 -0
- metadata +63 -14
- data/lib/table_cloth/actions.rb +0 -23
- data/lib/table_cloth/columns/action.rb +0 -24
- data/spec/lib/actions_spec.rb +0 -28
- data/spec/lib/columns/action_spec.rb +0 -73
- data/spec/support/dummy_table_with_actions.rb +0 -7
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,13 @@ require 'awesome_print'
|
|
3
3
|
require 'nokogiri'
|
4
4
|
require 'factory_girl'
|
5
5
|
require 'pry'
|
6
|
+
require 'simplecov'
|
7
|
+
|
8
|
+
if ENV["COVERAGE"] == "true"
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter "spec/support"
|
11
|
+
end
|
12
|
+
end
|
6
13
|
|
7
14
|
Dir['./spec/support/**/*.rb'].each {|f| require f }
|
8
15
|
|
data/spec/support/dummy_table.rb
CHANGED
data/table_cloth.gemspec
CHANGED
@@ -18,12 +18,14 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
gem.add_development_dependency('rspec', '~> 2.11')
|
21
|
+
gem.add_development_dependency('simplecov')
|
21
22
|
gem.add_development_dependency('awesome_print')
|
22
23
|
gem.add_development_dependency('nokogiri')
|
23
24
|
gem.add_development_dependency('pry')
|
24
25
|
gem.add_development_dependency('factory_girl')
|
25
26
|
gem.add_development_dependency('guard-rspec')
|
26
27
|
gem.add_development_dependency('rake')
|
28
|
+
gem.add_development_dependency('rb-fsevent', '~> 0.9.1')
|
27
29
|
|
28
30
|
gem.add_dependency('actionpack', '~> 3.2')
|
29
31
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_cloth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0.beta1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Robert Ross
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '2.11'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: simplecov
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: awesome_print
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,6 +139,22 @@ dependencies:
|
|
123
139
|
- - ! '>='
|
124
140
|
- !ruby/object:Gem::Version
|
125
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: rb-fsevent
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 0.9.1
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 0.9.1
|
126
158
|
- !ruby/object:Gem::Dependency
|
127
159
|
name: actionpack
|
128
160
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,33 +189,43 @@ files:
|
|
157
189
|
- lib/generators/table_generator.rb
|
158
190
|
- lib/generators/templates/table.rb
|
159
191
|
- lib/table_cloth.rb
|
160
|
-
- lib/table_cloth/action.rb
|
161
192
|
- lib/table_cloth/action_view_extension.rb
|
162
|
-
- lib/table_cloth/actions.rb
|
163
193
|
- lib/table_cloth/base.rb
|
164
194
|
- lib/table_cloth/builder.rb
|
165
195
|
- lib/table_cloth/column.rb
|
166
|
-
- lib/table_cloth/
|
196
|
+
- lib/table_cloth/column_jury.rb
|
167
197
|
- lib/table_cloth/configurable_elements.rb
|
168
198
|
- lib/table_cloth/configuration.rb
|
199
|
+
- lib/table_cloth/extensions/actions.rb
|
200
|
+
- lib/table_cloth/extensions/actions/action.rb
|
201
|
+
- lib/table_cloth/extensions/actions/action_collection.rb
|
202
|
+
- lib/table_cloth/extensions/actions/column.rb
|
203
|
+
- lib/table_cloth/extensions/actions/jury.rb
|
169
204
|
- lib/table_cloth/presenter.rb
|
170
205
|
- lib/table_cloth/presenters/default.rb
|
171
206
|
- lib/table_cloth/version.rb
|
207
|
+
- spec/factories/actions.rb
|
208
|
+
- spec/factories/columns.rb
|
172
209
|
- spec/factories/dummy_models.rb
|
210
|
+
- spec/factories/dummy_tables.rb
|
173
211
|
- spec/lib/action_view_extension_spec.rb
|
174
|
-
- spec/lib/actions_spec.rb
|
175
212
|
- spec/lib/base_spec.rb
|
176
213
|
- spec/lib/builder_spec.rb
|
214
|
+
- spec/lib/column_jury_spec.rb
|
177
215
|
- spec/lib/column_spec.rb
|
178
|
-
- spec/lib/columns/action_spec.rb
|
179
216
|
- spec/lib/configuration_spec.rb
|
217
|
+
- spec/lib/extensions/actions/action_collection_spec.rb
|
218
|
+
- spec/lib/extensions/actions/action_spec.rb
|
219
|
+
- spec/lib/extensions/actions/column_spec.rb
|
220
|
+
- spec/lib/extensions/actions/jury_spec.rb
|
221
|
+
- spec/lib/extensions/actions_spec.rb
|
180
222
|
- spec/lib/presenter_spec.rb
|
181
223
|
- spec/lib/presenters/default_spec.rb
|
182
224
|
- spec/spec_helper.rb
|
183
225
|
- spec/support/dummy_model.rb
|
184
226
|
- spec/support/dummy_table.rb
|
185
|
-
- spec/support/dummy_table_with_actions.rb
|
186
227
|
- spec/support/dummy_table_with_value_options.rb
|
228
|
+
- spec/support/matchers/element_matchers.rb
|
187
229
|
- spec/support/shared_config_examples.rb
|
188
230
|
- spec/support/view_mocks.rb
|
189
231
|
- table_cloth.gemspec
|
@@ -202,9 +244,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
244
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
245
|
none: false
|
204
246
|
requirements:
|
205
|
-
- - ! '
|
247
|
+
- - ! '>'
|
206
248
|
- !ruby/object:Gem::Version
|
207
|
-
version:
|
249
|
+
version: 1.3.1
|
208
250
|
requirements: []
|
209
251
|
rubyforge_project:
|
210
252
|
rubygems_version: 1.8.23
|
@@ -213,20 +255,27 @@ specification_version: 3
|
|
213
255
|
summary: Table Cloth provides an easy and intuitive DSL for creating tables in rails
|
214
256
|
views.
|
215
257
|
test_files:
|
258
|
+
- spec/factories/actions.rb
|
259
|
+
- spec/factories/columns.rb
|
216
260
|
- spec/factories/dummy_models.rb
|
261
|
+
- spec/factories/dummy_tables.rb
|
217
262
|
- spec/lib/action_view_extension_spec.rb
|
218
|
-
- spec/lib/actions_spec.rb
|
219
263
|
- spec/lib/base_spec.rb
|
220
264
|
- spec/lib/builder_spec.rb
|
265
|
+
- spec/lib/column_jury_spec.rb
|
221
266
|
- spec/lib/column_spec.rb
|
222
|
-
- spec/lib/columns/action_spec.rb
|
223
267
|
- spec/lib/configuration_spec.rb
|
268
|
+
- spec/lib/extensions/actions/action_collection_spec.rb
|
269
|
+
- spec/lib/extensions/actions/action_spec.rb
|
270
|
+
- spec/lib/extensions/actions/column_spec.rb
|
271
|
+
- spec/lib/extensions/actions/jury_spec.rb
|
272
|
+
- spec/lib/extensions/actions_spec.rb
|
224
273
|
- spec/lib/presenter_spec.rb
|
225
274
|
- spec/lib/presenters/default_spec.rb
|
226
275
|
- spec/spec_helper.rb
|
227
276
|
- spec/support/dummy_model.rb
|
228
277
|
- spec/support/dummy_table.rb
|
229
|
-
- spec/support/dummy_table_with_actions.rb
|
230
278
|
- spec/support/dummy_table_with_value_options.rb
|
279
|
+
- spec/support/matchers/element_matchers.rb
|
231
280
|
- spec/support/shared_config_examples.rb
|
232
281
|
- spec/support/view_mocks.rb
|
data/lib/table_cloth/actions.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module TableCloth
|
2
|
-
class Actions
|
3
|
-
attr_reader :column, :options
|
4
|
-
|
5
|
-
def initialize(options={}, &block)
|
6
|
-
@options = options
|
7
|
-
@column = Columns::Action.new(:actions, options)
|
8
|
-
|
9
|
-
block.arity > 0 ? block.call(self) : instance_eval(&block)
|
10
|
-
end
|
11
|
-
|
12
|
-
def action(*args, &block)
|
13
|
-
options = args.extract_options! || {}
|
14
|
-
options[:proc] = block if block_given?
|
15
|
-
|
16
|
-
column.actions << Action.new(options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def all
|
20
|
-
column.actions
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module TableCloth
|
2
|
-
module Columns
|
3
|
-
class Action < Column
|
4
|
-
def value(object, view_context, table)
|
5
|
-
actions_html = actions.each_with_object('') do |action, links|
|
6
|
-
if action.available?(table)
|
7
|
-
links << "\n"
|
8
|
-
links << (view_context.instance_exec(object, view_context, &action.options[:proc]) || "")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
view_context.raw(actions_html)
|
13
|
-
end
|
14
|
-
|
15
|
-
def actions
|
16
|
-
@actions ||= []
|
17
|
-
end
|
18
|
-
|
19
|
-
def available?(table)
|
20
|
-
actions.any? {|a| a.available?(table) }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/spec/lib/actions_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe TableCloth::Actions do
|
4
|
-
subject { TableCloth::Actions }
|
5
|
-
|
6
|
-
context "block syntax" do
|
7
|
-
it "accepts a block" do
|
8
|
-
actions = subject.new do
|
9
|
-
action { 'Edit' }
|
10
|
-
end
|
11
|
-
|
12
|
-
expect(actions.column).to have(1).actions
|
13
|
-
end
|
14
|
-
|
15
|
-
it "accepts options with a block" do
|
16
|
-
actions = subject.new(class: "actions") do
|
17
|
-
action { "Edit" }
|
18
|
-
end
|
19
|
-
|
20
|
-
expect(actions.options[:class]).to eq("actions")
|
21
|
-
end
|
22
|
-
|
23
|
-
it ".all returns all actions for the column" do
|
24
|
-
actions = subject.new { action { "Edit" } }
|
25
|
-
expect(actions.all.length).to be 1
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe TableCloth::Columns::Action do
|
4
|
-
let(:view_context) { ActionView::Base.new }
|
5
|
-
let(:dummy_table) { Class.new(DummyTable) }
|
6
|
-
let(:dummy_model) do
|
7
|
-
DummyModel.new.tap do |d|
|
8
|
-
d.id = 1
|
9
|
-
d.email = 'robert@example.com'
|
10
|
-
d.name = 'robert'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { TableCloth::Columns::Action.new(object, view_context) }
|
15
|
-
|
16
|
-
it '.value returns all actions in HTML' do
|
17
|
-
dummy_table.actions do
|
18
|
-
action {|object, view| view.link_to "Edit", "#{object.id}"}
|
19
|
-
end
|
20
|
-
presenter = TableCloth::Presenters::Default.new([dummy_model], dummy_table, view_context)
|
21
|
-
doc = Nokogiri::HTML(presenter.render_table)
|
22
|
-
|
23
|
-
actions_column = doc.at_xpath('//tbody')
|
24
|
-
.at_xpath('.//tr')
|
25
|
-
.xpath('.//td')
|
26
|
-
.last
|
27
|
-
|
28
|
-
link = actions_column.at_xpath('.//a')
|
29
|
-
link.should be_present
|
30
|
-
link[:href].should == '1'
|
31
|
-
end
|
32
|
-
|
33
|
-
it '.value only returns actions that pass' do
|
34
|
-
dummy_table.actions do
|
35
|
-
action(if: :admin?) { '/admin' }
|
36
|
-
action(if: :moderator?) { '/moderator' }
|
37
|
-
end
|
38
|
-
|
39
|
-
table = dummy_table.new([], view_context)
|
40
|
-
|
41
|
-
def table.admin?
|
42
|
-
true
|
43
|
-
end
|
44
|
-
|
45
|
-
def table.moderator?
|
46
|
-
false
|
47
|
-
end
|
48
|
-
|
49
|
-
actions_column = dummy_table.columns[:actions]
|
50
|
-
actions_value = actions_column.value(dummy_model, view_context, table)
|
51
|
-
|
52
|
-
actions_value.should include '/admin'
|
53
|
-
actions_value.should_not include '/moderator'
|
54
|
-
end
|
55
|
-
|
56
|
-
it "does not need to use the view context of a block" do
|
57
|
-
dummy_table.actions do
|
58
|
-
action {|object| link_to "Edit", "#{object.id}" }
|
59
|
-
end
|
60
|
-
presenter = TableCloth::Presenters::Default.new([dummy_model], dummy_table, view_context)
|
61
|
-
|
62
|
-
doc = Nokogiri::HTML(presenter.render_table)
|
63
|
-
|
64
|
-
actions_column = doc.at_xpath('//tbody')
|
65
|
-
.at_xpath('.//tr')
|
66
|
-
.xpath('.//td')
|
67
|
-
.last
|
68
|
-
|
69
|
-
link = actions_column.at_xpath('.//a')
|
70
|
-
link.should be_present
|
71
|
-
link[:href].should == '1'
|
72
|
-
end
|
73
|
-
end
|