i18n_fields 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails'
4
+ gem 'globalize3'
5
+ gem 'active_record_schema'
6
+
7
+ group :development do
8
+ gem "jeweler"
9
+ end
@@ -0,0 +1,103 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.8)
5
+ actionpack (= 3.2.8)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.8)
8
+ activemodel (= 3.2.8)
9
+ activesupport (= 3.2.8)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.3)
17
+ active_record_schema (0.5.12)
18
+ rails
19
+ activemodel (3.2.8)
20
+ activesupport (= 3.2.8)
21
+ builder (~> 3.0.0)
22
+ activerecord (3.2.8)
23
+ activemodel (= 3.2.8)
24
+ activesupport (= 3.2.8)
25
+ arel (~> 3.0.2)
26
+ tzinfo (~> 0.3.29)
27
+ activeresource (3.2.8)
28
+ activemodel (= 3.2.8)
29
+ activesupport (= 3.2.8)
30
+ activesupport (3.2.8)
31
+ i18n (~> 0.6)
32
+ multi_json (~> 1.0)
33
+ arel (3.0.2)
34
+ builder (3.0.0)
35
+ erubis (2.7.0)
36
+ git (1.2.5)
37
+ globalize3 (0.2.0)
38
+ activemodel (>= 3.0.0)
39
+ activerecord (>= 3.0.0)
40
+ paper_trail (~> 2)
41
+ hike (1.2.1)
42
+ i18n (0.6.0)
43
+ jeweler (1.8.4)
44
+ bundler (~> 1.0)
45
+ git (>= 1.2.5)
46
+ rake
47
+ rdoc
48
+ journey (1.0.4)
49
+ json (1.7.5)
50
+ mail (2.4.4)
51
+ i18n (>= 0.4.0)
52
+ mime-types (~> 1.16)
53
+ treetop (~> 1.4.8)
54
+ mime-types (1.19)
55
+ multi_json (1.3.6)
56
+ paper_trail (2.6.3)
57
+ activerecord (~> 3.0)
58
+ railties (~> 3.0)
59
+ polyglot (0.3.3)
60
+ rack (1.4.1)
61
+ rack-cache (1.2)
62
+ rack (>= 0.4)
63
+ rack-ssl (1.3.2)
64
+ rack
65
+ rack-test (0.6.1)
66
+ rack (>= 1.0)
67
+ rails (3.2.8)
68
+ actionmailer (= 3.2.8)
69
+ actionpack (= 3.2.8)
70
+ activerecord (= 3.2.8)
71
+ activeresource (= 3.2.8)
72
+ activesupport (= 3.2.8)
73
+ bundler (~> 1.0)
74
+ railties (= 3.2.8)
75
+ railties (3.2.8)
76
+ actionpack (= 3.2.8)
77
+ activesupport (= 3.2.8)
78
+ rack-ssl (~> 1.3.2)
79
+ rake (>= 0.8.7)
80
+ rdoc (~> 3.4)
81
+ thor (>= 0.14.6, < 2.0)
82
+ rake (0.9.2.2)
83
+ rdoc (3.12)
84
+ json (~> 1.4)
85
+ sprockets (2.1.3)
86
+ hike (~> 1.2)
87
+ rack (~> 1.0)
88
+ tilt (~> 1.1, != 1.3.0)
89
+ thor (0.16.0)
90
+ tilt (1.3.3)
91
+ treetop (1.4.10)
92
+ polyglot
93
+ polyglot (>= 0.3.1)
94
+ tzinfo (0.3.33)
95
+
96
+ PLATFORMS
97
+ ruby
98
+
99
+ DEPENDENCIES
100
+ active_record_schema
101
+ globalize3
102
+ jeweler
103
+ rails
@@ -0,0 +1,57 @@
1
+ # I18n Fields
2
+
3
+ ## Translatable fields for [ActiveRecordSchema](https://github.com/mcasimir/active_record_schema)
4
+
5
+ **I18n Fields** brings multilingual support to [ActiveRecordSchema](https://github.com/mcasimir/active_record_schema) through `globalize3`.
6
+
7
+ ### Installation
8
+
9
+ ``` rb
10
+ gem 'i18n_fields'
11
+ ```
12
+
13
+ ### Usage
14
+
15
+ ``` rb
16
+ class Post < ActiveRecord::Base
17
+
18
+ field :title, :translatable => true
19
+ field :text, :as => :text, :translatable => true
20
+
21
+ end
22
+ ```
23
+
24
+ ### How to generate migrations
25
+
26
+ For model with translatable fields you should generate an additional migration for translation model
27
+
28
+ ``` bash
29
+ rails g migration:from post post/translation
30
+ ```
31
+
32
+ Now learn how to use `globalize3` to actually translate your models either reading the [globalize docs](https://github.com/svenfuchs/globalize3) or watching this [Railscast episode](http://railscasts.com/episodes/338-globalize3).
33
+
34
+ ---
35
+
36
+ Copyright (c) 2012 mcasimir
37
+
38
+ MIT License
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining
41
+ a copy of this software and associated documentation files (the
42
+ "Software"), to deal in the Software without restriction, including
43
+ without limitation the rights to use, copy, modify, merge, publish,
44
+ distribute, sublicense, and/or sell copies of the Software, and to
45
+ permit persons to whom the Software is furnished to do so, subject to
46
+ the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be
49
+ included in all copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
52
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
54
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
55
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
56
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
57
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "i18n_fields"
18
+ gem.homepage = "http://github.com/mcasimir/kaminari-bootstrap"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Translatable fields for ActiveRecordSchema}
21
+ gem.description = %Q{Translatable fields for ActiveRecordSchema}
22
+ gem.email = "maurizio.cas@gmail.com"
23
+ gem.authors = ["mcasimir"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+
29
+ task :push do
30
+ message = ENV["message"] || "commit #{Time.now}"
31
+ `git add . && git commit -a -m '#{message}' && git push`
32
+ end
33
+
34
+ task "release:patch" do
35
+ Rake::Task["gemspec"].invoke
36
+ Rake::Task["version:bump:patch"]
37
+ Rake::Task["push"].invoke
38
+ Rake::Task["release"].invoke
39
+ end
40
+
41
+ task "release:minor" do
42
+ Rake::Task["gemspec"].invoke
43
+ Rake::Task["version:bump:minor"]
44
+ Rake::Task["push"].invoke
45
+ Rake::Task["release"].invoke
46
+ end
47
+
48
+ task "release:major" do
49
+ Rake::Task["gemspec"].invoke
50
+ Rake::Task["version:bump:major"]
51
+ Rake::Task["push"].invoke
52
+ Rake::Task["release"].invoke
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "i18n_fields"
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["mcasimir"]
12
+ s.date = "2012-08-24"
13
+ s.description = "Translatable fields for ActiveRecordSchema"
14
+ s.email = "maurizio.cas@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "i18n_fields.gemspec",
25
+ "lib/i18n_fields.rb"
26
+ ]
27
+ s.homepage = "http://github.com/mcasimir/kaminari-bootstrap"
28
+ s.licenses = ["MIT"]
29
+ s.require_paths = ["lib"]
30
+ s.rubygems_version = "1.8.24"
31
+ s.summary = "Translatable fields for ActiveRecordSchema"
32
+
33
+ if s.respond_to? :specification_version then
34
+ s.specification_version = 3
35
+
36
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
37
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
38
+ s.add_runtime_dependency(%q<globalize3>, [">= 0"])
39
+ s.add_runtime_dependency(%q<active_record_schema>, [">= 0"])
40
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
41
+ else
42
+ s.add_dependency(%q<rails>, [">= 0"])
43
+ s.add_dependency(%q<globalize3>, [">= 0"])
44
+ s.add_dependency(%q<active_record_schema>, [">= 0"])
45
+ s.add_dependency(%q<jeweler>, [">= 0"])
46
+ end
47
+ else
48
+ s.add_dependency(%q<rails>, [">= 0"])
49
+ s.add_dependency(%q<globalize3>, [">= 0"])
50
+ s.add_dependency(%q<active_record_schema>, [">= 0"])
51
+ s.add_dependency(%q<jeweler>, [">= 0"])
52
+ end
53
+ end
54
+
@@ -0,0 +1,68 @@
1
+ # Author:: Maurizio Casimirri (mailto:maurizio.cas@gmail.com)
2
+ # Copyright:: Copyright (c) 2012 Maurizio Casimirri
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'globalize3'
24
+ require 'active_record_schema'
25
+ module I18nFields
26
+ module TranslatableFields
27
+ extend ActiveSupport::Concern
28
+
29
+ module ClassMethods
30
+ def field(field_name, *args)
31
+
32
+ options = args.extract_options!
33
+ multilingual = options.delete(:translatable) || options.delete(:multilingual)
34
+ args << options
35
+
36
+ if multilingual
37
+ @has_translations = true
38
+ translates field_name
39
+
40
+ self::Translation.class_eval do
41
+ # belongs_to association with translated model is already added by globalize
42
+
43
+ field field_name, *args
44
+ field :locale
45
+ index :locale
46
+ schema.indexes.keys.each {|k|
47
+ schema.indexes[k].options ||= {}
48
+ schema.indexes[k].options[:name] = "index_#{SecureRandom::uuid}" # avoid index_name too long error
49
+ }
50
+ timestamps
51
+ end
52
+
53
+ else
54
+ super(field_name, *args)
55
+ end
56
+
57
+ end
58
+
59
+ def has_translations?
60
+ !!@has_translations
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ ActiveRecord::Base.send :include, I18nFields::TranslatableFields
68
+
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n_fields
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mcasimir
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: globalize3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: active_record_schema
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Translatable fields for ActiveRecordSchema
79
+ email: maurizio.cas@gmail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files:
83
+ - README.md
84
+ files:
85
+ - Gemfile
86
+ - Gemfile.lock
87
+ - README.md
88
+ - Rakefile
89
+ - VERSION
90
+ - i18n_fields.gemspec
91
+ - lib/i18n_fields.rb
92
+ homepage: http://github.com/mcasimir/kaminari-bootstrap
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: -1565948633769916894
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.24
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Translatable fields for ActiveRecordSchema
120
+ test_files: []