tabletastic 0.2.0.pre → 0.2.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -1
- data/README.rdoc +57 -0
- data/init.rb +2 -0
- data/lib/tabletastic/helper.rb +36 -0
- data/lib/tabletastic/version.rb +1 -1
- data/lib/tabletastic.rb +4 -23
- data/spec/spec_helper.rb +4 -3
- data/spec/tabletastic_spec.rb +24 -0
- metadata +8 -6
data/CHANGELOG.rdoc
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
Git
|
1
|
+
Git (for upcoming v0.2.0 release)
|
2
|
+
|
2
3
|
* Updating to Rails3 API and idioms
|
4
|
+
* Adding default table html options
|
5
|
+
* Adding default lambda (table block) so that table_for can be called without passing a block
|
3
6
|
|
4
7
|
v0.1.3 (Dec 28, 2009)
|
8
|
+
|
5
9
|
* Changing destroy action to have confirmation by default
|
6
10
|
|
7
11
|
v0.1.2 (Nov 25, 2009)
|
data/README.rdoc
CHANGED
@@ -210,6 +210,63 @@ will product html like:
|
|
210
210
|
|
211
211
|
If it _still_ isn't flexible enough for your needs, it might be time to return to static html/erb.
|
212
212
|
|
213
|
+
== Default Options and Tabletastic initializer
|
214
|
+
|
215
|
+
As of version 0.2.0, you can now setup some of your own defaults in an initializer file.
|
216
|
+
|
217
|
+
For example, create a file called tabletastic.rb in your config/initializers folder.
|
218
|
+
|
219
|
+
Within that file, there are several defaults that you can setup for yourself, including:
|
220
|
+
|
221
|
+
Tabletastic.default_table_html
|
222
|
+
Tabletastic.default_table_block
|
223
|
+
|
224
|
+
Both of these options are setup up so that inline options will still override whatever they are set to,
|
225
|
+
but providing them here will save you some code if you commonly reuse options.
|
226
|
+
|
227
|
+
By default, +default_table_html+ is simple an empty hash <code>{}</code>. By providing your own defaults, you can ensure that all
|
228
|
+
of your tables have a specific html +class+ or +cellspacing+, or whatever.
|
229
|
+
|
230
|
+
If <code>Tabletastic.default_table_html</code> is set to <code>{:cellspacing => 0, :class => 'yowza'}</code>,
|
231
|
+
then all tabletastic tables will have this html by default, unless overridden:
|
232
|
+
|
233
|
+
table_for(@posts) do |t|
|
234
|
+
|
235
|
+
will produce:
|
236
|
+
|
237
|
+
<table class="yowza" cellspacing="0" id="posts">
|
238
|
+
|
239
|
+
Similarly, all of those calls to +table_for+ can get boring since you might be using the same block every time.
|
240
|
+
The option +default_table_block+ lets you set a default lambda so that you can omit the block with +table_for+.
|
241
|
+
Since by default +default_table_block+ is set to <code>lambda{|table| table.data}</code>, the following:
|
242
|
+
|
243
|
+
<%= table_for(@posts) %>
|
244
|
+
|
245
|
+
will be the same as
|
246
|
+
|
247
|
+
<%= table_for(@posts) do |t|
|
248
|
+
t.data
|
249
|
+
end %>
|
250
|
+
|
251
|
+
However, just like +default_table_html+, you can set a different block in the initializer file for your block to default to.
|
252
|
+
For example:
|
253
|
+
|
254
|
+
Tabletastic.default_table_block = lambda {|table| table.data :actions => :all }
|
255
|
+
|
256
|
+
will make the following equivalent:
|
257
|
+
|
258
|
+
<%= table_for(@posts) %>
|
259
|
+
|
260
|
+
<%= table_for(@posts) do |t|
|
261
|
+
t.data :actions => :all
|
262
|
+
end %>
|
263
|
+
|
264
|
+
And to omit those action links, you can just use +table_for+ the old-fashioned way:
|
265
|
+
|
266
|
+
<%= table_for(@posts) do |t|
|
267
|
+
t.data
|
268
|
+
end %>
|
269
|
+
|
213
270
|
== Note on Patches/Pull Requests
|
214
271
|
|
215
272
|
* Fork the project.
|
data/init.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Tabletastic
|
2
|
+
module Helper
|
3
|
+
# returns and outputs a table for the given active record collection
|
4
|
+
def table_for(collection, *args, &block)
|
5
|
+
block = Tabletastic.default_table_block unless block_given?
|
6
|
+
klass = default_class_for(collection)
|
7
|
+
options = args.extract_options!
|
8
|
+
initialize_html_options(options, klass)
|
9
|
+
result = block.call(TableBuilder.new(collection, klass, self))
|
10
|
+
|
11
|
+
content_tag(:table, result, options[:html])
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
# Finds the class representing the objects within the collection
|
16
|
+
def default_class_for(collection)
|
17
|
+
if collection.respond_to?(:proxy_reflection)
|
18
|
+
collection.proxy_reflection.klass
|
19
|
+
elsif !collection.empty?
|
20
|
+
collection.first.class
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize_html_options(options, klass)
|
25
|
+
options[:html] ||= {}
|
26
|
+
options[:html][:id] ||= get_id_for(klass)
|
27
|
+
options[:html].reverse_merge!(Tabletastic.default_table_html)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_id_for(klass)
|
31
|
+
klass ? klass.model_name.collection : ""
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ActionView::Base.send :include, Tabletastic::Helper
|
data/lib/tabletastic/version.rb
CHANGED
data/lib/tabletastic.rb
CHANGED
@@ -1,28 +1,9 @@
|
|
1
1
|
require 'tabletastic/table_builder'
|
2
|
+
require 'tabletastic/helper'
|
2
3
|
|
3
4
|
module Tabletastic
|
4
|
-
|
5
|
-
|
6
|
-
raise ArgumentError, "you must provide a block" unless block_given?
|
7
|
-
klass = default_class_for(collection)
|
8
|
-
options = args.extract_options!
|
9
|
-
options[:html] ||= {}
|
10
|
-
options[:html][:id] ||= get_id_for(klass)
|
11
|
-
result = block.call(TableBuilder.new(collection, klass, self))
|
12
|
-
content_tag(:table, result, options[:html])
|
13
|
-
end
|
5
|
+
@@default_table_html = {}
|
6
|
+
@@default_table_block = lambda {|table| table.data}
|
14
7
|
|
15
|
-
|
16
|
-
# Finds the class representing the objects within the collection
|
17
|
-
def default_class_for(collection)
|
18
|
-
if collection.respond_to?(:proxy_reflection)
|
19
|
-
collection.proxy_reflection.klass
|
20
|
-
elsif !collection.empty?
|
21
|
-
collection.first.class
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_id_for(klass)
|
26
|
-
klass ? klass.model_name.collection : ""
|
27
|
-
end
|
8
|
+
mattr_accessor :default_table_html, :default_table_block
|
28
9
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,9 +17,9 @@ smart_require 'rspec', '>= 1.3.0', 'spec'
|
|
17
17
|
require 'spec/autorun'
|
18
18
|
smart_require 'nokogiri'
|
19
19
|
smart_require 'rspec_tag_matchers', '>= 1.0.0'
|
20
|
-
smart_require 'activesupport', '>= 3.0.0.
|
21
|
-
smart_require 'actionpack', '>= 3.0.0.
|
22
|
-
smart_require 'activerecord', '>= 3.0.0.
|
20
|
+
smart_require 'activesupport', '>= 3.0.0.beta3', 'active_support'
|
21
|
+
smart_require 'actionpack', '>= 3.0.0.beta3', 'action_pack'
|
22
|
+
smart_require 'activerecord', '>= 3.0.0.beta3', 'active_record'
|
23
23
|
require 'action_controller'
|
24
24
|
require 'action_view/base'
|
25
25
|
require 'action_view/template'
|
@@ -113,3 +113,4 @@ end
|
|
113
113
|
|
114
114
|
include TabletasticSpecHelper
|
115
115
|
include Tabletastic
|
116
|
+
include Tabletastic::Helper
|
data/spec/tabletastic_spec.rb
CHANGED
@@ -23,4 +23,28 @@ describe "Tabletastic#table_for" do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
describe "default options" do
|
28
|
+
before do
|
29
|
+
Tabletastic.default_table_html = {:class => 'default', :cellspacing => 0}
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should allow default table html to be set" do
|
33
|
+
concat(table_for([]){})
|
34
|
+
output_buffer.should have_tag("table.default")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "can be overridden with inline options" do
|
38
|
+
concat(table_for([], :html => {:class => 'newclass'}){})
|
39
|
+
output_buffer.should have_tag("table.newclass")
|
40
|
+
output_buffer.should_not have_tag("table.default")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "without a block" do
|
45
|
+
it "should use default block" do
|
46
|
+
concat table_for([])
|
47
|
+
output_buffer.should have_tag("table")
|
48
|
+
end
|
49
|
+
end
|
26
50
|
end
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.2.0.
|
9
|
+
- pre2
|
10
|
+
version: 0.2.0.pre2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joshua Davey
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-04-
|
18
|
+
date: 2010-04-18 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: "0"
|
31
31
|
type: :development
|
32
32
|
version_requirements: *id001
|
33
|
-
description: A table builder for active record collections
|
33
|
+
description: A table builder for active record collections that produces semantically rich and accessible table markup
|
34
34
|
email: josh@joshuadavey.com
|
35
35
|
executables: []
|
36
36
|
|
@@ -40,6 +40,7 @@ extra_rdoc_files:
|
|
40
40
|
- README.rdoc
|
41
41
|
- LICENSE
|
42
42
|
files:
|
43
|
+
- lib/tabletastic/helper.rb
|
43
44
|
- lib/tabletastic/table_builder.rb
|
44
45
|
- lib/tabletastic/table_field.rb
|
45
46
|
- lib/tabletastic/version.rb
|
@@ -47,6 +48,7 @@ files:
|
|
47
48
|
- LICENSE
|
48
49
|
- README.rdoc
|
49
50
|
- CHANGELOG.rdoc
|
51
|
+
- init.rb
|
50
52
|
has_rdoc: true
|
51
53
|
homepage: http://github.com/jgdavey/tabletastic
|
52
54
|
licenses: []
|
@@ -70,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
72
|
segments:
|
71
73
|
- 1
|
72
74
|
- 3
|
73
|
-
-
|
74
|
-
version: 1.3.
|
75
|
+
- 6
|
76
|
+
version: 1.3.6
|
75
77
|
requirements: []
|
76
78
|
|
77
79
|
rubyforge_project:
|