simple_model_translations 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,14 +1,10 @@
1
1
  source :rubygems
2
2
 
3
- gem 'activerecord', '>= 3.0.0'
3
+ gem 'activerecord', '~> 3.0.0'
4
4
 
5
5
  group :test do
6
- gem 'database_cleaner', '>= 0.5.2'
7
- gem 'sqlite3-ruby', '>= 1.3.1'
8
- gem 'shoulda', '>= 2.11.3'
9
- gem 'rspec', '>= 2.0.0'
10
- end
11
-
12
- group :console do
13
- gem 'jeweler', '>= 1.5.0.pre5'
6
+ gem 'database_cleaner', '~> 0.5.2'
7
+ gem 'sqlite3-ruby', '~> 1.3.1'
8
+ gem 'shoulda', '~> 2.11.3'
9
+ gem 'rspec', '~> 2.0.0'
14
10
  end
data/Gemfile.lock CHANGED
@@ -1,38 +1,32 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.0.0)
5
- activesupport (= 3.0.0)
4
+ activemodel (3.0.1)
5
+ activesupport (= 3.0.1)
6
6
  builder (~> 2.1.2)
7
7
  i18n (~> 0.4.1)
8
- activerecord (3.0.0)
9
- activemodel (= 3.0.0)
10
- activesupport (= 3.0.0)
8
+ activerecord (3.0.1)
9
+ activemodel (= 3.0.1)
10
+ activesupport (= 3.0.1)
11
11
  arel (~> 1.0.0)
12
12
  tzinfo (~> 0.3.23)
13
- activesupport (3.0.0)
13
+ activesupport (3.0.1)
14
14
  arel (1.0.1)
15
15
  activesupport (~> 3.0.0)
16
16
  builder (2.1.2)
17
17
  database_cleaner (0.5.2)
18
18
  diff-lcs (1.1.2)
19
- git (1.2.5)
20
19
  i18n (0.4.1)
21
- jeweler (1.5.0.pre5)
22
- bundler (~> 1.0.0)
23
- git (>= 1.2.5)
24
- rake
25
- rake (0.8.7)
26
- rspec (2.0.0)
27
- rspec-core (= 2.0.0)
28
- rspec-expectations (= 2.0.0)
29
- rspec-mocks (= 2.0.0)
30
- rspec-core (2.0.0)
31
- rspec-expectations (2.0.0)
20
+ rspec (2.0.1)
21
+ rspec-core (~> 2.0.1)
22
+ rspec-expectations (~> 2.0.1)
23
+ rspec-mocks (~> 2.0.1)
24
+ rspec-core (2.0.1)
25
+ rspec-expectations (2.0.1)
32
26
  diff-lcs (>= 1.1.2)
33
- rspec-mocks (2.0.0)
34
- rspec-core (= 2.0.0)
35
- rspec-expectations (= 2.0.0)
27
+ rspec-mocks (2.0.1)
28
+ rspec-core (~> 2.0.1)
29
+ rspec-expectations (~> 2.0.1)
36
30
  shoulda (2.11.3)
37
31
  sqlite3-ruby (1.3.1)
38
32
  tzinfo (0.3.23)
@@ -41,9 +35,8 @@ PLATFORMS
41
35
  ruby
42
36
 
43
37
  DEPENDENCIES
44
- activerecord (>= 3.0.0)
45
- database_cleaner (>= 0.5.2)
46
- jeweler (>= 1.5.0.pre5)
47
- rspec (>= 2.0.0)
48
- shoulda (>= 2.11.3)
49
- sqlite3-ruby (>= 1.3.1)
38
+ activerecord (~> 3.0.0)
39
+ database_cleaner (~> 0.5.2)
40
+ rspec (~> 2.0.0)
41
+ shoulda (~> 2.11.3)
42
+ sqlite3-ruby (~> 1.3.1)
data/README.rdoc CHANGED
@@ -51,6 +51,22 @@ Now you are able to translate values for the attributes :title and :description
51
51
 
52
52
  Additional features can be discovered by searching the code and specs. Documentation is not available yet. I hope, it'll be done when releasing zn.ua. :)
53
53
 
54
+ == Nested attributes
55
+
56
+ Usually, when creating bootstrap data (e.g. seeds.rb) you want to pass all translations in one statement.
57
+ You can do it using Rails' nested attributes, and we propose a very convenient option for that:
58
+
59
+ class Category < ActiveRecord::Base
60
+ translates :name, :attributes => true
61
+ end
62
+
63
+ Usage:
64
+
65
+ Category.create!(:translations_attributes => [
66
+ { :locale => :en, :name => 'Science' },
67
+ { :locale => :ru, :name => 'Наука' }
68
+ ])
69
+
54
70
  == Note on Patches/Pull Requests
55
71
 
56
72
  * Fork the project.
data/Rakefile CHANGED
@@ -1,45 +1,30 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
1
3
  require 'rubygems'
2
4
  require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "simple_model_translations"
8
- gem.summary = %Q{Simple ActiveRecord translations for Rails 3}
9
- gem.description = %Q{Simple ActiveRecord translations for Rails 3}
10
- gem.email = "fxposter@gmail.com"
11
- gem.homepage = "http://github.com/fxposter/simple_model_translations"
12
- gem.authors = ["Pavel Forkert"]
13
-
14
- gem.add_development_dependency 'database_cleaner', '>= 0.5.2'
15
- gem.add_development_dependency 'sqlite3-ruby', '>= 1.3.1'
16
- gem.add_development_dependency 'shoulda', '>= 2.11.3'
17
- gem.add_development_dependency 'rspec', '>= 2.0.0'
18
- gem.add_development_dependency 'jeweler', '>= 1.5.0.pre5'
19
- end
20
- Jeweler::GemcutterTasks.new
21
- rescue LoadError
22
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler --pre"
23
- end
24
-
5
+ require 'simple_model_translations/version'
25
6
  require 'rspec/core/rake_task'
26
- RSpec::Core::RakeTask.new(:spec) do |spec|
27
- end
7
+ require 'rake/rdoctask'
28
8
 
29
- RSpec::Core::RakeTask.new(:rcov) do |spec|
30
- spec.rcov = true
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.rspec_opts = %w(-fs --color)
31
11
  end
32
12
 
33
- task :spec => :check_dependencies
34
-
35
- task :default => :spec
36
-
37
- require 'rake/rdoctask'
38
13
  Rake::RDocTask.new do |rdoc|
39
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
-
41
14
  rdoc.rdoc_dir = 'rdoc'
42
- rdoc.title = "simple_model_translations #{version}"
15
+ rdoc.title = "simple_model_translations #{SimpleModelTranslations::VERSION}"
43
16
  rdoc.rdoc_files.include('README*')
44
17
  rdoc.rdoc_files.include('lib/**/*.rb')
45
18
  end
19
+
20
+ task :build do
21
+ system 'gem build simple_model_translations.gemspec'
22
+ system 'mkdir pkg' unless File.exists?('pkg')
23
+ system "mv simple_model_translations-#{SimpleModelTranslations::VERSION}.gem pkg"
24
+ end
25
+
26
+ task :release => :build do
27
+ system "gem push pkg/simple_model_translations-#{SimpleModelTranslations::VERSION}.gem"
28
+ end
29
+
30
+ task :default => :spec
@@ -15,7 +15,7 @@ module SimpleModelTranslations
15
15
  # Configure translated attributes.
16
16
  # Eg:
17
17
  # class Post < ActiveRecord::Base
18
- # translates :title, :description
18
+ # translates :title, :description, :attributes => true
19
19
  # end
20
20
  def translates(*attributes)
21
21
  configure_translations(attributes.extract_options!)
@@ -52,7 +52,7 @@ module SimpleModelTranslations
52
52
 
53
53
  has_many :translations, :class_name => translation_class.name, :dependent => :destroy, :autosave => true
54
54
 
55
- if options[:accepts_nested_attributes]
55
+ if options[:attributes]
56
56
  accepts_nested_attributes_for :translations, :allow_destroy => true
57
57
  end
58
58
  end
@@ -1,6 +1,6 @@
1
1
  module SimpleModelTranslations
2
2
  module Validations
3
- class TranslationsValidator < ActiveModel::Validator
3
+ class TranslationsValidator < ::ActiveModel::Validator
4
4
  def validate(record)
5
5
  locales = options[:locales]
6
6
  locales = [locales] unless locales.respond_to?(:each)
@@ -0,0 +1,3 @@
1
+ module SimpleModelTranslations
2
+ VERSION = '0.1.6'
3
+ end
@@ -1,86 +1,26 @@
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 -*-
5
-
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require 'simple_model_translations/version'
6
+
6
7
  Gem::Specification.new do |s|
7
- s.name = %q{simple_model_translations}
8
- s.version = "0.1.4"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Pavel Forkert"]
12
- s.date = %q{2010-10-14}
13
- s.description = %q{Simple ActiveRecord translations for Rails 3}
14
- s.email = %q{fxposter@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "lib/simple_model_translations.rb",
28
- "lib/simple_model_translations/attributes.rb",
29
- "lib/simple_model_translations/base.rb",
30
- "lib/simple_model_translations/class_methods.rb",
31
- "lib/simple_model_translations/instance_methods.rb",
32
- "lib/simple_model_translations/validations.rb",
33
- "simple_model_translations.gemspec",
34
- "spec/attributes_spec.rb",
35
- "spec/auto_generated_translation_classes_spec.rb",
36
- "spec/class_methods_spec.rb",
37
- "spec/data/models.rb",
38
- "spec/data/schema.rb",
39
- "spec/simple_model_translations_spec.rb",
40
- "spec/spec_helper.rb",
41
- "spec/validations_spec.rb"
42
- ]
43
- s.homepage = %q{http://github.com/fxposter/simple_model_translations}
44
- s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.3.7}
46
- s.summary = %q{Simple ActiveRecord translations for Rails 3}
47
- s.test_files = [
48
- "spec/attributes_spec.rb",
49
- "spec/auto_generated_translation_classes_spec.rb",
50
- "spec/class_methods_spec.rb",
51
- "spec/data/models.rb",
52
- "spec/data/schema.rb",
53
- "spec/simple_model_translations_spec.rb",
54
- "spec/spec_helper.rb",
55
- "spec/validations_spec.rb"
56
- ]
8
+ s.name = 'simple_model_translations'
9
+ s.version = SimpleModelTranslations::VERSION
10
+ s.author = 'Pavel Forkert'
11
+ s.email = 'fxposter@gmail.com'
12
+ s.homepage = 'http://github.com/fxposter/simple_model_translations'
13
+ s.summary = 'Simple ActiveRecord translations for Rails 3'
14
+ s.description = 'Simple ActiveRecord translations for Rails 3'
15
+ s.require_path = 'lib'
16
+ s.files = Dir.glob('{spec,lib}/**/*') + %w(Gemfile Gemfile.lock LICENSE Rakefile README.rdoc simple_model_translations.gemspec)
17
+ s.test_files = Dir.glob('spec/**/*')
18
+ s.extra_rdoc_files = %w(LICENSE README.rdoc)
57
19
 
58
- if s.respond_to? :specification_version then
59
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
60
- s.specification_version = 3
61
-
62
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
- s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0"])
64
- s.add_development_dependency(%q<database_cleaner>, [">= 0.5.2"])
65
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.3.1"])
66
- s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
67
- s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
68
- s.add_development_dependency(%q<jeweler>, [">= 1.5.0.pre5"])
69
- else
70
- s.add_dependency(%q<activerecord>, [">= 3.0.0"])
71
- s.add_dependency(%q<database_cleaner>, [">= 0.5.2"])
72
- s.add_dependency(%q<sqlite3-ruby>, [">= 1.3.1"])
73
- s.add_dependency(%q<shoulda>, [">= 2.11.3"])
74
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
75
- s.add_dependency(%q<jeweler>, [">= 1.5.0.pre5"])
76
- end
77
- else
78
- s.add_dependency(%q<activerecord>, [">= 3.0.0"])
79
- s.add_dependency(%q<database_cleaner>, [">= 0.5.2"])
80
- s.add_dependency(%q<sqlite3-ruby>, [">= 1.3.1"])
81
- s.add_dependency(%q<shoulda>, [">= 2.11.3"])
82
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
83
- s.add_dependency(%q<jeweler>, [">= 1.5.0.pre5"])
84
- end
20
+ s.required_rubygems_version = '>= 1.3.6'
21
+ s.add_runtime_dependency('activerecord', '~> 3.0.0')
22
+ s.add_development_dependency('database_cleaner', '~> 0.5.2')
23
+ s.add_development_dependency('sqlite3-ruby', '~> 1.3.1')
24
+ s.add_development_dependency('shoulda', '~> 2.11.3')
25
+ s.add_development_dependency('rspec', '~> 2.0.0')
85
26
  end
86
-
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
4
 
3
5
  describe Article do
@@ -95,3 +97,18 @@ end
95
97
  describe ArticleTranslation do
96
98
  it { should belong_to :article }
97
99
  end
100
+
101
+ describe Category do
102
+ it { should respond_to(:translations_attributes=) }
103
+ it 'should accept array of translation attributes' do
104
+ category = Category.create!(:translations_attributes => [
105
+ { :locale => :en, :name => 'Science' },
106
+ { :locale => :ru, :name => 'Наука' }
107
+ ])
108
+ category.should have_translation(:ru)
109
+ category.should have_translation(:en)
110
+ category.should have_translated_attribute(:en, :name, 'Science')
111
+ category.should have_translated_attribute(:ru, :name, 'Наука')
112
+ end
113
+ end
114
+
data/spec/data/models.rb CHANGED
@@ -17,4 +17,8 @@ end
17
17
 
18
18
  class Tag < ActiveRecord::Base
19
19
  translates :name
20
- end
20
+ end
21
+
22
+ class Category < ActiveRecord::Base
23
+ translates :name, :attributes => true
24
+ end
data/spec/data/schema.rb CHANGED
@@ -31,5 +31,14 @@ ActiveRecord::Schema.define do
31
31
  t.references :tag
32
32
  t.string :name
33
33
  end
34
+
35
+ create_table :categories, :force => true do |t|
36
+ end
37
+
38
+ create_table :category_translations, :force => true do |t|
39
+ t.string :locale
40
+ t.references :category
41
+ t.string :name
42
+ end
34
43
  end
35
44
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_model_translations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pavel Forkert
@@ -15,17 +15,16 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-14 00:00:00 +03:00
18
+ date: 2010-10-22 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :runtime
24
22
  name: activerecord
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
28
- - - ">="
27
+ - - ~>
29
28
  - !ruby/object:Gem::Version
30
29
  hash: 7
31
30
  segments:
@@ -33,15 +32,15 @@ dependencies:
33
32
  - 0
34
33
  - 0
35
34
  version: 3.0.0
36
- requirement: *id001
35
+ type: :runtime
36
+ version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- prerelease: false
39
- type: :development
40
38
  name: database_cleaner
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
42
41
  none: false
43
42
  requirements:
44
- - - ">="
43
+ - - ~>
45
44
  - !ruby/object:Gem::Version
46
45
  hash: 15
47
46
  segments:
@@ -49,15 +48,15 @@ dependencies:
49
48
  - 5
50
49
  - 2
51
50
  version: 0.5.2
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
54
- prerelease: false
55
51
  type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
56
54
  name: sqlite3-ruby
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
58
57
  none: false
59
58
  requirements:
60
- - - ">="
59
+ - - ~>
61
60
  - !ruby/object:Gem::Version
62
61
  hash: 25
63
62
  segments:
@@ -65,15 +64,15 @@ dependencies:
65
64
  - 3
66
65
  - 1
67
66
  version: 1.3.1
68
- requirement: *id003
69
- - !ruby/object:Gem::Dependency
70
- prerelease: false
71
67
  type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
72
70
  name: shoulda
73
- version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
74
73
  none: false
75
74
  requirements:
76
- - - ">="
75
+ - - ~>
77
76
  - !ruby/object:Gem::Version
78
77
  hash: 37
79
78
  segments:
@@ -81,15 +80,15 @@ dependencies:
81
80
  - 11
82
81
  - 3
83
82
  version: 2.11.3
84
- requirement: *id004
85
- - !ruby/object:Gem::Dependency
86
- prerelease: false
87
83
  type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
88
86
  name: rspec
89
- version_requirements: &id005 !ruby/object:Gem::Requirement
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
90
89
  none: false
91
90
  requirements:
92
- - - ">="
91
+ - - ~>
93
92
  - !ruby/object:Gem::Version
94
93
  hash: 15
95
94
  segments:
@@ -97,24 +96,8 @@ dependencies:
97
96
  - 0
98
97
  - 0
99
98
  version: 2.0.0
100
- requirement: *id005
101
- - !ruby/object:Gem::Dependency
102
- prerelease: false
103
99
  type: :development
104
- name: jeweler
105
- version_requirements: &id006 !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: -1876988220
111
- segments:
112
- - 1
113
- - 5
114
- - 0
115
- - pre5
116
- version: 1.5.0.pre5
117
- requirement: *id006
100
+ version_requirements: *id005
118
101
  description: Simple ActiveRecord translations for Rails 3
119
102
  email: fxposter@gmail.com
120
103
  executables: []
@@ -125,20 +108,6 @@ extra_rdoc_files:
125
108
  - LICENSE
126
109
  - README.rdoc
127
110
  files:
128
- - .document
129
- - Gemfile
130
- - Gemfile.lock
131
- - LICENSE
132
- - README.rdoc
133
- - Rakefile
134
- - VERSION
135
- - lib/simple_model_translations.rb
136
- - lib/simple_model_translations/attributes.rb
137
- - lib/simple_model_translations/base.rb
138
- - lib/simple_model_translations/class_methods.rb
139
- - lib/simple_model_translations/instance_methods.rb
140
- - lib/simple_model_translations/validations.rb
141
- - simple_model_translations.gemspec
142
111
  - spec/attributes_spec.rb
143
112
  - spec/auto_generated_translation_classes_spec.rb
144
113
  - spec/class_methods_spec.rb
@@ -147,6 +116,19 @@ files:
147
116
  - spec/simple_model_translations_spec.rb
148
117
  - spec/spec_helper.rb
149
118
  - spec/validations_spec.rb
119
+ - lib/simple_model_translations/attributes.rb
120
+ - lib/simple_model_translations/base.rb
121
+ - lib/simple_model_translations/class_methods.rb
122
+ - lib/simple_model_translations/instance_methods.rb
123
+ - lib/simple_model_translations/validations.rb
124
+ - lib/simple_model_translations/version.rb
125
+ - lib/simple_model_translations.rb
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE
129
+ - Rakefile
130
+ - README.rdoc
131
+ - simple_model_translations.gemspec
150
132
  has_rdoc: true
151
133
  homepage: http://github.com/fxposter/simple_model_translations
152
134
  licenses: []
@@ -170,10 +152,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
152
  requirements:
171
153
  - - ">="
172
154
  - !ruby/object:Gem::Version
173
- hash: 3
155
+ hash: 23
174
156
  segments:
175
- - 0
176
- version: "0"
157
+ - 1
158
+ - 3
159
+ - 6
160
+ version: 1.3.6
177
161
  requirements: []
178
162
 
179
163
  rubyforge_project:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.4