tabletastic 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +18 -1
- data/lib/tabletastic/table_builder.rb +12 -4
- data/lib/tabletastic/table_field.rb +19 -3
- data/lib/tabletastic/version.rb +1 -1
- data/spec/tabletastic/table_field_spec.rb +36 -11
- metadata +10 -5
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -77,7 +77,7 @@ For more information about Rails 3 and Block helpers and the new conventions, ch
|
|
77
77
|
== Installation
|
78
78
|
|
79
79
|
In your Rails project, Gemfile:
|
80
|
-
gem "tabletastic"
|
80
|
+
gem "tabletastic"
|
81
81
|
|
82
82
|
Or, for if you're behind the times, as a plugin:
|
83
83
|
script/plugin install git://github.com/jgdavey/tabletastic.git
|
@@ -239,6 +239,23 @@ will product html like:
|
|
239
239
|
|
240
240
|
If it _still_ isn't flexible enough for your needs, it might be time to return to static html/erb.
|
241
241
|
|
242
|
+
== Internationalization (I18n)
|
243
|
+
|
244
|
+
Tabletastic has some i18n-features enabled by default.
|
245
|
+
|
246
|
+
Here is an example of locales:
|
247
|
+
|
248
|
+
en:
|
249
|
+
tabletastic:
|
250
|
+
actions:
|
251
|
+
show: "See"
|
252
|
+
edit: "Edit"
|
253
|
+
destroy: "Remove"
|
254
|
+
confirmation: "Are you sure?"
|
255
|
+
models:
|
256
|
+
comment:
|
257
|
+
title: "Title"
|
258
|
+
|
242
259
|
== Default Options and Tabletastic initializer
|
243
260
|
|
244
261
|
As of version 0.2.0, you can now setup some of your own defaults in an initializer file.
|
@@ -109,12 +109,12 @@ module Tabletastic
|
|
109
109
|
compound_resource.flatten! if prefix.kind_of?(Array)
|
110
110
|
case action
|
111
111
|
when :show
|
112
|
-
@template.link_to(
|
112
|
+
@template.link_to(link_title(action), compound_resource)
|
113
113
|
when :destroy
|
114
|
-
@template.link_to(
|
115
|
-
:method => :delete, :confirm =>
|
114
|
+
@template.link_to(link_title(action), compound_resource,
|
115
|
+
:method => :delete, :confirm => confirmation_message)
|
116
116
|
else # edit, other resource GET actions
|
117
|
-
@template.link_to(action
|
117
|
+
@template.link_to(link_title(action),
|
118
118
|
@template.polymorphic_path(compound_resource, :action => action))
|
119
119
|
end
|
120
120
|
end
|
@@ -154,8 +154,16 @@ module Tabletastic
|
|
154
154
|
associations
|
155
155
|
end
|
156
156
|
|
157
|
+
def confirmation_message
|
158
|
+
I18n.t("tabletastic.actions.confirmation", :default => @@destroy_confirm_message)
|
159
|
+
end
|
160
|
+
|
157
161
|
def content_tag(name, content = nil, options = nil, escape = true, &block)
|
158
162
|
@template.content_tag(name, content, options, escape, &block)
|
159
163
|
end
|
164
|
+
|
165
|
+
def link_title(action)
|
166
|
+
I18n.translate(action, :scope => "tabletastic.actions", :default => action.to_s.titleize)
|
167
|
+
end
|
160
168
|
end
|
161
169
|
end
|
@@ -4,15 +4,15 @@ module Tabletastic
|
|
4
4
|
class TableField
|
5
5
|
@@association_methods = %w[to_label display_name full_name name title username login value to_str to_s]
|
6
6
|
|
7
|
-
|
7
|
+
attr_reader :heading, :method, :method_or_proc, :cell_html, :heading_html, :klass
|
8
8
|
|
9
9
|
def initialize(*args, &proc)
|
10
10
|
options = args.extract_options!
|
11
|
-
method = args.first.to_sym
|
11
|
+
@method = args.first.to_sym
|
12
12
|
@method_or_proc = block_given? ? proc : method
|
13
13
|
@cell_html, @heading_html = options[:cell_html], options[:heading_html]
|
14
14
|
@klass = options.delete(:klass)
|
15
|
-
@heading = options.delete(:heading) ||
|
15
|
+
@heading = options.delete(:heading) || default_heading
|
16
16
|
end
|
17
17
|
|
18
18
|
def cell_data(record)
|
@@ -29,6 +29,22 @@ module Tabletastic
|
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
+
def default_heading
|
33
|
+
I18n.translate(method, :scope => i18n_scope, :default => klass_default_heading)
|
34
|
+
end
|
35
|
+
|
36
|
+
def klass_default_heading
|
37
|
+
if klass.respond_to?(:human_attribute_name)
|
38
|
+
klass.human_attribute_name(method.to_s)
|
39
|
+
else
|
40
|
+
method.to_s.humanize
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def i18n_scope
|
45
|
+
[:tabletastic, :models, klass.try(:model_name).try(:singular)].compact
|
46
|
+
end
|
47
|
+
|
32
48
|
def detect_string_method(association)
|
33
49
|
@@association_methods.detect { |method| association.respond_to?(method) }
|
34
50
|
end
|
data/lib/tabletastic/version.rb
CHANGED
@@ -7,22 +7,11 @@ describe Tabletastic::TableField do
|
|
7
7
|
tf.heading.should == "Method"
|
8
8
|
end
|
9
9
|
|
10
|
-
it "should know its heading when provided" do
|
11
|
-
tf = TableField.new(:method, :heading => 'Foo', :klass => ::Post)
|
12
|
-
tf.heading.should == "Foo"
|
13
|
-
end
|
14
|
-
|
15
10
|
it "should know what to do with a record" do
|
16
11
|
tf = TableField.new(:downcase)
|
17
12
|
tf.cell_data("HELLO").should == "hello"
|
18
13
|
end
|
19
14
|
|
20
|
-
it "should use a human_attribute_name whenever possible" do
|
21
|
-
::Post.stub!(:human_attribute_name).with('method').and_return("Blah blue")
|
22
|
-
tf = TableField.new(:method, :klass => ::Post)
|
23
|
-
tf.heading.should == "Blah blue"
|
24
|
-
end
|
25
|
-
|
26
15
|
it "should know what to do with a record (proc)" do
|
27
16
|
tf = TableField.new(:fake) do |record|
|
28
17
|
record.upcase
|
@@ -35,4 +24,40 @@ describe Tabletastic::TableField do
|
|
35
24
|
tf = TableField.new(:booya)
|
36
25
|
tf.cell_data(post).should_not be_html_safe
|
37
26
|
end
|
27
|
+
|
28
|
+
describe "#heading" do
|
29
|
+
subject { TableField.new(:method, :heading => heading, :klass => Post) }
|
30
|
+
context "when heading option is provided" do
|
31
|
+
let(:heading) { "Foo" }
|
32
|
+
its(:heading) { should == "Foo" }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when heading option is omitted" do
|
36
|
+
let(:heading) { nil }
|
37
|
+
let(:derived_heading) { "Blah blue" }
|
38
|
+
let(:i18n_heading) { "I18n Foo" }
|
39
|
+
|
40
|
+
context "with I18n attributes defined" do
|
41
|
+
let(:i18n_translations) do
|
42
|
+
{ :tabletastic => { :models => { :post => { :method => i18n_heading } } } }
|
43
|
+
end
|
44
|
+
before { I18n.backend.store_translations :en, i18n_translations }
|
45
|
+
after { I18n.backend.reload! }
|
46
|
+
|
47
|
+
its(:heading) { should == i18n_heading }
|
48
|
+
end
|
49
|
+
|
50
|
+
context "with no I18n attributes defined" do
|
51
|
+
context "with human_attribute_name-capable class" do
|
52
|
+
before { Post.stub!(:human_attribute_name).with('method').and_return(derived_heading) }
|
53
|
+
its(:heading) { should == derived_heading }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "without human_attribute_name-capable class" do
|
57
|
+
its(:heading) { should == "Method" }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
38
63
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabletastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Joshua Davey
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-03-26 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
28
30
|
segments:
|
29
31
|
- 3
|
30
32
|
- 0
|
@@ -40,6 +42,7 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
43
46
|
segments:
|
44
47
|
- 0
|
45
48
|
version: "0"
|
@@ -82,6 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
85
|
requirements:
|
83
86
|
- - ">="
|
84
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
85
89
|
segments:
|
86
90
|
- 0
|
87
91
|
version: "0"
|
@@ -90,6 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
94
|
requirements:
|
91
95
|
- - ">="
|
92
96
|
- !ruby/object:Gem::Version
|
97
|
+
hash: 23
|
93
98
|
segments:
|
94
99
|
- 1
|
95
100
|
- 3
|
@@ -98,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
103
|
requirements: []
|
99
104
|
|
100
105
|
rubyforge_project:
|
101
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.5.2
|
102
107
|
signing_key:
|
103
108
|
specification_version: 3
|
104
109
|
summary: A smarter table builder for Rails collections
|