traco 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -2
- data/lib/traco/class_methods.rb +5 -3
- data/lib/traco/version.rb +1 -1
- data/spec/traco_spec.rb +9 -1
- metadata +16 -16
data/README.markdown
CHANGED
@@ -55,11 +55,17 @@ You can still use your accessors like `title_sv` and `title_sv=` in forms, valid
|
|
55
55
|
|
56
56
|
Or perhaps for things like:
|
57
57
|
|
58
|
-
attr_accessible *locale_columns(:
|
58
|
+
attr_accessible *locale_columns(:title)
|
59
59
|
|
60
|
-
validates *locale_columns(:
|
60
|
+
validates *locale_columns(:title),
|
61
61
|
:uniqueness => true
|
62
62
|
|
63
|
+
You can also pass multiple attributes if you like:
|
64
|
+
|
65
|
+
attr_accessible *locale_columns(:title, :body)
|
66
|
+
|
67
|
+
The return value will be sorted like `[:title_sv, :title_en, :body_sv, :body_en]`.
|
68
|
+
|
63
69
|
`.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with default locale first and then alphabetically.
|
64
70
|
|
65
71
|
And the equivalent methods for `body`, of course.
|
data/lib/traco/class_methods.rb
CHANGED
@@ -8,9 +8,11 @@ module Traco
|
|
8
8
|
sort_by(&locale_sort_value)
|
9
9
|
end
|
10
10
|
|
11
|
-
def locale_columns(
|
12
|
-
|
13
|
-
|
11
|
+
def locale_columns(*attributes)
|
12
|
+
attributes.inject([]) { |memo, attribute|
|
13
|
+
memo += locales_for_attribute(attribute).map { |locale|
|
14
|
+
:"#{attribute}_#{locale}"
|
15
|
+
}
|
14
16
|
}
|
15
17
|
end
|
16
18
|
|
data/lib/traco/version.rb
CHANGED
data/spec/traco_spec.rb
CHANGED
@@ -54,14 +54,22 @@ end
|
|
54
54
|
describe Post, ".locale_columns" do
|
55
55
|
before do
|
56
56
|
Post.translates :title
|
57
|
+
I18n.default_locale = :fi
|
57
58
|
end
|
58
59
|
|
59
60
|
it "lists the columns-with-locale for that attribute, default locale first and then alphabetically" do
|
60
|
-
I18n.default_locale = :fi
|
61
61
|
Post.locale_columns(:title).should == [
|
62
62
|
:title_fi, :title_en, :title_sv
|
63
63
|
]
|
64
64
|
end
|
65
|
+
|
66
|
+
it "supports multiple attributes" do
|
67
|
+
Post.translates :body
|
68
|
+
Post.locale_columns(:body, :title).should == [
|
69
|
+
:body_fi, :body_en, :body_sv,
|
70
|
+
:title_fi, :title_en, :title_sv
|
71
|
+
]
|
72
|
+
end
|
65
73
|
end
|
66
74
|
|
67
75
|
describe Post, "#title" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70205689234740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70205689234740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &70205689234320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70205689234320
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70205689233860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70205689233860
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70205689233440 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70205689233440
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard
|
60
|
-
requirement: &
|
60
|
+
requirement: &70205689216580 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70205689216580
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard-rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70205689216160 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70205689216160
|
80
80
|
description:
|
81
81
|
email:
|
82
82
|
- henrik@barsoom.se
|
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
segments:
|
117
117
|
- 0
|
118
|
-
hash: -
|
118
|
+
hash: -797656003425247647
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
none: false
|
121
121
|
requirements:
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash: -
|
127
|
+
hash: -797656003425247647
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
130
|
rubygems_version: 1.8.5
|