i18n_column 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.rb +4 -0
- data/README.rdoc +6 -0
- data/Rakefile +3 -20
- data/i18n_column.gemspec +19 -56
- data/lib/i18n_column/base.rb +14 -6
- data/lib/i18n_column/version.rb +3 -0
- data/spec/i18n_column_spec.rb +31 -18
- data/spec/spec_helper.rb +4 -16
- metadata +20 -21
- data/.document +0 -5
- data/VERSION +0 -1
data/Gemfile.rb
ADDED
data/README.rdoc
CHANGED
@@ -66,6 +66,12 @@ The current and default locale are retrieved from the {Rails Internationalizatio
|
|
66
66
|
node.save! => {"en":"Home","de":"Zuhause"}
|
67
67
|
node.name => 'Zuhause'
|
68
68
|
|
69
|
+
== Known issues
|
70
|
+
|
71
|
+
* Rails versions greater than <tt>3.0.1</tt>: JSON hash instead of translation is displayed in form fields. Workaround:
|
72
|
+
|
73
|
+
f.text_field(:fname) instead of f.text_field(:name)
|
74
|
+
|
69
75
|
== Copyright
|
70
76
|
|
71
77
|
Copyright (c) 2010 Philipp Ullmann. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,24 +1,7 @@
|
|
1
|
-
require('
|
2
|
-
require('
|
3
|
-
require 'rspec/core/rake_task'
|
1
|
+
require('bundler')
|
2
|
+
require('rspec/core/rake_task')
|
4
3
|
|
5
|
-
|
6
|
-
require 'jeweler'
|
7
|
-
Jeweler::Tasks.new do |gem|
|
8
|
-
gem.name = "i18n_column"
|
9
|
-
gem.summary = %Q{Storing and retrieving translations from a single database column}
|
10
|
-
gem.description = %Q{This extension provides the capabilities of storing and retrieving translations from a single database column. The translations are serialized using JSON.}
|
11
|
-
gem.email = "philipp.ullmann@create.at"
|
12
|
-
gem.homepage = "http://github.com/create-philipp-ullmann/i18n_column"
|
13
|
-
gem.authors = ["Philipp Ullmann"]
|
14
|
-
gem.add_development_dependency('rspec', '>= 2.0.0')
|
15
|
-
gem.add_development_dependency('sqlite3-ruby', '>= 1.3.1')
|
16
|
-
gem.add_development_dependency('activerecord', '>= 3.0.0')
|
17
|
-
end
|
18
|
-
Jeweler::GemcutterTasks.new
|
19
|
-
rescue LoadError
|
20
|
-
puts('Jeweler (or a dependency) not available. Install it with: gem install jeweler')
|
21
|
-
end
|
4
|
+
Bundler::GemHelper.install_tasks
|
22
5
|
|
23
6
|
desc('Run RSpec')
|
24
7
|
RSpec::Core::RakeTask.new do |t|
|
data/i18n_column.gemspec
CHANGED
@@ -1,62 +1,25 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push(File.expand_path('../lib', __FILE__))
|
3
|
+
require('i18n_column/version')
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
6
|
+
s.name = 'i18n_column'
|
7
|
+
s.version = I18nColumn::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Philipp Ullmann']
|
10
|
+
s.email = 'philipp.ullmann@create.at'
|
11
|
+
s.homepage = 'http://github.com/create-philipp-ullmann/i18n_column'
|
12
|
+
s.summary = 'Storing and retrieving translations from a single database column'
|
13
|
+
s.description = 'This extension provides the capabilities of storing and retrieving translations from a single database column. The translations are serialized using JSON.'
|
9
14
|
|
10
|
-
s.
|
11
|
-
s.authors = ["Philipp Ullmann"]
|
12
|
-
s.date = %q{2010-10-14}
|
13
|
-
s.description = %q{This extension provides the capabilities of storing and retrieving translations from a single database column. The translations are serialized using JSON.}
|
14
|
-
s.email = %q{philipp.ullmann@create.at}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"i18n_column.gemspec",
|
27
|
-
"lib/i18n_column.rb",
|
28
|
-
"lib/i18n_column/base.rb",
|
29
|
-
"spec/.rspec",
|
30
|
-
"spec/i18n_column_spec.rb",
|
31
|
-
"spec/spec_helper.rb"
|
32
|
-
]
|
33
|
-
s.homepage = %q{http://github.com/create-philipp-ullmann/i18n_column}
|
34
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
-
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.3.7}
|
37
|
-
s.summary = %q{Storing and retrieving translations from a single database column}
|
38
|
-
s.test_files = [
|
39
|
-
"spec/i18n_column_spec.rb",
|
40
|
-
"spec/spec_helper.rb"
|
41
|
-
]
|
15
|
+
s.rubyforge_project = "i18n_column"
|
42
16
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
else
|
52
|
-
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
53
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 1.3.1"])
|
54
|
-
s.add_dependency(%q<activerecord>, [">= 3.0.0"])
|
55
|
-
end
|
56
|
-
else
|
57
|
-
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
58
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 1.3.1"])
|
59
|
-
s.add_dependency(%q<activerecord>, [">= 3.0.0"])
|
60
|
-
end
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
|
22
|
+
s.add_development_dependency('rspec', ['>= 2.5.0'])
|
23
|
+
s.add_development_dependency('sqlite3-ruby', ['>= 1.3.3'])
|
24
|
+
s.add_development_dependency('activerecord', ['>= 3.0.5'])
|
61
25
|
end
|
62
|
-
|
data/lib/i18n_column/base.rb
CHANGED
@@ -18,20 +18,28 @@ module I18nColumn
|
|
18
18
|
for col_name in col_names
|
19
19
|
class_eval <<-EOV
|
20
20
|
def #{col_name}
|
21
|
-
json = #{col_name}
|
21
|
+
json = decode_#{col_name}
|
22
22
|
json.nil? ? nil : json[::I18n.locale.to_s]
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def #{col_name}=(value)
|
26
|
-
json = #{col_name}
|
26
|
+
json = decode_#{col_name} || {}
|
27
27
|
json[::I18n.locale.to_s] = value
|
28
28
|
self[:#{col_name}] = json.to_json
|
29
29
|
value
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
|
+
def f#{col_name}
|
33
|
+
self.#{col_name}
|
34
|
+
end
|
35
|
+
|
36
|
+
def f#{col_name}=(value)
|
37
|
+
self.#{col_name} = value
|
38
|
+
end
|
39
|
+
|
32
40
|
private
|
33
|
-
|
34
|
-
def #{col_name}
|
41
|
+
|
42
|
+
def decode_#{col_name}
|
35
43
|
::ActiveSupport::JSON::decode(self[:#{col_name}].to_s) || nil
|
36
44
|
end
|
37
45
|
EOV
|
data/spec/i18n_column_spec.rb
CHANGED
@@ -1,52 +1,48 @@
|
|
1
|
-
require
|
1
|
+
require('spec_helper')
|
2
2
|
|
3
3
|
describe(I18nColumn::Base) do
|
4
4
|
before(:each) do
|
5
5
|
I18n.locale = :en
|
6
|
-
setup_db
|
7
6
|
end
|
8
7
|
|
9
|
-
|
10
|
-
teardown_db
|
11
|
-
end
|
12
|
-
|
13
|
-
context('with no translation') do
|
8
|
+
context('with no translations') do
|
14
9
|
before(:each) do
|
15
10
|
@node = Node.new
|
16
11
|
end
|
17
12
|
|
18
13
|
describe('#name') do
|
19
|
-
it('
|
14
|
+
it('should return nil') do
|
20
15
|
@node.name.should(be_nil)
|
21
16
|
end
|
22
17
|
end
|
23
18
|
|
24
19
|
describe('#name=') do
|
25
|
-
it('
|
20
|
+
it('should set the english translation') do
|
26
21
|
@node.name = 'Home'
|
27
22
|
@node.name.should == 'Home'
|
28
23
|
end
|
29
24
|
end
|
30
25
|
end
|
31
26
|
|
32
|
-
context('with an english
|
27
|
+
context('with an english translation') do
|
33
28
|
before(:each) do
|
34
29
|
@node = Node.create!(:name => 'Home')
|
30
|
+
@node.reload
|
35
31
|
end
|
36
32
|
|
37
33
|
describe('#name') do
|
38
|
-
it('
|
34
|
+
it('should return the english translation') do
|
39
35
|
@node.name.should == 'Home'
|
40
36
|
end
|
41
37
|
end
|
42
38
|
|
43
39
|
describe('#name=') do
|
44
|
-
it('
|
40
|
+
it('should override the english translation') do
|
45
41
|
@node.name = 'Home overridden'
|
46
42
|
@node.name.should == 'Home overridden'
|
47
43
|
end
|
48
44
|
|
49
|
-
it('
|
45
|
+
it('should set the german translation') do
|
50
46
|
I18n.locale = :de
|
51
47
|
@node.name = 'Zuhause'
|
52
48
|
@node.name.should == 'Zuhause'
|
@@ -54,27 +50,28 @@ describe(I18nColumn::Base) do
|
|
54
50
|
end
|
55
51
|
end
|
56
52
|
|
57
|
-
context('with an english and german
|
53
|
+
context('with an english and german translation') do
|
58
54
|
before(:each) do
|
59
55
|
@node = Node.create!(:name => 'Home')
|
60
56
|
I18n.locale = :de
|
61
57
|
@node.update_attribute(:name, 'Zuhause')
|
58
|
+
@node.reload
|
62
59
|
end
|
63
60
|
|
64
61
|
describe('#name') do
|
65
|
-
it('
|
62
|
+
it('should return the english translation') do
|
66
63
|
I18n.locale = :en
|
67
64
|
@node.name.should == 'Home'
|
68
65
|
end
|
69
66
|
|
70
|
-
it('
|
67
|
+
it('should return the german translation') do
|
71
68
|
I18n.locale = :de
|
72
69
|
@node.name.should == 'Zuhause'
|
73
70
|
end
|
74
71
|
end
|
75
72
|
|
76
73
|
describe('#name=') do
|
77
|
-
it('
|
74
|
+
it('should set the english translation') do
|
78
75
|
I18n.locale = :en
|
79
76
|
@node.name = 'Home overridden'
|
80
77
|
@node.name.should == 'Home overridden'
|
@@ -82,7 +79,7 @@ describe(I18nColumn::Base) do
|
|
82
79
|
@node.name.should == 'Zuhause'
|
83
80
|
end
|
84
81
|
|
85
|
-
it('
|
82
|
+
it('should set the german translation') do
|
86
83
|
I18n.locale = :de
|
87
84
|
@node.name = 'Zuhause ueberschrieben'
|
88
85
|
@node.name.should == 'Zuhause ueberschrieben'
|
@@ -91,4 +88,20 @@ describe(I18nColumn::Base) do
|
|
91
88
|
end
|
92
89
|
end
|
93
90
|
end
|
91
|
+
|
92
|
+
describe('#fname') do
|
93
|
+
it('should call method name') do
|
94
|
+
node = Node.new
|
95
|
+
node.should_receive(:name)
|
96
|
+
node.fname
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe('#fname=') do
|
101
|
+
it('should call method name=') do
|
102
|
+
node = Node.new
|
103
|
+
node.should_receive(:name=).with('translation')
|
104
|
+
node.fname = 'translation'
|
105
|
+
end
|
106
|
+
end
|
94
107
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,22 +1,10 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'rubygems'
|
4
|
-
require 'active_record'
|
5
|
-
require 'i18n_column'
|
1
|
+
require('i18n_column')
|
6
2
|
|
7
3
|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
t.text(:name)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def teardown_db
|
18
|
-
ActiveRecord::Base.connection.tables.each do |table|
|
19
|
-
ActiveRecord::Base.connection.drop_table(table)
|
5
|
+
ActiveRecord::Schema.define(:version => 1) do
|
6
|
+
create_table(:nodes) do |t|
|
7
|
+
t.string(:name)
|
20
8
|
end
|
21
9
|
end
|
22
10
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_column
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Philipp Ullmann
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-03-01 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 27
|
30
30
|
segments:
|
31
31
|
- 2
|
32
|
+
- 5
|
32
33
|
- 0
|
33
|
-
|
34
|
-
version: 2.0.0
|
34
|
+
version: 2.5.0
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
@@ -42,12 +42,12 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 29
|
46
46
|
segments:
|
47
47
|
- 1
|
48
48
|
- 3
|
49
|
-
-
|
50
|
-
version: 1.3.
|
49
|
+
- 3
|
50
|
+
version: 1.3.3
|
51
51
|
type: :development
|
52
52
|
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
@@ -58,12 +58,12 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
61
|
+
hash: 13
|
62
62
|
segments:
|
63
63
|
- 3
|
64
64
|
- 0
|
65
|
-
-
|
66
|
-
version: 3.0.
|
65
|
+
- 5
|
66
|
+
version: 3.0.5
|
67
67
|
type: :development
|
68
68
|
version_requirements: *id003
|
69
69
|
description: This extension provides the capabilities of storing and retrieving translations from a single database column. The translations are serialized using JSON.
|
@@ -72,19 +72,18 @@ executables: []
|
|
72
72
|
|
73
73
|
extensions: []
|
74
74
|
|
75
|
-
extra_rdoc_files:
|
76
|
-
|
77
|
-
- README.rdoc
|
75
|
+
extra_rdoc_files: []
|
76
|
+
|
78
77
|
files:
|
79
|
-
- .document
|
80
78
|
- .gitignore
|
79
|
+
- Gemfile.rb
|
81
80
|
- LICENSE
|
82
81
|
- README.rdoc
|
83
82
|
- Rakefile
|
84
|
-
- VERSION
|
85
83
|
- i18n_column.gemspec
|
86
84
|
- lib/i18n_column.rb
|
87
85
|
- lib/i18n_column/base.rb
|
86
|
+
- lib/i18n_column/version.rb
|
88
87
|
- spec/.rspec
|
89
88
|
- spec/i18n_column_spec.rb
|
90
89
|
- spec/spec_helper.rb
|
@@ -93,8 +92,8 @@ homepage: http://github.com/create-philipp-ullmann/i18n_column
|
|
93
92
|
licenses: []
|
94
93
|
|
95
94
|
post_install_message:
|
96
|
-
rdoc_options:
|
97
|
-
|
95
|
+
rdoc_options: []
|
96
|
+
|
98
97
|
require_paths:
|
99
98
|
- lib
|
100
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -117,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
116
|
version: "0"
|
118
117
|
requirements: []
|
119
118
|
|
120
|
-
rubyforge_project:
|
119
|
+
rubyforge_project: i18n_column
|
121
120
|
rubygems_version: 1.3.7
|
122
121
|
signing_key:
|
123
122
|
specification_version: 3
|
data/.document
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.2
|